mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:57:33 +00:00
feat: enable tracing (#3528)
This commit is contained in:
@@ -2,10 +2,13 @@ package otel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
otlpgrpc "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -14,6 +17,21 @@ type Config struct {
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
func NewTracerFromConfig(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
c.Endpoint, _ = rawConfig["endpoint"].(string)
|
||||
c.MetricPrefix, _ = rawConfig["metricprefix"].(string)
|
||||
fraction, ok := rawConfig["fraction"].(string)
|
||||
if ok {
|
||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "OTEL-Dd2s", "could not map fraction")
|
||||
}
|
||||
}
|
||||
|
||||
return c.NewTracer()
|
||||
}
|
||||
|
||||
func (c *Config) NewTracer() error {
|
||||
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
||||
exporter, err := otlpgrpc.New(context.Background(), otlpgrpc.WithEndpoint(c.Endpoint), otlpgrpc.WithInsecure())
|
||||
|
Reference in New Issue
Block a user