From 03c2a8f912caf1cefd795b701416b398e7c5d20a Mon Sep 17 00:00:00 2001 From: Caleb Schoepp Date: Tue, 28 May 2024 09:55:51 -0600 Subject: [PATCH] WASI support I was attempting to use this library with a WASI target and it was not compiling. The cfg options in the Cargo.toml and the source files did not match. Signed-off-by: Caleb Schoepp --- src/layer.rs | 4 ++-- src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/layer.rs b/src/layer.rs index 43d2193..8ed2832 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -7,7 +7,7 @@ use opentelemetry::{ use std::fmt; use std::marker; use std::thread; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use std::time::Instant; use std::{any::TypeId, borrow::Cow}; use tracing_core::span::{self, Attributes, Id, Record}; @@ -17,7 +17,7 @@ use tracing_log::NormalizeEvent; use tracing_subscriber::layer::Context; use tracing_subscriber::registry::LookupSpan; use tracing_subscriber::Layer; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use web_time::Instant; const SPAN_NAME_FIELD: &str = "otel.name"; diff --git a/src/lib.rs b/src/lib.rs index 233d0fc..debed0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -154,12 +154,12 @@ pub struct OtelData { pub(crate) mod time { use std::time::SystemTime; - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] pub(crate) fn now() -> SystemTime { SystemTime::now() } - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] pub(crate) fn now() -> SystemTime { SystemTime::UNIX_EPOCH + std::time::Duration::from_millis(js_sys::Date::now() as u64) }