Skip to content

Commit 60f6709

Browse files
committed
Add preliminary wasm32-unknown-unknown support
1 parent 285dc92 commit 60f6709

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+141
-107
lines changed

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[resolver]
22
# https://doc.rust-lang.org/cargo/reference/config.html#resolverincompatible-rust-versions
33
incompatible-rust-versions = "fallback"
4+
5+
[build]
6+
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))']
7+
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ http = { version = "1.1", default-features = false, features = ["std"] }
2929
http-body-util = "0.1"
3030
hyper = { version = "1.3", default-features = false }
3131
hyper-util = "0.1"
32+
getrandom = { version = "0.3", default-features = false }
3233
log = "0.4.21"
3334
once_cell = "1.13"
3435
pin-project-lite = "0.2"

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use super::{
44
};
55
use crate::{ExportConfig, Protocol, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS};
66
use http::{HeaderName, HeaderValue, Uri};
7+
use opentelemetry::env;
78
use opentelemetry::otel_debug;
9+
use opentelemetry::time::Duration;
810
use opentelemetry_http::HttpClient;
911
use opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema;
1012
#[cfg(feature = "logs")]
@@ -17,10 +19,8 @@ use opentelemetry_sdk::logs::LogBatch;
1719
use opentelemetry_sdk::trace::SpanData;
1820
use prost::Message;
1921
use std::collections::HashMap;
20-
use std::env;
2122
use std::str::FromStr;
2223
use std::sync::{Arc, Mutex};
23-
use std::time::Duration;
2424

2525
#[cfg(feature = "metrics")]
2626
mod metrics;
@@ -859,7 +859,7 @@ mod tests {
859859
"http://localhost:4318".parse().unwrap(),
860860
std::collections::HashMap::new(),
861861
crate::Protocol::HttpBinary,
862-
std::time::Duration::from_secs(10),
862+
opentelemetry::time::Duration::from_secs(10),
863863
Some(crate::Compression::Gzip),
864864
);
865865

@@ -890,7 +890,7 @@ mod tests {
890890
"http://localhost:4318".parse().unwrap(),
891891
std::collections::HashMap::new(),
892892
crate::Protocol::HttpBinary,
893-
std::time::Duration::from_secs(10),
893+
opentelemetry::time::Duration::from_secs(10),
894894
Some(crate::Compression::Zstd),
895895
);
896896

@@ -918,7 +918,7 @@ mod tests {
918918
"http://localhost:4318".parse().unwrap(),
919919
std::collections::HashMap::new(),
920920
crate::Protocol::HttpBinary,
921-
std::time::Duration::from_secs(10),
921+
opentelemetry::time::Duration::from_secs(10),
922922
None, // No compression
923923
);
924924

@@ -939,7 +939,7 @@ mod tests {
939939
"http://localhost:4318".parse().unwrap(),
940940
std::collections::HashMap::new(),
941941
crate::Protocol::HttpBinary,
942-
std::time::Duration::from_secs(10),
942+
opentelemetry::time::Duration::from_secs(10),
943943
Some(crate::Compression::Gzip),
944944
);
945945

@@ -961,7 +961,7 @@ mod tests {
961961
"http://localhost:4318".parse().unwrap(),
962962
std::collections::HashMap::new(),
963963
crate::Protocol::HttpBinary,
964-
std::time::Duration::from_secs(10),
964+
opentelemetry::time::Duration::from_secs(10),
965965
Some(crate::Compression::Zstd),
966966
);
967967

@@ -1023,19 +1023,19 @@ mod tests {
10231023
"http://localhost:4318".parse().unwrap(),
10241024
HashMap::new(),
10251025
protocol,
1026-
std::time::Duration::from_secs(10),
1026+
opentelemetry::time::Duration::from_secs(10),
10271027
compression,
10281028
)
10291029
}
10301030

10311031
fn create_test_span_data() -> opentelemetry_sdk::trace::SpanData {
1032+
use opentelemetry::time::{Duration, SystemTime};
10321033
use opentelemetry::trace::Status;
10331034
use opentelemetry::trace::{
10341035
SpanContext, SpanId, SpanKind, TraceFlags, TraceId, TraceState,
10351036
};
10361037
use opentelemetry_sdk::trace::{SpanData, SpanEvents, SpanLinks};
10371038
use std::borrow::Cow;
1038-
use std::time::{Duration, SystemTime};
10391039

10401040
let span_context = SpanContext::new(
10411041
TraceId::from(123),

opentelemetry-otlp/src/exporter/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::Protocol;
1111
use serde::{Deserialize, Serialize};
1212
use std::fmt::{Display, Formatter};
1313
use std::str::FromStr;
14-
use std::time::Duration;
14+
use opentelemetry::time::Duration;
1515
use thiserror::Error;
1616

1717
/// Target to which the exporter is going to send signals, defaults to https://localhost:4317.
@@ -181,9 +181,9 @@ fn resolve_compression_from_env(
181181
) -> Result<Option<Compression>, ExporterBuildError> {
182182
if let Some(compression) = config_compression {
183183
Ok(Some(compression))
184-
} else if let Ok(compression) = std::env::var(signal_env_var) {
184+
} else if let Ok(compression) = opentelemetry::env::var(signal_env_var) {
185185
Ok(Some(compression.parse::<Compression>()?))
186-
} else if let Ok(compression) = std::env::var(OTEL_EXPORTER_OTLP_COMPRESSION) {
186+
} else if let Ok(compression) = opentelemetry::env::var(OTEL_EXPORTER_OTLP_COMPRESSION) {
187187
Ok(Some(compression.parse::<Compression>()?))
188188
} else {
189189
Ok(None)
@@ -299,13 +299,13 @@ fn resolve_timeout(signal_timeout_var: &str, provided_timeout: Option<&Duration>
299299
// programmatic configuration overrides any value set via environment variables
300300
if let Some(timeout) = provided_timeout {
301301
*timeout
302-
} else if let Some(timeout) = std::env::var(signal_timeout_var)
302+
} else if let Some(timeout) = opentelemetry::env::var(signal_timeout_var)
303303
.ok()
304304
.and_then(|s| s.parse().ok())
305305
{
306306
// per signal env var is not modified
307307
Duration::from_millis(timeout)
308-
} else if let Some(timeout) = std::env::var(OTEL_EXPORTER_OTLP_TIMEOUT)
308+
} else if let Some(timeout) = opentelemetry::env::var(OTEL_EXPORTER_OTLP_TIMEOUT)
309309
.ok()
310310
.and_then(|s| s.parse().ok())
311311
{
@@ -397,7 +397,7 @@ mod tests {
397397
#[cfg(any(feature = "http-proto", feature = "http-json"))]
398398
#[test]
399399
fn export_builder_error_invalid_http_endpoint() {
400-
use std::time::Duration;
400+
use opentelemetry::time::Duration;
401401

402402
use crate::{ExportConfig, LogExporter, Protocol, WithExportConfig};
403403

@@ -424,7 +424,7 @@ mod tests {
424424
#[cfg(feature = "grpc-tonic")]
425425
#[tokio::test]
426426
async fn export_builder_error_invalid_grpc_endpoint() {
427-
use std::time::Duration;
427+
use opentelemetry::time::Duration;
428428

429429
use crate::{ExportConfig, LogExporter, Protocol, WithExportConfig};
430430

@@ -577,7 +577,7 @@ mod tests {
577577
|| {
578578
let timeout = super::resolve_timeout(
579579
crate::OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
580-
Some(&std::time::Duration::from_millis(1000)),
580+
Some(&opentelemetry::time::Duration::from_millis(1000)),
581581
);
582582
assert_eq!(timeout.as_millis(), 1000);
583583
},

opentelemetry-otlp/src/exporter/tonic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::env;
21
use std::fmt::{Debug, Formatter};
32
use std::str::FromStr;
43

54
use http::{HeaderMap, HeaderName, HeaderValue};
5+
use opentelemetry::env;
66
use opentelemetry::otel_debug;
77
use tonic::codec::CompressionEncoding;
88
use tonic::metadata::{KeyAndValueRef, MetadataMap};

opentelemetry-otlp/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
//! use opentelemetry_otlp::WithTonicConfig;
255255
//! # #[cfg(any(feature = "http-proto", feature = "http-json"))]
256256
//! use opentelemetry_otlp::WithHttpConfig;
257-
//! use std::time::Duration;
257+
//! use opentelemetry::time::Duration;
258258
//! # #[cfg(feature = "grpc-tonic")]
259259
//! use tonic::metadata::*;
260260
//!

opentelemetry-otlp/src/metric.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use opentelemetry_sdk::metrics::{
2121
data::ResourceMetrics, exporter::PushMetricExporter, Temporality,
2222
};
2323
use std::fmt::{Debug, Formatter};
24-
use std::time::Duration;
24+
use opentelemetry::time::Duration;
2525

2626
/// Target to which the exporter is going to send metrics, defaults to https://localhost:4317/v1/metrics.
2727
/// Learn about the relationship between this constant and default/spans/logs at
@@ -174,7 +174,7 @@ impl PushMetricExporter for MetricExporter {
174174
self.shutdown_with_timeout(Duration::from_secs(5))
175175
}
176176

177-
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
177+
fn shutdown_with_timeout(&self, _timeout: opentelemetry::time::Duration) -> OTelSdkResult {
178178
match &self.client {
179179
#[cfg(feature = "grpc-tonic")]
180180
SupportedTransportClient::Tonic(client) => client.shutdown(),

opentelemetry-proto/src/transform/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
feature = "gen-tonic-messages",
33
any(feature = "trace", feature = "metrics", feature = "logs")
44
))]
5-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
5+
use opentelemetry::time::{Duration, SystemTime, UNIX_EPOCH};
66

77
#[cfg(all(
88
feature = "gen-tonic-messages",

opentelemetry-sdk/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ tokio = { workspace = true, default-features = false, optional = true }
2626
tokio-stream = { workspace = true, optional = true }
2727
http = { workspace = true, optional = true }
2828

29+
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies]
30+
getrandom = { workspace = true, features = ["wasm_js"] }
31+
2932
[package.metadata.docs.rs]
3033
all-features = true
3134
rustdoc-args = ["--cfg", "docsrs"]

opentelemetry-sdk/src/logs/batch_log_processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type LogsData = Box<(SdkLogRecord, InstrumentationScope)>;
107107
/// ```rust
108108
/// use opentelemetry_sdk::logs::{BatchLogProcessor, BatchConfigBuilder, SdkLoggerProvider};
109109
/// use opentelemetry::global;
110-
/// use std::time::Duration;
110+
/// use opentelemetry::time::Duration;
111111
/// use opentelemetry_sdk::logs::InMemoryLogExporter;
112112
///
113113
/// let exporter = InMemoryLogExporter::default(); // Replace with an actual exporter
@@ -751,7 +751,7 @@ mod tests {
751751
use opentelemetry::InstrumentationScope;
752752
use opentelemetry::KeyValue;
753753
use std::sync::{Arc, Mutex};
754-
use std::time::Duration;
754+
use opentelemetry::time::Duration;
755755

756756
#[test]
757757
fn test_default_const_values() {

0 commit comments

Comments
 (0)