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
This commit is contained in:
Mridang Agarwalla
2026-03-13 16:18:51 +00:00
committed by GitHub
parent 3c3201e5a0
commit cadf75e4fe
+7 -1
View File
@@ -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),
}