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