Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASI support #147

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,18 @@ jobs:
- name: Run doctests
run: cargo test --doc --workspace

test-build-wasm:
name: build tests (wasm)
test-build-across-targets:
name: build tests (${{ matrix.target }})
needs: check
strategy:
matrix:
target: [wasm32-unknown-unknown, wasm32-wasi]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
target: ${{ matrix.target }}
- name: build all tests
run: cargo test --no-run

Expand All @@ -169,7 +172,7 @@ jobs:
- style
- cargo-hack
- check-msrv
- test-build-wasm
- test-build-across-targets
- test
steps:
- run: exit 0
4 changes: 2 additions & 2 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading