From 72564c69d1b5a2fbc6fc157e95043c653247316e Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Mon, 22 Jan 2024 10:35:53 +0200 Subject: [PATCH] chore(dependencies): update opentelemetry to latest version Signed-off-by: Dotan Simha --- minitrace-opentelemetry/Cargo.toml | 5 +++-- minitrace-opentelemetry/README.md | 21 +++++++++++---------- minitrace-opentelemetry/src/lib.rs | 16 ++++++++-------- minitrace/Cargo.toml | 5 +++-- minitrace/examples/asynchronous.rs | 23 +++++++++++------------ minitrace/examples/synchronous.rs | 23 +++++++++++------------ 6 files changed, 47 insertions(+), 46 deletions(-) diff --git a/minitrace-opentelemetry/Cargo.toml b/minitrace-opentelemetry/Cargo.toml index 387ecb3f..ed134e7b 100644 --- a/minitrace-opentelemetry/Cargo.toml +++ b/minitrace-opentelemetry/Cargo.toml @@ -16,9 +16,10 @@ keywords = ["tracing", "span", "datadog", "jaeger", "opentelemetry"] futures = { version = "0.3", features = ["executor"] } log = "0.4" minitrace = { version = "0.6.2", path = "../minitrace" } -opentelemetry = { version = "0.20", features = ["trace"] } +opentelemetry = { version = "0.21", features = ["trace"] } +opentelemetry_sdk = { version = "0.21", features = ["trace"] } [dev-dependencies] -opentelemetry-otlp = { version = "0.13", features = ["trace"] } +opentelemetry-otlp = { version = "0.14", features = ["trace"] } rand = "0.8" tokio = { version = "1", features = ["rt-multi-thread"] } diff --git a/minitrace-opentelemetry/README.md b/minitrace-opentelemetry/README.md index cb3a8807..235121a2 100644 --- a/minitrace-opentelemetry/README.md +++ b/minitrace-opentelemetry/README.md @@ -37,21 +37,22 @@ use minitrace::prelude::*; use minitrace_opentelemetry::OpenTelemetryReporter; use opentelemetry_otlp::{SpanExporter, ExportConfig, Protocol, TonicConfig}; use opentelemetry::trace::SpanKind; -use opentelemetry::sdk::Resource; +use opentelemetry_sdk::Resource; use opentelemetry::KeyValue; use opentelemetry::InstrumentationLibrary; +use opentelemetry_otlp::WithExportConfig; // Initialize reporter let reporter = OpenTelemetryReporter::new( - SpanExporter::new_tonic( - ExportConfig { - endpoint: "http://127.0.0.1:4317".to_string(), - protocol: Protocol::Grpc, - timeout: Duration::from_secs(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT), - }, - TonicConfig::default(), - ) - .unwrap(), + opentelemetry_otlp::new_exporter() + .tonic() + .with_endpoint("http://127.0.0.1:4317".to_string()) + .with_protocol(opentelemetry_otlp::Protocol::Grpc) + .with_timeout(Duration::from_secs( + opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT, + )) + .build_span_exporter() + .expect("initialize oltp exporter"), SpanKind::Server, Cow::Owned(Resource::new([KeyValue::new("service.name", "asynchronous")])), InstrumentationLibrary::new("example-crate", Some(env!("CARGO_PKG_VERSION")), None::<&'static str>, None), diff --git a/minitrace-opentelemetry/src/lib.rs b/minitrace-opentelemetry/src/lib.rs index b1a3f018..cd05dae7 100644 --- a/minitrace-opentelemetry/src/lib.rs +++ b/minitrace-opentelemetry/src/lib.rs @@ -9,11 +9,6 @@ use std::time::UNIX_EPOCH; use minitrace::collector::EventRecord; use minitrace::collector::Reporter; use minitrace::prelude::*; -use opentelemetry::sdk::export::trace::SpanData; -use opentelemetry::sdk::export::trace::SpanExporter; -use opentelemetry::sdk::trace::EvictedHashMap; -use opentelemetry::sdk::trace::EvictedQueue; -use opentelemetry::sdk::Resource; use opentelemetry::trace::Event; use opentelemetry::trace::SpanContext; use opentelemetry::trace::SpanKind; @@ -25,6 +20,10 @@ use opentelemetry::Key; use opentelemetry::KeyValue; use opentelemetry::StringValue; use opentelemetry::Value; +use opentelemetry_sdk::export::trace::SpanData; +use opentelemetry_sdk::export::trace::SpanExporter; +use opentelemetry_sdk::trace::EvictedQueue; +use opentelemetry_sdk::Resource; /// [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-rust) reporter for `minitrace`. /// @@ -63,6 +62,7 @@ impl OpenTelemetryReporter { false, TraceState::default(), ), + dropped_attributes_count: 0, parent_span_id: span.parent_id.0.into(), name: span.name.clone(), start_time: UNIX_EPOCH + Duration::from_nanos(span.begin_time_unix_ns), @@ -79,10 +79,10 @@ impl OpenTelemetryReporter { .collect() } - fn convert_properties(properties: &[(Cow<'static, str>, Cow<'static, str>)]) -> EvictedHashMap { - let mut map = EvictedHashMap::new(u32::MAX, properties.len()); + fn convert_properties(properties: &[(Cow<'static, str>, Cow<'static, str>)]) -> Vec { + let mut map = Vec::new(); for (k, v) in properties { - map.insert(KeyValue::new( + map.push(KeyValue::new( cow_to_otel_key(k.clone()), cow_to_otel_value(v.clone()), )); diff --git a/minitrace/Cargo.toml b/minitrace/Cargo.toml index 718e2d95..308bbff0 100644 --- a/minitrace/Cargo.toml +++ b/minitrace/Cargo.toml @@ -42,8 +42,9 @@ minitrace-jaeger = { version = "0.6.2", path = "../minitrace-jaeger" } minitrace-opentelemetry = { version = "0.6.2", path = "../minitrace-opentelemetry" } mockall = "0.11" once_cell = "1" -opentelemetry = { version = "0.20", features = ["trace"] } -opentelemetry-otlp = { version = "0.13", features = ["trace"] } +opentelemetry = { version = "0.21", features = ["trace"] } +opentelemetry-otlp = { version = "0.14", features = ["trace"] } +opentelemetry_sdk = { version = "0.21" } rand = "0.8" rustracing = "0.6" serial_test = "2" diff --git a/minitrace/examples/asynchronous.rs b/minitrace/examples/asynchronous.rs index d2f9ce77..ecca53f2 100644 --- a/minitrace/examples/asynchronous.rs +++ b/minitrace/examples/asynchronous.rs @@ -8,6 +8,7 @@ use std::time::Duration; use minitrace::collector::Config; use minitrace::collector::Reporter; use minitrace::prelude::*; +use opentelemetry_otlp::WithExportConfig; fn parallel_job() -> Vec> { let mut v = Vec::with_capacity(4); @@ -85,19 +86,17 @@ impl ReportAll { "select", ), opentelemetry: minitrace_opentelemetry::OpenTelemetryReporter::new( - opentelemetry_otlp::SpanExporter::new_tonic( - opentelemetry_otlp::ExportConfig { - endpoint: "http://127.0.0.1:4317".to_string(), - protocol: opentelemetry_otlp::Protocol::Grpc, - timeout: Duration::from_secs( - opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT, - ), - }, - opentelemetry_otlp::TonicConfig::default(), - ) - .expect("initialize oltp exporter"), + opentelemetry_otlp::new_exporter() + .tonic() + .with_endpoint("http://127.0.0.1:4317".to_string()) + .with_protocol(opentelemetry_otlp::Protocol::Grpc) + .with_timeout(Duration::from_secs( + opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT, + )) + .build_span_exporter() + .expect("initialize oltp exporter"), opentelemetry::trace::SpanKind::Server, - Cow::Owned(opentelemetry::sdk::Resource::new([ + Cow::Owned(opentelemetry_sdk::Resource::new([ opentelemetry::KeyValue::new("service.name", "asynchronous(opentelemetry)"), ])), opentelemetry::InstrumentationLibrary::new( diff --git a/minitrace/examples/synchronous.rs b/minitrace/examples/synchronous.rs index 29279e3b..2650d690 100644 --- a/minitrace/examples/synchronous.rs +++ b/minitrace/examples/synchronous.rs @@ -8,6 +8,7 @@ use std::time::Duration; use minitrace::collector::Config; use minitrace::collector::Reporter; use minitrace::prelude::*; +use opentelemetry_otlp::WithExportConfig; fn func1(i: u64) { let _guard = LocalSpan::enter_with_local_parent("func1"); @@ -61,19 +62,17 @@ impl ReportAll { "select", ), opentelemetry: minitrace_opentelemetry::OpenTelemetryReporter::new( - opentelemetry_otlp::SpanExporter::new_tonic( - opentelemetry_otlp::ExportConfig { - endpoint: "http://127.0.0.1:4317".to_string(), - protocol: opentelemetry_otlp::Protocol::Grpc, - timeout: Duration::from_secs( - opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT, - ), - }, - opentelemetry_otlp::TonicConfig::default(), - ) - .expect("initialize oltp exporter"), + opentelemetry_otlp::new_exporter() + .tonic() + .with_endpoint("http://127.0.0.1:4317".to_string()) + .with_protocol(opentelemetry_otlp::Protocol::Grpc) + .with_timeout(Duration::from_secs( + opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT, + )) + .build_span_exporter() + .expect("initialize oltp exporter"), opentelemetry::trace::SpanKind::Server, - Cow::Owned(opentelemetry::sdk::Resource::new([ + Cow::Owned(opentelemetry_sdk::Resource::new([ opentelemetry::KeyValue::new("service.name", "synchronous(opentelemetry)"), ])), opentelemetry::InstrumentationLibrary::new(