Skip to content
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

Allow wasmtime serve command's LogStream prefix to be customizable #9799

Open
jzhn opened this issue Dec 12, 2024 · 2 comments
Open

Allow wasmtime serve command's LogStream prefix to be customizable #9799

jzhn opened this issue Dec 12, 2024 · 2 comments

Comments

@jzhn
Copy link
Contributor

jzhn commented Dec 12, 2024

Feature

Currently, the wasmtime serve always prefixes the stdout and stderr output of http handlers. This prevents users from implementing structured logs like json.

Expected behaviour

logging from http handler in json will be logged by wasmtime serve as-is, without any prefixes.

{"timestamp":"2024-12-12T02:01:04.794485Z","level":"INFO","fields":{"message":"hello world","log.target":"webservice","log.module_path":"webservice","log.file":"webservice/src/lib.rs","log.line":237},"target":"webservice"}
Actual behaviour

handler logs are prefixed with stdout [{req_id}] :: .

stdout [176] :: {"timestamp":"2024-12-12T02:01:04.794485Z","level":"INFO","fields":{"message":"hello world","log.target":"webservice","log.module_path":"webservice","log.file":"webservice/src/lib.rs","log.line":237},"target":"webservice"}

Benefit

If wasmtime serve allows customizing log prefixes, it would allow users to implement structured logging at their http handlers, like json, so the stdout and stderr logs from wasmtime serve can be easily parsed by popular log management tools like Grafana Loki and AWS CloudWatch

Implementation

Hopefully it's as simple as adding a coupld CLI flags, to make

builder.stdout(LogStream::new(
format!("stdout [{req_id}] :: "),
Output::Stdout,
));
builder.stderr(LogStream::new(
format!("stderr [{req_id}] :: "),
Output::Stderr,
));
configurable.

Alternatives

No workarounds/alternatives I could think of.

@alexcrichton
Copy link
Member

Sounds reasonable to me to have some CLI flags for this yeah, would you be interested in sending a PR? Perhaps we could start out with a flag to just turn off the prefixes?

@jzhn
Copy link
Contributor Author

jzhn commented Dec 14, 2024

@alexcrichton : I'm fairly new to Rust and WASM, but with your encouragement I've created a PR for this. Please take a look and let me know your feedbacks. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants