From 3597479ab6dbee5a6a3701ae628a694b0fd08471 Mon Sep 17 00:00:00 2001 From: Wolfgang Schnerring Date: Thu, 30 Mar 2023 00:41:28 +0200 Subject: [PATCH] Use the browser-only js-sys workaround only when actually targeting a browser (#1005) (#1008) wasi runtimes do provide a SystemTime implementation, see https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-common/src/clocks.rs --- opentelemetry-api/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/opentelemetry-api/src/lib.rs b/opentelemetry-api/src/lib.rs index 2a07884bc8..e19182726f 100644 --- a/opentelemetry-api/src/lib.rs +++ b/opentelemetry-api/src/lib.rs @@ -73,13 +73,16 @@ pub mod time { use std::time::SystemTime; #[doc(hidden)] - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any( + not(target_arch = "wasm32"), + all(target_arch = "wasm32", target_os = "wasi") + ))] pub fn now() -> SystemTime { SystemTime::now() } #[doc(hidden)] - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] pub fn now() -> SystemTime { SystemTime::UNIX_EPOCH + std::time::Duration::from_millis(js_sys::Date::now() as u64) }