diff --git a/src/config.rs b/src/config.rs index 90b047c8..a69e2394 100644 --- a/src/config.rs +++ b/src/config.rs @@ -178,6 +178,7 @@ pub(crate) struct OtelTraceConfig { pub(crate) enable: bool, pub(crate) filter: EnvFilterClone, pub(crate) endpoint: Option, + pub(crate) service_name: String, } impl Default for OtelTraceConfig { @@ -186,6 +187,7 @@ impl Default for OtelTraceConfig { enable: false, filter: default_tracing_filter(), endpoint: None, + service_name: env!("CARGO_PKG_NAME").to_owned(), } } } diff --git a/src/observability.rs b/src/observability.rs index 177001aa..8e3c662c 100644 --- a/src/observability.rs +++ b/src/observability.rs @@ -171,8 +171,11 @@ pub(crate) fn init( let tracer = opentelemetry_otlp::new_pipeline() .tracing() .with_trace_config( - opentelemetry_sdk::trace::config() - .with_resource(standard_resource()), + opentelemetry_sdk::trace::config().with_resource( + standard_resource( + config.observability.traces.service_name.clone(), + ), + ), ) .with_exporter(exporter) .install_batch(opentelemetry_sdk::runtime::Tokio)?; @@ -248,11 +251,9 @@ pub(crate) fn init( } /// Construct the standard [`Resource`] value to use for this service -fn standard_resource() -> Resource { - Resource::default().merge(&Resource::new([KeyValue::new( - "service.name", - env!("CARGO_PKG_NAME"), - )])) +fn standard_resource(service_name: String) -> Resource { + Resource::default() + .merge(&Resource::new([KeyValue::new("service.name", service_name)])) } /// Holds state relating to metrics @@ -306,7 +307,7 @@ impl Metrics { ) .expect("view should be valid"), ) - .with_resource(standard_resource()) + .with_resource(standard_resource(env!("CARGO_PKG_NAME").to_owned())) .build(); let meter = provider.meter(env!("CARGO_PKG_NAME"));