mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 03:54:21 +00:00
168242e725
* 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
44 lines
1.0 KiB
Go
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")
|
|
}
|