Skip to content

Commit 63e9520

Browse files
committed
chore: be more defensive with empty env var
Signed-off-by: jeluard <jeluard@users.noreply.github.com>
1 parent fee82b1 commit 63e9520

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crates/amaru/src/observability.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ pub fn setup_open_telemetry(subscriber: &mut TracingSubscriber<Registry>) -> (Op
275275
use opentelemetry::KeyValue;
276276
use opentelemetry_sdk::{Resource, metrics::Temporality};
277277

278-
let service_name = var("OTEL_SERVICE_NAME").unwrap_or_else(|_| DEFAULT_OTLP_SERVICE_NAME.to_string());
278+
let service_name =
279+
var("OTEL_SERVICE_NAME").unwrap_or_else(|_| DEFAULT_OTLP_SERVICE_NAME.to_string()).trim().to_string();
279280
let service_instance_id = var("OTEL_SERVICE_INSTANCE_ID").ok();
280281
let mut attributes = vec![KeyValue::new(SERVICE_NAME, service_name.clone())];
281-
if let Some(id) = service_instance_id {
282+
if let Some(id) = service_instance_id.filter(|value| !value.trim().is_empty()) {
282283
attributes.push(KeyValue::new(SERVICE_INSTANCE_ID, id));
283284
}
284285
let resource = Resource::builder().with_attributes(attributes).build();

0 commit comments

Comments
 (0)