2020-03-24 14:15:01 +01:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2020-12-02 08:50:59 +01:00
|
|
|
"github.com/caos/zitadel/internal/telemetry/tracing"
|
|
|
|
"github.com/caos/zitadel/internal/telemetry/tracing/otel"
|
2021-08-10 07:27:27 +02:00
|
|
|
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
|
2020-11-20 07:57:39 +01:00
|
|
|
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
2020-03-24 14:15:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-11-20 07:57:39 +01:00
|
|
|
Fraction float64
|
|
|
|
MetricPrefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Tracer struct {
|
|
|
|
otel.Tracer
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) NewTracer() error {
|
2020-11-20 07:57:39 +01:00
|
|
|
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
2021-08-10 07:27:27 +02:00
|
|
|
exporter, err := stdout.New(stdout.WithPrettyPrint())
|
2020-11-20 07:57:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|
|
|
|
|
2020-11-20 07:57:39 +01:00
|
|
|
tracing.T = &Tracer{Tracer: *(otel.NewTracer(c.MetricPrefix, sampler, exporter))}
|
|
|
|
return nil
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|