-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logging and request id tracking to wasmtime serve
#7366
Add logging and request id tracking to wasmtime serve
#7366
Conversation
} | ||
|
||
fn check_write(&mut self) -> StreamResult<usize> { | ||
Ok(1024 * 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is arbitrary.
|
||
#[async_trait::async_trait] | ||
impl preview2::Subscribe for LogStream { | ||
async fn ready(&mut self) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear that there's a reasonable implementation for this here. Perhaps using tokio::io::Stdout
instead of a mutex guarded std::io::Stdout
would make more sense?
src/commands/serve.rs
Outdated
|
||
builder.stderr(LogStream { | ||
prefix: format!("stderr [{req_id}] :: "), | ||
output, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be reasonable to make a separate Stderr
handle here. My thought was that since the output is already prefixed with stdout
/stderr
, using the same output stream would be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! One thought about whether or not this should be an async write, but otherwise seems fine to me
src/commands/serve.rs
Outdated
for line in bytes.split(|c| *c == b'\n') { | ||
if !line.is_empty() { | ||
msg.extend_from_slice(&self.prefix.as_bytes()); | ||
msg.extend_from_slice(line); | ||
msg.push(b'\n'); | ||
} | ||
} | ||
|
||
let output = self.output.clone(); | ||
tokio::task::spawn(async move { | ||
use std::io::Write; | ||
let mut output = output.lock().await; | ||
output.write_all(&msg).expect("writing to stdout"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you think of going ahead and directly doing a blocking write to stdout/stderr here? That'd help applying a bit of backpressure (albeit not in a perfect way) if necessary and additionally would avoid the need to pass around streams much. That'd also perhaps make it a bit easier to write stdout to stdout and stderr to stderr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! I've implemented that, and substantially simplified the LogStream::write
implementation :)
4a1b335
to
698ec0f
Compare
Add some missing log handling to
wasmtime serve
:Fixes #7257