From cadf75e4fedf89287fc641367cd6145d7d5b60b9 Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Sat, 14 Mar 2026 03:18:51 +1100 Subject: [PATCH] fix: use configured service name for OTEL resources (#11818) # Which Problems Are Solved The OTEL service.name resource attribute is hardcoded to "ZITADEL" in setupOTelSDK, so the Instrumentation.ServiceName config and the OTEL_SERVICE_NAME environment variable are both ignored. This makes it impossible to distinguish between multiple Zitadel instances or co-located services in tracing dashboards and alerting rules. # How the Problems Are Solved The hardcoded string is replaced with cfg.ServiceName so the configured value flows through. An explicit check for the OTEL_SERVICE_NAME environment variable is added at the top of resourceWithService, giving it the highest priority per the OpenTelemetry specification. # Additional Changes None. # Additional Context Closes #11455 Backport to v4 --- backend/v3/instrumentation/otel.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/v3/instrumentation/otel.go b/backend/v3/instrumentation/otel.go index 7cc5a2fff..32ae63c91 100644 --- a/backend/v3/instrumentation/otel.go +++ b/backend/v3/instrumentation/otel.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "os" "time" "go.opentelemetry.io/otel" @@ -79,7 +80,7 @@ func setupOTelSDK(ctx context.Context, cfg Config) (*log.LoggerProvider, Shutdow prop := newPropagator() otel.SetTextMapPropagator(prop) - resource, err := resourceWithService("ZITADEL") + resource, err := resourceWithService(cfg.ServiceName) if err != nil { return nil, shutdown, err } @@ -121,6 +122,11 @@ func newPropagator() propagation.TextMapPropagator { } func resourceWithService(serviceName string) (*resource.Resource, error) { + // OTEL_SERVICE_NAME takes priority over programmatic config per the + // OpenTelemetry specification. + if envName := os.Getenv("OTEL_SERVICE_NAME"); envName != "" { + serviceName = envName + } attributes := []attribute.KeyValue{ semconv.ServiceNameKey.String(serviceName), }