tower-rs / tower-rs/tower-http
Feature Proposal: Shall we replace some API calls from `std::time` with `web_time` to make `TraceLayer` (and more services) WASM compatible?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 913
- Forks
- 231
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 8
Description
- I have looked for existing issues (including closed) about this
Feature Request
Motivation
I'm developing a qqbot webhook callback handler targeting WASM (to be ran on Supabase Edge Functions' Runtime), and would like to use tower_http::trace::TraceLayer to enable tracing for my application. However, as some time related APIs from standard library (like std::time::Instant::now()) panics on wasm-unkown-unkown, TraceLayer and some other service couldn't be used in WASM context.
By replacing those time related API calls with WASM compatible ones, we can make this crate more accessible to those who wish to use them in WASM context (for example, worker with axum for Cloudflare Workers and edge computing).
Proposal
We could replace std::time with web-time, and gate this behind a cargo feature (for compatibility and those who don't want wasm stuff). I've tried vibe coding with Copilot and it seems to be working, so this should be a viable solution.
Possible drawback is the user will have to download an extra dependency if they enable full.
If possible, I'm willing to do the implementation myself (I would do it by hand and won't vibe code for the PR of course).
Alternatives
An alternative would be not use tower_http::trace::TraceLayer and instead manually implement the tracing stuff. The drawback is the user would have to write a lot more code to get it working.
I chose the proposed solution because it's relatively simple to implement (web-time should be a drop-in replacement for those APIs) and could make more tower-http services available for WASM (edge computing scenario).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TraceLayer entry point and identify the other services that use the affected std::time APIs. Review the comment thread before choosing an implementation, then assess the proposed web-time dependency and feature-gating approach. Done means the selected services can be used in WASM without breaking existing compatibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100