Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
I was attempting to use this library with a wasm target in a browser. If you call
std::time::{Instant, SystemTime}::now
in a wasm target, it will panic at runtime. This library makes use of both::now()
calls, which will result in a panic when attempting to record a trace.Solution
In the library that this library calls (
opentelemetry-api
), this is resolved by replacing calls toSystemTime::now()
with an implementation that returns aSystemTime
constructed fromjs_sys::Date
. To preserve the ability to passSystemTime
-typed args toopentelemetry_api
methods, I just added the same mechanism to this library.Because
Instant
is never used inopentelemetry_api
, we can instead replace the implementation entirely with the api-compatible "polyfill" fromweb_time
.All of these changes are behind
cfg
and automatically enabled when building forwasm32
targets, so this will not change any behavior/performance when built for other targets.