Skip to content

Commit 7fcefa1

Browse files
committed
fix: do not blindly override attributes
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
1 parent fe325e8 commit 7fcefa1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/amaru/src/observability.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ pub fn setup_open_telemetry(
285285
use opentelemetry::KeyValue;
286286
use opentelemetry_sdk::{Resource, metrics::Temporality};
287287

288+
// Build the SDK-default resource first to discover any pre-configured attributes
289+
// (e.g. via OTEL_RESOURCE_ATTRIBUTES), so we only add our fallback values when absent.
290+
let default_resource = Resource::builder().build();
291+
288292
let service_name =
289293
var("OTEL_SERVICE_NAME").unwrap_or_else(|_| DEFAULT_OTLP_SERVICE_NAME.to_string()).trim().to_string();
290294
let service_instance_id: Option<String> =
@@ -294,9 +298,14 @@ pub fn setup_open_telemetry(
294298
let port = listen_addr.trim().rsplit(':').next()?;
295299
Some(format!("{hostname}:{port}"))
296300
});
297-
let mut attributes = vec![KeyValue::new(SERVICE_NAME, service_name.clone())];
301+
let mut attributes = Vec::new();
302+
if default_resource.get(&opentelemetry::Key::from_static_str(SERVICE_NAME)).is_none() {
303+
attributes.push(KeyValue::new(SERVICE_NAME, service_name.clone()));
304+
}
298305
if let Some(instance_id) = service_instance_id {
299-
attributes.push(KeyValue::new(SERVICE_INSTANCE_ID, instance_id));
306+
if default_resource.get(&opentelemetry::Key::from_static_str(SERVICE_INSTANCE_ID)).is_none() {
307+
attributes.push(KeyValue::new(SERVICE_INSTANCE_ID, instance_id));
308+
}
300309
}
301310
let resource = Resource::builder().with_attributes(attributes).build();
302311

0 commit comments

Comments
 (0)