Files
zitadel/internal/telemetry/tracing/google/google_tracer.go
Harsha Reddy dc64e35128 feat: Make service name configurable for Metrics and Tracing (#9563)
# Which Problems Are Solved

The service name is hardcoded in the metrics code. Making the service
name to be configurable helps when running multiple instances of
Zitadel.

The defaults remain unchanged, the service name will be defaulted to
ZITADEL.

# How the Problems Are Solved

Add a config option to override the name in defaults.yaml and pass it
down to the corresponding metrics or tracing module (google or otel)

# Additional Changes
NA

# Additional Context
NA
2025-03-20 09:35:54 +00:00

42 lines
1005 B
Go

package google
import (
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
"github.com/zitadel/zitadel/internal/telemetry/tracing"
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
)
type Config struct {
ProjectID string
Fraction float64
ServiceName string
}
func NewTracer(rawConfig map[string]interface{}) (err error) {
c := new(Config)
c.ProjectID, _ = rawConfig["projectid"].(string)
c.ServiceName, _ = rawConfig["servicename"].(string)
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
if err != nil {
return err
}
return c.NewTracer()
}
type Tracer struct {
otel.Tracer
}
func (c *Config) NewTracer() error {
sampler := otel.NewSampler(sdk_trace.TraceIDRatioBased(c.Fraction))
exporter, err := texporter.New(texporter.WithProjectID(c.ProjectID))
if err != nil {
return err
}
tracing.T, err = otel.NewTracer(sampler, exporter, c.ServiceName)
return err
}