zitadel/internal/tracing/google/google_tracer.go
Silvan 168242e725
fix(tracing): from opencensus to opentelemetry (#937)
* refactor: switch from opencensus to opentelemetry

* tempo works as designed nooooot

* fix: log traceids

* with grafana agent

* fix: http tracing

* fix: cleanup files

* chore: remove todo

* fix: bad test

* fix: ignore methods in grpc interceptors

* fix: remove test log

* clean up

* typo

* fix(config): configure tracing endpoint

* fix(span): add error id to span
2020-11-20 07:57:39 +01:00

44 lines
1.0 KiB
Go

package google
import (
"os"
"strings"
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/tracing"
"github.com/caos/zitadel/internal/tracing/otel"
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
)
type Config struct {
ProjectID string
MetricPrefix string
Fraction float64
}
type Tracer struct {
otel.Tracer
}
func (c *Config) NewTracer() error {
if !envIsSet() {
return errors.ThrowInvalidArgument(nil, "GOOGL-sdh3a", "env not properly set, GOOGLE_APPLICATION_CREDENTIALS is misconfigured or missing")
}
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
exporter, err := texporter.NewExporter(texporter.WithProjectID(c.ProjectID))
if err != nil {
return err
}
tracing.T = &Tracer{Tracer: *(otel.NewTracer(c.MetricPrefix, sampler, exporter))}
return nil
}
func envIsSet() bool {
gAuthCred := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
return strings.Contains(gAuthCred, ".json")
}