diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..1798cce --- /dev/null +++ b/.mise.toml @@ -0,0 +1,2 @@ +[tools] +rust = "1.76" diff --git a/Cargo.toml b/Cargo.toml index d07f544..a2fd4fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,12 +37,12 @@ required-features = ["json-logger"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -opentelemetry = {version = "0.26", optional = true} -opentelemetry-otlp = {version = "0.26", features = ["http-proto", "reqwest-client"], default-features = false, optional = true} -opentelemetry_sdk = {version = "0.26", features = ["rt-tokio"], optional = true} +opentelemetry = {version = "0.27", optional = true} +opentelemetry-otlp = {version = "0.27", features = ["http-proto", "reqwest-client"], default-features = false, optional = true} +opentelemetry_sdk = {version = "0.27", features = ["rt-tokio"], optional = true} tracing = {version = "0.1", features = ["max_level_debug", "release_max_level_info"]} tracing-log = {version = "0.2"} -tracing-opentelemetry = {version = "0.27", optional = true} +tracing-opentelemetry = {version = "0.28", optional = true} tracing-subscriber = {version = "0.3", features = ["env-filter"]} # serialization/deserialization @@ -60,5 +60,5 @@ actix-web = "4.0.1" opentelemetry-jaeger = {version = "0.22", features = ["integration_test"]} prima_bridge = "0.18" tokio = {version = "1.17", features = ["rt", "macros", "rt-multi-thread"]} -tracing-actix-web = {version = "0.7.11", features = ["opentelemetry_0_23"]} +tracing-actix-web = {version = "0.7.11", features = ["opentelemetry_0_27"]} uuid = {version = "1.10", features = ["v4"]} diff --git a/src/telemetry.rs b/src/telemetry.rs index f29330d..00d9c84 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -1,12 +1,7 @@ use once_cell::sync::Lazy; -use opentelemetry::global; -use opentelemetry::trace::TracerProvider; -use opentelemetry::KeyValue; -use opentelemetry_otlp::WithExportConfig; -use opentelemetry_sdk::{ - trace::{self, Tracer}, - Resource, -}; +use opentelemetry::{global, trace::TracerProvider, InstrumentationScope, KeyValue}; +use opentelemetry_otlp::{SpanExporter, WithExportConfig}; +use opentelemetry_sdk::{trace as sdktrace, Resource}; use std::mem; use std::sync::Mutex; @@ -31,7 +26,7 @@ fn normalize_collector_url(collector_url: &str) -> String { collector_url.to_string() + "/v1/traces" } -pub fn configure(config: &SubscriberConfig) -> Tracer { +pub fn configure(config: &SubscriberConfig) -> sdktrace::Tracer { let telemetry = config .telemetry .as_ref() @@ -50,9 +45,11 @@ pub fn configure(config: &SubscriberConfig) -> Tracer { let collector_url = normalize_collector_url(&telemetry.collector_url); - let otlp_exporter = opentelemetry_otlp::new_exporter() - .http() - .with_endpoint(collector_url); + let otlp_exporter = SpanExporter::builder() + .with_http() + .with_endpoint(collector_url) + .build() + .expect("Failed to configure the OpenTelemetry OTLP span exporter"); let resource = Resource::new(vec![ KeyValue::new("environment", config.env.to_string()), @@ -60,25 +57,24 @@ pub fn configure(config: &SubscriberConfig) -> Tracer { KeyValue::new("service.name", telemetry.service_name.clone()), ]); - let tracer_provider = opentelemetry_otlp::new_pipeline() - .tracing() - .with_exporter(otlp_exporter) - .with_trace_config(trace::Config::default().with_resource(resource)) - .install_batch(runtime) - .expect("Failed to configure the OpenTelemetry tracer provider"); + let tracer_provider = sdktrace::TracerProvider::builder() + .with_batch_exporter(otlp_exporter, runtime) + .with_resource(resource) + .build(); set_tracer_provider(tracer_provider.clone()); - tracer_provider - .tracer_builder("prima-tracing") + let scope = InstrumentationScope::builder("prima-tracing") .with_version(env!("CARGO_PKG_VERSION")) - .build() + .build(); + + tracer_provider.tracer_with_scope(scope) } // Consider to remove this wrapper when https://github.com/open-telemetry/opentelemetry-rust/issues/1961 is resolved -static TRACER_PROVIDER: Lazy>> = Lazy::new(Default::default); +static TRACER_PROVIDER: Lazy>> = Lazy::new(Default::default); -fn set_tracer_provider(new_provider: trace::TracerProvider) { +fn set_tracer_provider(new_provider: sdktrace::TracerProvider) { global::set_tracer_provider(new_provider.clone()); let mut tracer_provider = TRACER_PROVIDER