2020-03-24 13:15:01 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2021-08-10 05:27:27 +00:00
|
|
|
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
|
2020-11-20 06:57:39 +00:00
|
|
|
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
2022-04-28 12:44:13 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
2020-03-24 13:15:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-04-28 15:35:56 +00:00
|
|
|
Fraction float64
|
2020-11-20 06:57:39 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 12:44:13 +00:00
|
|
|
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
|
|
|
c := new(Config)
|
2022-05-24 09:18:25 +00:00
|
|
|
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-04-28 12:44:13 +00:00
|
|
|
}
|
|
|
|
return c.NewTracer()
|
|
|
|
}
|
|
|
|
|
2020-11-20 06:57:39 +00:00
|
|
|
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))
|
2021-08-10 05:27:27 +00:00
|
|
|
exporter, err := stdout.New(stdout.WithPrettyPrint())
|
2020-11-20 06:57:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 15:35:56 +00:00
|
|
|
tracing.T, err = otel.NewTracer(sampler, exporter)
|
|
|
|
return err
|
2020-03-24 13:15:01 +00:00
|
|
|
}
|