mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:37:34 +00:00
feat: enable tracing (#3528)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"strconv"
|
||||
|
||||
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
|
||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||
@@ -18,15 +17,26 @@ type Config struct {
|
||||
Fraction float64
|
||||
}
|
||||
|
||||
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
c.ProjectID, _ = rawConfig["projectid"].(string)
|
||||
c.MetricPrefix, _ = rawConfig["metricprefix"].(string)
|
||||
fraction, ok := rawConfig["fraction"].(string)
|
||||
if ok {
|
||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "GOOGLE-Dsag3", "could not map fraction")
|
||||
}
|
||||
}
|
||||
|
||||
return c.NewTracer()
|
||||
}
|
||||
|
||||
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.New(texporter.WithProjectID(c.ProjectID))
|
||||
if err != nil {
|
||||
@@ -37,8 +47,3 @@ func (c *Config) NewTracer() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func envIsSet() bool {
|
||||
gAuthCred := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
return strings.Contains(gAuthCred, ".json")
|
||||
}
|
||||
|
Reference in New Issue
Block a user