diff --git a/Cargo.toml b/Cargo.toml index 16941d8..96fbd82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,16 +29,16 @@ opentelemetry = { version = "0.24", features = [ opentelemetry_sdk = { version = "0.24.1", default-features = false, features = [ "rt-tokio", ] } -opentelemetry-aws = { version = "0.11", default-features = false } +opentelemetry-aws = { version = "0.12", default-features = false } opentelemetry-jaeger = { version = "0.22", default-features = false } -opentelemetry-jaeger-propagator = { version = "0.2", default-features = false } -opentelemetry-resource-detectors = { version = "0.2.0", default-features = false } -opentelemetry-semantic-conventions = { version = "0.15", default-features = false } -opentelemetry-zipkin = { version = "0.21", default-features = false } +opentelemetry-jaeger-propagator = { version = "0.3", default-features = false } +opentelemetry-resource-detectors = { version = "0.3", default-features = false } +opentelemetry-semantic-conventions = { version = "0.16", default-features = false } +opentelemetry-zipkin = { version = "0.22", default-features = false } opentelemetry-otlp = { version = "0.17", default-features = false } -opentelemetry-proto = { version = "0.6", default-features = false } -opentelemetry-stdout = { version = "0.4" } -tonic = { version = "0.11", default-features = false } #should be sync with opentelemetry-proto +opentelemetry-proto = { version = "0.7", default-features = false } +opentelemetry-stdout = { version = "0.5" } +tonic = { version = "0.12", default-features = false } #should be sync with opentelemetry-proto tracing = "0.1" tracing-opentelemetry = "0.25" diff --git a/axum-tracing-opentelemetry/Cargo.toml b/axum-tracing-opentelemetry/Cargo.toml index be1d40b..8642359 100644 --- a/axum-tracing-opentelemetry/Cargo.toml +++ b/axum-tracing-opentelemetry/Cargo.toml @@ -25,18 +25,12 @@ opentelemetry = { workspace = true, features = [ "trace", ], default-features = false } pin-project-lite = "0.2" -tower = "0.4" +tower = "0.5" tracing = { workspace = true } tracing-opentelemetry = { workspace = true } - -instrumentation-sdk-trace = { package = "tracing-opentelemetry-instrumentation-sdk", path = "../tracing-opentelemetry-instrumentation-sdk", features = [ - "http", -], version = "0.18", optional = true } - -instrumentation-sdk-info = { package = "tracing-opentelemetry-instrumentation-sdk", path = "../tracing-opentelemetry-instrumentation-sdk", features = [ +tracing-opentelemetry-instrumentation-sdk = { path = "../tracing-opentelemetry-instrumentation-sdk", features = [ "http", - "tracing_level_info", -], version = "0.19", optional = true } +], version = "0.19" } [dev-dependencies] fake-opentelemetry-collector = { path = "../fake-opentelemetry-collector" } @@ -69,4 +63,6 @@ opentelemetry_sdk = { workspace = true, features = [ [features] # to use level `info` instead of `trace` to create otel span -tracing_level_info = ["tracing-opentelemetry-instrumentation-sdk/tracing_level_info"] +tracing_level_info = [ + "tracing-opentelemetry-instrumentation-sdk/tracing_level_info", +] diff --git a/examples/axum-otlp/Cargo.toml b/examples/axum-otlp/Cargo.toml index 3716858..235791f 100644 --- a/examples/axum-otlp/Cargo.toml +++ b/examples/axum-otlp/Cargo.toml @@ -11,17 +11,14 @@ init-tracing-opentelemetry = { path = "../../init-tracing-opentelemetry", featur "otlp", "tracing_subscriber_ext", ] } -opentelemetry = "0.23" -opentelemetry-otlp = { version = "0.16", optional = true } +opentelemetry = "0.24" +opentelemetry-otlp = { version = "*", default-features = false, features = [ + "reqwest-client", + "reqwest-rustls", + "http-proto", + "tls", +] } serde_json = "1.0.79" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-opentelemetry-instrumentation-sdk = { path = "../../tracing-opentelemetry-instrumentation-sdk" } - -[features] -otlp-over-http = [ - "opentelemetry-otlp/reqwest-client", - "opentelemetry-otlp/reqwest-rustls", - "opentelemetry-otlp/http-proto", - "opentelemetry-otlp/tls", -] diff --git a/fake-opentelemetry-collector/Cargo.toml b/fake-opentelemetry-collector/Cargo.toml index e0fecaf..9ac3150 100644 --- a/fake-opentelemetry-collector/Cargo.toml +++ b/fake-opentelemetry-collector/Cargo.toml @@ -14,20 +14,28 @@ license.workspace = true futures = "0.3" hex = "0.4" opentelemetry = { workspace = true } -opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "trace", "logs"] } -opentelemetry-proto = { workspace = true, features = ["gen-tonic"] } +opentelemetry-otlp = { workspace = true, features = [ + "grpc-tonic", + "logs", + "trace", +] } +opentelemetry-proto = { workspace = true, features = [ + "gen-tonic", + "logs", + "trace", +] } # need tokio runtime to run smoke tests. opentelemetry_sdk = { workspace = true, features = [ "trace", "rt-tokio", "testing", ] } -serde = { version = "1.0.136", features = ["derive"] } -tokio = { version = "1.27", features = ["full"] } +serde = { version = "1.0", features = ["derive"] } +tokio = { version = "1.39", features = ["full"] } tokio-stream = { version = "0.1", features = ["net"] } tonic = { workspace = true } tracing = { workspace = true } [dev-dependencies] assert2 = "0.3" -insta = { version = "1.29.0", features = ["yaml", "redactions"] } +insta = { version = "1.39.0", features = ["yaml", "redactions"] } diff --git a/fake-opentelemetry-collector/src/lib.rs b/fake-opentelemetry-collector/src/lib.rs index 2f87634..56a75f4 100644 --- a/fake-opentelemetry-collector/src/lib.rs +++ b/fake-opentelemetry-collector/src/lib.rs @@ -10,6 +10,7 @@ use trace::*; use std::net::SocketAddr; use futures::StreamExt; +use opentelemetry::trace::TracerProvider; use opentelemetry_otlp::WithExportConfig; use opentelemetry_proto::tonic::collector::logs::v1::logs_service_server::LogsServiceServer; use opentelemetry_proto::tonic::collector::trace::v1::trace_service_server::TraceServiceServer; @@ -91,6 +92,7 @@ pub async fn setup_tracer(fake_server: &FakeCollectorServer) -> opentelemetry_sd ) .install_batch(opentelemetry_sdk::runtime::Tokio) .expect("failed to install tracer") + .tracer("") } pub async fn setup_logger( diff --git a/fake-opentelemetry-collector/src/logs.rs b/fake-opentelemetry-collector/src/logs.rs index 7d33a82..ab3c866 100644 --- a/fake-opentelemetry-collector/src/logs.rs +++ b/fake-opentelemetry-collector/src/logs.rs @@ -2,7 +2,6 @@ use crate::common::cnv_attributes; use opentelemetry_proto::tonic::collector::logs::v1::{ logs_service_server::LogsService, ExportLogsServiceRequest, ExportLogsServiceResponse, }; -use opentelemetry_proto::tonic::common::v1::AnyValue; use serde::Serialize; use std::collections::BTreeMap; use std::sync::{mpsc, Mutex}; diff --git a/init-tracing-opentelemetry/src/otlp.rs b/init-tracing-opentelemetry/src/otlp.rs index b7c2986..c6d56b9 100644 --- a/init-tracing-opentelemetry/src/otlp.rs +++ b/init-tracing-opentelemetry/src/otlp.rs @@ -1,11 +1,8 @@ use std::{collections::HashMap, str::FromStr}; -use opentelemetry::trace::{TraceError, TracerProvider}; +use opentelemetry::trace::TraceError; use opentelemetry_otlp::SpanExporterBuilder; -use opentelemetry_sdk::{ - trace::{Sampler, Tracer}, - Resource, -}; +use opentelemetry_sdk::{trace::Sampler, trace::TracerProvider, Resource}; #[cfg(feature = "tls")] use tonic::transport::ClientTlsConfig; @@ -17,7 +14,10 @@ pub fn identity( } // see https://opentelemetry.io/docs/reference/specification/protocol/exporter/ -pub fn init_tracer(resource: Resource, transform: F) -> Result +pub fn init_tracerprovider( + resource: Resource, + transform: F, +) -> Result where F: FnOnce( opentelemetry_otlp::OtlpTracePipeline, @@ -57,9 +57,8 @@ where .with_sampler(read_sampler_from_env()), ); pipeline = transform(pipeline); - let provider = pipeline.install_batch(opentelemetry_sdk::runtime::Tokio); - opentelemetry::global::set_tracer_provider(provider.clone()); - provider.tracer() + let provider = pipeline.install_batch(opentelemetry_sdk::runtime::Tokio)?; + Ok(provider) } /// turn a string of "k1=v1,k2=v2,..." into an iterator of (key, value) tuples diff --git a/init-tracing-opentelemetry/src/tracing_subscriber_ext.rs b/init-tracing-opentelemetry/src/tracing_subscriber_ext.rs index e1d5675..30c240b 100644 --- a/init-tracing-opentelemetry/src/tracing_subscriber_ext.rs +++ b/init-tracing-opentelemetry/src/tracing_subscriber_ext.rs @@ -1,4 +1,4 @@ -use opentelemetry::trace::TraceError; +use opentelemetry::trace::{TraceError, TracerProvider}; use opentelemetry_sdk::trace::Tracer; use tracing::{info, Subscriber}; use tracing_opentelemetry::OpenTelemetryLayer; @@ -68,11 +68,12 @@ where otlp, resource::DetectResource, }; + use opentelemetry::global; let otel_rsrc = DetectResource::default() //.with_fallback_service_name(env!("CARGO_PKG_NAME")) //.with_fallback_service_version(env!("CARGO_PKG_VERSION")) .build(); - let otel_tracer = otlp::init_tracer(otel_rsrc, otlp::identity)?; + let tracerprovider = otlp::init_tracerprovider(otel_rsrc, otlp::identity)?; // to not send trace somewhere, but continue to create and propagate,... // then send them to `axum_tracing_opentelemetry::stdio::WriteNoWhere::default()` // or to `std::io::stdout()` to print @@ -83,9 +84,11 @@ where // stdio::WriteNoWhere::default(), // )?; init_propagator()?; - Ok(tracing_opentelemetry::layer() + let layer = tracing_opentelemetry::layer() .with_error_records_to_exceptions(true) - .with_tracer(otel_tracer)) + .with_tracer(tracerprovider.tracer("")); + global::set_tracer_provider(tracerprovider); + Ok(layer) } pub fn init_subscribers() -> Result<(), Error> {