mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-18 13:57:32 +00:00
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")
|
||
|
}
|