mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
tracing: allow configuring service name
This is essential when consuming tracing data from multiple servers.
This commit is contained in:
parent
c355e2ad39
commit
14afa1357e
2 changed files with 11 additions and 8 deletions
|
|
@ -178,6 +178,7 @@ pub(crate) struct OtelTraceConfig {
|
||||||
pub(crate) enable: bool,
|
pub(crate) enable: bool,
|
||||||
pub(crate) filter: EnvFilterClone,
|
pub(crate) filter: EnvFilterClone,
|
||||||
pub(crate) endpoint: Option<String>,
|
pub(crate) endpoint: Option<String>,
|
||||||
|
pub(crate) service_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OtelTraceConfig {
|
impl Default for OtelTraceConfig {
|
||||||
|
|
@ -186,6 +187,7 @@ impl Default for OtelTraceConfig {
|
||||||
enable: false,
|
enable: false,
|
||||||
filter: default_tracing_filter(),
|
filter: default_tracing_filter(),
|
||||||
endpoint: None,
|
endpoint: None,
|
||||||
|
service_name: env!("CARGO_PKG_NAME").to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,8 +171,11 @@ pub(crate) fn init(
|
||||||
let tracer = opentelemetry_otlp::new_pipeline()
|
let tracer = opentelemetry_otlp::new_pipeline()
|
||||||
.tracing()
|
.tracing()
|
||||||
.with_trace_config(
|
.with_trace_config(
|
||||||
opentelemetry_sdk::trace::config()
|
opentelemetry_sdk::trace::config().with_resource(
|
||||||
.with_resource(standard_resource()),
|
standard_resource(
|
||||||
|
config.observability.traces.service_name.clone(),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.with_exporter(exporter)
|
.with_exporter(exporter)
|
||||||
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
|
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
|
||||||
|
|
@ -248,11 +251,9 @@ pub(crate) fn init(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct the standard [`Resource`] value to use for this service
|
/// Construct the standard [`Resource`] value to use for this service
|
||||||
fn standard_resource() -> Resource {
|
fn standard_resource(service_name: String) -> Resource {
|
||||||
Resource::default().merge(&Resource::new([KeyValue::new(
|
Resource::default()
|
||||||
"service.name",
|
.merge(&Resource::new([KeyValue::new("service.name", service_name)]))
|
||||||
env!("CARGO_PKG_NAME"),
|
|
||||||
)]))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Holds state relating to metrics
|
/// Holds state relating to metrics
|
||||||
|
|
@ -306,7 +307,7 @@ impl Metrics {
|
||||||
)
|
)
|
||||||
.expect("view should be valid"),
|
.expect("view should be valid"),
|
||||||
)
|
)
|
||||||
.with_resource(standard_resource())
|
.with_resource(standard_resource(env!("CARGO_PKG_NAME").to_owned()))
|
||||||
.build();
|
.build();
|
||||||
let meter = provider.meter(env!("CARGO_PKG_NAME"));
|
let meter = provider.meter(env!("CARGO_PKG_NAME"));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue