Skip to content

Feature Proposal: Shall we replace some API calls from std::time with web_time to make TraceLayer (and more services) WASM compatible? #657

Description

@Saplyn
  • 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions