mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
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:
@@ -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),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user