mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
feat: enable tracing (#3528)
This commit is contained in:
@@ -1,69 +1,34 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/google"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/log"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
||||
)
|
||||
|
||||
type TracingConfig struct {
|
||||
type Config struct {
|
||||
Type string
|
||||
Config tracing.Config
|
||||
Config map[string]interface{} `mapstructure:",remain"`
|
||||
}
|
||||
|
||||
var tracer = map[string]func() tracing.Config{
|
||||
"otel": func() tracing.Config { return &otel.Config{} },
|
||||
"google": func() tracing.Config { return &google.Config{} },
|
||||
"log": func() tracing.Config { return &log.Config{} },
|
||||
"none": func() tracing.Config { return &NoTracing{} },
|
||||
"": func() tracing.Config { return &NoTracing{} },
|
||||
}
|
||||
|
||||
func (c *TracingConfig) UnmarshalJSON(data []byte) error {
|
||||
var rc struct {
|
||||
Type string
|
||||
Config json.RawMessage
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &rc); err != nil {
|
||||
return errors.ThrowInternal(err, "TRACE-vmjS", "error parsing config")
|
||||
}
|
||||
|
||||
c.Type = rc.Type
|
||||
|
||||
var err error
|
||||
c.Config, err = newTracingConfig(c.Type, rc.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Config.NewTracer()
|
||||
}
|
||||
|
||||
func newTracingConfig(tracerType string, configData []byte) (tracing.Config, error) {
|
||||
t, ok := tracer[tracerType]
|
||||
func (c *Config) NewTracer() error {
|
||||
t, ok := tracer[c.Type]
|
||||
if !ok {
|
||||
return nil, errors.ThrowInternalf(nil, "TRACE-HMEJ", "config type %s not supported", tracerType)
|
||||
return errors.ThrowInternalf(nil, "TRACE-dsbjh", "config type %s not supported", c.Type)
|
||||
}
|
||||
|
||||
tracingConfig := t()
|
||||
if len(configData) == 0 {
|
||||
return tracingConfig, nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(configData, tracingConfig); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "TRACE-1tSS", "Could not read config: %v")
|
||||
}
|
||||
|
||||
return tracingConfig, nil
|
||||
return t(c.Config)
|
||||
}
|
||||
|
||||
type NoTracing struct{}
|
||||
var tracer = map[string]func(map[string]interface{}) error{
|
||||
"otel": otel.NewTracerFromConfig,
|
||||
"google": google.NewTracer,
|
||||
"log": log.NewTracer,
|
||||
"none": NoTracer,
|
||||
"": NoTracer,
|
||||
}
|
||||
|
||||
func (_ *NoTracing) NewTracer() error {
|
||||
func NoTracer(_ map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user