Skip to content

Commit 03c2a8f

Browse files
calebschoeppdjc
authored andcommitted
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 <caleb.schoepp@fermyon.com>
1 parent 2539f4f commit 03c2a8f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/layer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use opentelemetry::{
77
use std::fmt;
88
use std::marker;
99
use std::thread;
10-
#[cfg(not(target_arch = "wasm32"))]
10+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
1111
use std::time::Instant;
1212
use std::{any::TypeId, borrow::Cow};
1313
use tracing_core::span::{self, Attributes, Id, Record};
@@ -17,7 +17,7 @@ use tracing_log::NormalizeEvent;
1717
use tracing_subscriber::layer::Context;
1818
use tracing_subscriber::registry::LookupSpan;
1919
use tracing_subscriber::Layer;
20-
#[cfg(target_arch = "wasm32")]
20+
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
2121
use web_time::Instant;
2222

2323
const SPAN_NAME_FIELD: &str = "otel.name";

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ pub struct OtelData {
154154
pub(crate) mod time {
155155
use std::time::SystemTime;
156156

157-
#[cfg(not(target_arch = "wasm32"))]
157+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
158158
pub(crate) fn now() -> SystemTime {
159159
SystemTime::now()
160160
}
161161

162-
#[cfg(target_arch = "wasm32")]
162+
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
163163
pub(crate) fn now() -> SystemTime {
164164
SystemTime::UNIX_EPOCH + std::time::Duration::from_millis(js_sys::Date::now() as u64)
165165
}

0 commit comments

Comments
 (0)