Stream: wasmtime

Topic: ✔ Wasmtime tracing subscriber for handling tracing in the...


view this post on Zulip Ari Seyhun (Nov 25 2023 at 06:49):

Are there any libraries or examples on using the tracing crate in guest code, and having the tracing subscriber be handled in the host with wasmtime?

So in guest code I can write tracing::info!("Hello!"), and handle this in the host either by printing it to the terminal, or sending it with open telemetry, etc?

I implemented something like this in Lunatic a while ago by essentially providing host functions the guest can call:
https://github.com/lunatic-solutions/lunatic/pull/202/files#diff-8134207e4272e3b8ccd1f4702d40839a1c6632b7c94ed1fe99dc8e541a602a1aR60-R86
However that was quite specific to lunatic, and I'm wondering if there's a more general approach I can use for regular wasmtime projects?

Todo: Each process should have its own single context. Ensure doc comments are written correctly. Make sure host function trait bounds are only whats required. Figure out how to add the enviro...

view this post on Zulip Ramon Klass (Nov 25 2023 at 13:34):

I think you can just write your own https://crates.io/crates/tracing-subscriber to implement a wit logger that takes tracing output and calls a host function with it

view this post on Zulip Ramon Klass (Nov 25 2023 at 13:34):

tracing was designed so that logging things is independant from where to write logged things to

view this post on Zulip Ari Seyhun (Nov 25 2023 at 13:36):

Yeah I guess I didn't phrase my question well, I was more so asking if anyone has gone through the effort of actually doing this for wasmtime. It's not so trivial to serialize all the types used in tracing subscribers, since there's a few dyn objects and such. I was just hoping somone might have gone through the effort already

view this post on Zulip Ramon Klass (Nov 25 2023 at 13:48):

oh, I don't think forwarding the tracing info would feasibly work, I would probably have sent the output string since as you said the way they use &dyn makes anything else than printing the thing not serializable anyway

view this post on Zulip Alex Crichton (Nov 27 2023 at 04:08):

I'm not aware of any example myself (not to say it doesn't already exist), but I can speak at least to how this might be done, which would be to specify a WIT interface with logging functions. You'd then write a tracing-subscriber lookalike that would route logging messages to this interface. That's the specification for both the guest and then from a host perspective that's what you'd get to work with from guests. Exactly how tracing primitives would map into WIT I'm not sure, I don't know enough about tracing myself

view this post on Zulip Ari Seyhun (Nov 27 2023 at 05:58):

Yeah I might tackle this soon, I think I'll need to serialize all the types somehow so that they can be received on the host

view this post on Zulip Simon (Nov 28 2023 at 20:27):

I was thinking the same last Friday. My initial idea was using tracing-tunnel and pass their serialized output to the host. Though my focus for the next two weeks shifted away so I don't have anything to share atm

view this post on Zulip Lann Martin (Nov 28 2023 at 20:46):

sqlx is a little annoying for simple stuff but as soon as it gets at all complicated its worth it

view this post on Zulip Lann Martin (Nov 28 2023 at 20:46):

which...is basically all of rust

view this post on Zulip Ari Seyhun (Dec 01 2023 at 06:03):

I got this working with tracing-tunnel. was actually very easy to do, thanks for pointing out tracing-tunnel @Simon :)
Here's the commit to get it working:
https://github.com/thalo-rs/thalo/commit/87ad7f82edbfaba3701ab519e114701d13e84a5a

An Event Sourcing runtime with WebAssembly & embedded event store - feat: add tracing support for aggregates · thalo-rs/thalo@87ad7f8

view this post on Zulip Notification Bot (Dec 01 2023 at 06:03):

Ari Seyhun has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC