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?
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
tracing was designed so that logging things is independant from where to write logged things to
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
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
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
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
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
sqlx is a little annoying for simple stuff but as soon as it gets at all complicated its worth it
which...is basically all of rust
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
Ari Seyhun has marked this topic as resolved.
Last updated: Dec 23 2024 at 14:03 UTC