Skip to content

Commit

Permalink
Bump the otel group with 4 updates (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Dec 3, 2024
1 parent 27a6d26 commit 5695a47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
rust = "1.76"
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,5 +60,5 @@ actix-web = "4.0.1"
opentelemetry-jaeger = {version = "0.22", features = ["integration_test"]}
prima_bridge = "0.19"
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"]}
42 changes: 19 additions & 23 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -31,7 +26,7 @@ fn normalize_collector_url(collector_url: &str) -> String {
collector_url.to_string() + "/v1/traces"
}

pub fn configure<T>(config: &SubscriberConfig<T>) -> Tracer {
pub fn configure<T>(config: &SubscriberConfig<T>) -> sdktrace::Tracer {
let telemetry = config
.telemetry
.as_ref()
Expand All @@ -50,35 +45,36 @@ pub fn configure<T>(config: &SubscriberConfig<T>) -> 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()),
KeyValue::new("country", config.country.to_string()),
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<Mutex<Option<trace::TracerProvider>>> = Lazy::new(Default::default);
static TRACER_PROVIDER: Lazy<Mutex<Option<sdktrace::TracerProvider>>> = 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
Expand Down

0 comments on commit 5695a47

Please sign in to comment.