Skip to content

Commit

Permalink
Upgrade to opentelemetry-rust v0.26.0 (#90)
Browse files Browse the repository at this point in the history
* bump to opentelemetry 0.26

* update to opentelemetry-rust v0.26.0

* Remove leftover cfg(feature=metrics)

* Update test snapshots

---------

Co-authored-by: Jan Kühle <[email protected]>
  • Loading branch information
sezna and frigus02 authored Oct 15, 2024
1 parent 1999b8e commit e41d0f9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 64 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ flate2 = "1"
http = "1"
once_cell = "1"
futures-util = { version = "0.3", default-features = false, optional = true }
opentelemetry = "0.25"
opentelemetry_sdk = "0.25"
opentelemetry-http = "0.25"
opentelemetry-semantic-conventions = "0.25"
opentelemetry = "0.26"
opentelemetry_sdk = "0.26"
opentelemetry-http = "0.26"
opentelemetry-semantic-conventions = { version = "0.26", features = ["semconv_experimental"] }
reqwest = { version = "0.12", default-features = false, features = ["blocking"], optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand All @@ -62,9 +62,9 @@ doc-comment = "0.3.3"
env_logger = "0.11.3"
insta = "1.39.0"
log = { version = "0.4", features = ["kv", "kv_sval"] }
opentelemetry_sdk = { version = "0.25", features = ["rt-async-std", "rt-tokio", "rt-tokio-current-thread", "logs_level_enabled"] }
opentelemetry-http = { version = "0.25", features = ["reqwest"] }
opentelemetry-appender-log = { version = "0.25", features = ["with-serde"] }
opentelemetry_sdk = { version = "0.26", features = ["rt-async-std", "rt-tokio", "rt-tokio-current-thread", "logs_level_enabled"] }
opentelemetry-http = { version = "0.26", features = ["reqwest"] }
opentelemetry-appender-log = { version = "0.26", features = ["with-serde"] }
rand = "0.8.5"
regex = "1.10.5"
reqwest = { version = "0.12", features = ["blocking"] }
Expand Down
8 changes: 4 additions & 4 deletions examples/opentelemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use opentelemetry::{
global,
propagation::TextMapPropagator,
trace::{FutureExt, Span, SpanKind, TraceContextExt, Tracer},
Context, Key,
Context, KeyValue,
};
use opentelemetry_sdk::propagation::TraceContextPropagator;
use std::collections::HashMap;
Expand All @@ -16,8 +16,8 @@ async fn spawn_children(n: u32, process_name: String) {
let tracer = global::tracer("spawn_children");
let mut span = tracer.start("spawn_children");
span.set_attributes([
Key::new("n").i64(n.into()),
Key::new("process_name").string(process_name.clone()),
KeyValue::new("n", Into::<i64>::into(n)),
KeyValue::new("process_name", process_name.clone()),
]);
let cx = Context::current_with_span(span);
for _ in 0..n {
Expand All @@ -33,7 +33,7 @@ async fn spawn_child_process(process_name: &str) {
.span_builder("spawn_child_process")
.with_kind(SpanKind::Client)
.start(&tracer);
span.set_attribute(Key::new("process_name").string(process_name.to_string()));
span.set_attribute(KeyValue::new("process_name", process_name.to_string()));
let cx = Context::current_with_span(span);

let mut injector = HashMap::new();
Expand Down
8 changes: 4 additions & 4 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {

#[test]
fn attrs_to_properties_filters_ms() {
let attrs = vec![KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let attrs = [KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let resource = Resource::new([KeyValue::new("c", "d"), KeyValue::new("_MS.c", "d")]);
let props = attrs_to_properties(attrs.iter(), Some(&resource), &[]).unwrap();
assert_eq!(props.len(), 2);
Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {

#[test]
fn attrs_map_to_properties_filters_ms() {
let attrs = vec![KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let attrs = [KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let attrs_map = attrs_to_map(attrs.iter());
assert_eq!(attrs_map.len(), 2);
let props = attrs_map_to_properties(attrs_map).unwrap();
Expand All @@ -264,9 +264,9 @@ mod tests {
#[test_case(AnyValue::Double(1.2), "1.2" ; "double")]
#[test_case(AnyValue::String("test".into()), "test" ; "string")]
#[test_case(AnyValue::Boolean(true), "true" ; "boolean")]
#[test_case(AnyValue::Bytes(Box::new(vec![])), "[]" ; "empty bytes")]
#[test_case(AnyValue::Bytes(Box::default()), "[]" ; "empty bytes")]
#[test_case(AnyValue::Bytes(Box::new(vec![1, 2, 3])), "[1,2,3]" ; "bytes")]
#[test_case(AnyValue::ListAny(Box::new(vec![])), "[]" ; "empty list")]
#[test_case(AnyValue::ListAny(Box::default()), "[]" ; "empty list")]
#[test_case(AnyValue::ListAny(Box::new(vec![1.into(), "test".into()])), "[1,test]" ; "list")]
#[test_case(AnyValue::Map(Box::new([].into())), "{}" ; "empty map")]
#[test_case(AnyValue::Map(Box::new([("k1".into(), "test".into())].into())), "{k1:test}" ; "map")]
Expand Down
21 changes: 0 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ pub use models::context_tag_keys::attrs;
use opentelemetry::{global, trace::TracerProvider as _, KeyValue, Value};
pub use opentelemetry_http::HttpClient;
use opentelemetry_sdk::export::ExportError;
#[cfg(feature = "metrics")]
use opentelemetry_sdk::metrics::reader::{AggregationSelector, DefaultAggregationSelector};
#[cfg(any(feature = "trace", feature = "logs"))]
use opentelemetry_sdk::Resource;
#[cfg(feature = "trace")]
Expand Down Expand Up @@ -649,8 +647,6 @@ where
),
instrumentation_key: self.instrumentation_key,
sample_rate: self.sample_rate.unwrap_or(100.0),
#[cfg(feature = "metrics")]
aggregation_selector: Box::new(DefaultAggregationSelector::new()),
resource: Resource::empty(),
}
}
Expand Down Expand Up @@ -737,8 +733,6 @@ pub struct Exporter<C> {
instrumentation_key: String,
#[cfg(feature = "trace")]
sample_rate: f64,
#[cfg(feature = "metrics")]
aggregation_selector: Box<dyn AggregationSelector>,
#[cfg(any(feature = "trace", feature = "logs"))]
resource: Resource,
}
Expand Down Expand Up @@ -769,8 +763,6 @@ impl<C> Exporter<C> {
instrumentation_key,
#[cfg(feature = "trace")]
sample_rate: 100.0,
#[cfg(feature = "metrics")]
aggregation_selector: Box::new(DefaultAggregationSelector::new()),
#[cfg(any(feature = "trace", feature = "logs"))]
resource: Resource::empty(),
}
Expand All @@ -791,8 +783,6 @@ impl<C> Exporter<C> {
instrumentation_key: connection_string.instrumentation_key,
#[cfg(feature = "trace")]
sample_rate: 100.0,
#[cfg(feature = "metrics")]
aggregation_selector: Box::new(DefaultAggregationSelector::new()),
#[cfg(any(feature = "trace", feature = "logs"))]
resource: Resource::empty(),
})
Expand Down Expand Up @@ -822,17 +812,6 @@ impl<C> Exporter<C> {
self.sample_rate = sample_rate * 100.0;
self
}

/// Set aggregation selector.
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
pub fn with_aggregation_selector(
mut self,
aggregation_selector: impl AggregationSelector + 'static,
) -> Self {
self.aggregation_selector = Box::new(aggregation_selector);
self
}
}

fn append_v2_track(uri: impl ToString) -> Result<http::Uri, http::uri::InvalidUri> {
Expand Down
14 changes: 2 additions & 12 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use opentelemetry_http::HttpClient;
use opentelemetry_sdk::metrics::{
data::{ExponentialHistogram, Gauge, Histogram, Metric, ResourceMetrics, Sum, Temporality},
exporter::PushMetricsExporter,
reader::{AggregationSelector, TemporalitySelector},
Aggregation, InstrumentKind,
reader::TemporalitySelector,
InstrumentKind,
};
use std::{convert::TryInto, sync::Arc, time::SystemTime};

Expand All @@ -39,16 +39,6 @@ where
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
impl<C> AggregationSelector for Exporter<C>
where
C: Send + Sync,
{
fn aggregation(&self, kind: InstrumentKind) -> Aggregation {
self.aggregation_selector.aggregation(kind)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
#[async_trait]
impl<C> PushMetricsExporter for Exporter<C>
Expand Down
20 changes: 10 additions & 10 deletions tests/snapshots/http_requests__live_metrics.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ x-ms-qps-role-name: unknown_service
"RoleName": "unknown_service",
"StreamId": "STRIPPED",
"Timestamp": "STRIPPED",
"Version": "opentelemetry:0.25.0"
"Version": "opentelemetry:0.26.0"
}


Expand Down Expand Up @@ -87,7 +87,7 @@ content-encoding: gzip
"RoleName": "unknown_service",
"StreamId": "STRIPPED",
"Timestamp": "STRIPPED",
"Version": "opentelemetry:0.25.0"
"Version": "opentelemetry:0.26.0"
}
]

Expand Down Expand Up @@ -144,7 +144,7 @@ content-encoding: gzip
"RoleName": "unknown_service",
"StreamId": "STRIPPED",
"Timestamp": "STRIPPED",
"Version": "opentelemetry:0.25.0"
"Version": "opentelemetry:0.26.0"
}
]

Expand All @@ -165,7 +165,7 @@ content-encoding: gzip
"service.name": "unknown_service",
"telemetry.sdk.language": "rust",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "0.25.0"
"telemetry.sdk.version": "0.26.0"
},
"resultCode": "2",
"success": false,
Expand All @@ -178,7 +178,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED"
},
"time": "STRIPPED"
Expand All @@ -201,7 +201,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED",
"ai.operation.parentId": "STRIPPED"
},
Expand All @@ -217,7 +217,7 @@ content-encoding: gzip
"service.name": "unknown_service",
"telemetry.sdk.language": "rust",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "0.25.0"
"telemetry.sdk.version": "0.26.0"
},
"responseCode": "2",
"success": false,
Expand All @@ -230,7 +230,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED"
},
"time": "STRIPPED"
Expand All @@ -245,7 +245,7 @@ content-encoding: gzip
"service.name": "unknown_service",
"telemetry.sdk.language": "rust",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "0.25.0"
"telemetry.sdk.version": "0.26.0"
},
"responseCode": "0",
"success": true,
Expand All @@ -258,7 +258,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED"
},
"time": "STRIPPED"
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/http_requests__logs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ content-encoding: gzip
"service.name": "unknown_service",
"telemetry.sdk.language": "rust",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "0.25.0"
"telemetry.sdk.version": "0.26.0"
},
"resultCode": "0",
"type": "InProc",
Expand All @@ -134,7 +134,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED"
},
"time": "STRIPPED"
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/http_requests__traces_batch_async_std.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ content-encoding: gzip
"service.name": "unknown_service",
"telemetry.sdk.language": "rust",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "0.25.0"
"telemetry.sdk.version": "0.26.0"
},
"resultCode": "0",
"type": "InProc",
Expand All @@ -31,7 +31,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED"
},
"time": "STRIPPED"
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/http_requests__traces_batch_tokio.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ content-encoding: gzip
"service.name": "unknown_service",
"telemetry.sdk.language": "rust",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "0.25.0"
"telemetry.sdk.version": "0.26.0"
},
"resultCode": "0",
"type": "InProc",
Expand All @@ -31,7 +31,7 @@ content-encoding: gzip
"sampleRate": 100.0,
"tags": {
"ai.cloud.role": "unknown_service",
"ai.internal.sdkVersion": "opentelemetry:0.25.0",
"ai.internal.sdkVersion": "opentelemetry:0.26.0",
"ai.operation.id": "STRIPPED"
},
"time": "STRIPPED"
Expand Down

0 comments on commit e41d0f9

Please sign in to comment.