feat: enable tracing (#3528)

This commit is contained in:
Livio Amstutz
2022-04-28 14:44:13 +02:00
committed by GitHub
parent 08ae39ae19
commit 44a2b81bef
6 changed files with 76 additions and 70 deletions

View File

@@ -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())