mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
fix(tracing): parsing of fraction (#3705)
* fix(tracing): parsing of fraction * log id
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
|
||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
||||
)
|
||||
@@ -19,14 +16,10 @@ type Config struct {
|
||||
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
c.ProjectID, _ = rawConfig["projectid"].(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")
|
||||
}
|
||||
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.NewTracer()
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,9 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
|
||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
||||
)
|
||||
@@ -17,14 +14,10 @@ type Config struct {
|
||||
|
||||
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
fraction, ok := rawConfig["fraction"].(string)
|
||||
if ok {
|
||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "LOG-Dsag3", "could not map fraction")
|
||||
}
|
||||
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.NewTracer()
|
||||
}
|
||||
|
||||
|
@@ -19,17 +19,33 @@ type Config struct {
|
||||
func NewTracerFromConfig(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
c.Endpoint, _ = rawConfig["endpoint"].(string)
|
||||
fraction, ok := rawConfig["fraction"].(string)
|
||||
if ok {
|
||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "OTEL-Dd2s", "could not map fraction")
|
||||
}
|
||||
c.Fraction, err = FractionFromConfig(rawConfig["fraction"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.NewTracer()
|
||||
}
|
||||
|
||||
func FractionFromConfig(i interface{}) (float64, error) {
|
||||
if i == nil {
|
||||
return 0, nil
|
||||
}
|
||||
switch fraction := i.(type) {
|
||||
case float64:
|
||||
return fraction, nil
|
||||
case int:
|
||||
return float64(fraction), nil
|
||||
case string:
|
||||
f, err := strconv.ParseFloat(fraction, 64)
|
||||
if err != nil {
|
||||
return 0, errors.ThrowInternal(err, "OTEL-SAfe1", "could not map fraction")
|
||||
}
|
||||
return f, nil
|
||||
default:
|
||||
return 0, errors.ThrowInternal(nil, "OTEL-Dd2s", "could not map fraction, unknown type")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) NewTracer() error {
|
||||
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
||||
exporter, err := otlpgrpc.New(context.Background(), otlpgrpc.WithEndpoint(c.Endpoint), otlpgrpc.WithInsecure())
|
||||
|
Reference in New Issue
Block a user