mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
feat: set service name in tracing (#3533)
This commit is contained in:
parent
44a2b81bef
commit
2af3e228e4
@ -12,15 +12,13 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ProjectID string
|
||||
MetricPrefix string
|
||||
Fraction float64
|
||||
ProjectID string
|
||||
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)
|
||||
@ -43,7 +41,6 @@ func (c *Config) NewTracer() error {
|
||||
return err
|
||||
}
|
||||
|
||||
tracing.T = &Tracer{Tracer: *(otel.NewTracer(c.MetricPrefix, sampler, exporter))}
|
||||
|
||||
return nil
|
||||
tracing.T, err = otel.NewTracer(sampler, exporter)
|
||||
return err
|
||||
}
|
||||
|
@ -12,13 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Fraction float64
|
||||
MetricPrefix string
|
||||
Fraction float64
|
||||
}
|
||||
|
||||
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
c.MetricPrefix, _ = rawConfig["metricprefix"].(string)
|
||||
fraction, ok := rawConfig["fraction"].(string)
|
||||
if ok {
|
||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
||||
@ -41,6 +39,6 @@ func (c *Config) NewTracer() error {
|
||||
return err
|
||||
}
|
||||
|
||||
tracing.T = &Tracer{Tracer: *(otel.NewTracer(c.MetricPrefix, sampler, exporter))}
|
||||
return nil
|
||||
tracing.T, err = otel.NewTracer(sampler, exporter)
|
||||
return err
|
||||
}
|
||||
|
@ -12,15 +12,13 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Fraction float64
|
||||
MetricPrefix string
|
||||
Endpoint string
|
||||
Fraction float64
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
func NewTracerFromConfig(rawConfig map[string]interface{}) (err error) {
|
||||
c := new(Config)
|
||||
c.Endpoint, _ = rawConfig["endpoint"].(string)
|
||||
c.MetricPrefix, _ = rawConfig["metricprefix"].(string)
|
||||
fraction, ok := rawConfig["fraction"].(string)
|
||||
if ok {
|
||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
||||
@ -39,6 +37,6 @@ func (c *Config) NewTracer() error {
|
||||
return err
|
||||
}
|
||||
|
||||
tracing.T = NewTracer(c.MetricPrefix, sampler, exporter)
|
||||
return nil
|
||||
tracing.T, err = NewTracer(sampler, exporter)
|
||||
return err
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ import (
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
|
||||
api_trace "go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
@ -17,19 +19,30 @@ type Tracer struct {
|
||||
sampler sdk_trace.Sampler
|
||||
}
|
||||
|
||||
func NewTracer(name string, sampler sdk_trace.Sampler, exporter sdk_trace.SpanExporter) *Tracer {
|
||||
func NewTracer(sampler sdk_trace.Sampler, exporter sdk_trace.SpanExporter) (*Tracer, error) {
|
||||
resource, err := resource.Merge(
|
||||
resource.Default(),
|
||||
resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
semconv.ServiceNameKey.String("ZITADEL"),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spanProcessor := sdk_trace.NewBatchSpanProcessor(exporter)
|
||||
tp := sdk_trace.NewTracerProvider(
|
||||
sdk_trace.WithSampler(sampler),
|
||||
sdk_trace.WithBatcher(exporter),
|
||||
sdk_trace.WithSpanProcessor(spanProcessor),
|
||||
sdk_trace.WithResource(resource),
|
||||
)
|
||||
|
||||
otel.SetTracerProvider(tp)
|
||||
tc := propagation.TraceContext{}
|
||||
otel.SetTextMapPropagator(tc)
|
||||
|
||||
return &Tracer{Exporter: tp.Tracer(name), sampler: sampler}
|
||||
return &Tracer{Exporter: tp.Tracer(""), sampler: sampler}, nil
|
||||
}
|
||||
|
||||
func (t *Tracer) Sampler() sdk_trace.Sampler {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
grpc_errs "github.com/zitadel/zitadel/internal/api/grpc/errors"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
grpc_errs "github.com/zitadel/zitadel/internal/api/grpc/errors"
|
||||
)
|
||||
|
||||
type Span struct {
|
||||
|
Loading…
Reference in New Issue
Block a user