2020-11-20 07:57:39 +01:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
|
2021-08-10 07:27:27 +02:00
|
|
|
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
2020-11-20 07:57:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-04-28 17:35:56 +02:00
|
|
|
ProjectID string
|
|
|
|
Fraction float64
|
2020-11-20 07:57:39 +01:00
|
|
|
}
|
|
|
|
|
2022-04-28 14:44:13 +02:00
|
|
|
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
|
|
|
c := new(Config)
|
|
|
|
c.ProjectID, _ = rawConfig["projectid"].(string)
|
2022-05-24 11:18:25 +02:00
|
|
|
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-04-28 14:44:13 +02:00
|
|
|
}
|
|
|
|
return c.NewTracer()
|
|
|
|
}
|
|
|
|
|
2020-11-20 07:57:39 +01:00
|
|
|
type Tracer struct {
|
|
|
|
otel.Tracer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) NewTracer() error {
|
|
|
|
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
2021-08-10 07:27:27 +02:00
|
|
|
exporter, err := texporter.New(texporter.WithProjectID(c.ProjectID))
|
2020-11-20 07:57:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:35:56 +02:00
|
|
|
tracing.T, err = otel.NewTracer(sampler, exporter)
|
|
|
|
return err
|
2020-11-20 07:57:39 +01:00
|
|
|
}
|