You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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 to `SystemTime::now()` with an
implementation that returns a `SystemTime` constructed from
`js_sys::Date`. To preserve the ability to pass `SystemTime`-typed args
to `opentelemetry_api` methods, I just added the same mechanism to this
library.
Because `Instant` is never used in `opentelemetry_api`, we can instead
replace the implementation entirely with the api-compatible "polyfill"
from `web_time`.
All of these changes are behind `cfg` and automatically enabled when
building for `wasm32` targets, so this will not change any
behavior/performance when built for other targets.
0 commit comments