Skip to content

feat(trace): add abstract Clock trait supporting custom timing impl#710

Open
Saplyn wants to merge 3 commits into
tower-rs:mainfrom
Saplyn:static-clock
Open

feat(trace): add abstract Clock trait supporting custom timing impl#710
Saplyn wants to merge 3 commits into
tower-rs:mainfrom
Saplyn:static-clock

Conversation

@Saplyn

@Saplyn Saplyn commented Jul 5, 2026

Copy link
Copy Markdown

Motivation

Adding a way to allow user to supply their own Clock (time-recording) implementation if the default one (from std) isn't desired. Enabling deterministic testing with fake clocks and WASM-compatibility if the user has a WASM-compatible clock implementation.

Closes #657

Solution

Added an abstract Clock trait for timing, replacing the original implementation.

I decided to go with static dispatch (despite @jlizen suggest otherwise) because adding a dyn Clock would make trace layer and service non-copy, resulting a potential breaking API change.

TODOs

@Saplyn
Saplyn marked this pull request as ready for review July 5, 2026 18:54
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

Successfully merging this pull request may close these issues.

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

1 participant