diff --git a/configx/provider.go b/configx/provider.go index 6f623c8f..6ae4c472 100644 --- a/configx/provider.go +++ b/configx/provider.go @@ -454,6 +454,7 @@ func (p *Provider) TracingConfig(serviceName string) *otelx.Config { Sampling: otelx.OTLPSampling{ SamplingRatio: p.Float64("tracing.providers.otlp.sampling.sampling_ratio"), }, + AuthorizationHeader: p.String("tracing.providers.otlp.authorization_header"), }, }, } diff --git a/otelx/config.go b/otelx/config.go index 66b033dd..32c2ec56 100644 --- a/otelx/config.go +++ b/otelx/config.go @@ -20,9 +20,10 @@ type ZipkinConfig struct { } type OTLPConfig struct { - ServerURL string `json:"server_url"` - Insecure bool `json:"insecure"` - Sampling OTLPSampling `json:"sampling"` + ServerURL string `json:"server_url"` + Insecure bool `json:"insecure"` + Sampling OTLPSampling `json:"sampling"` + AuthorizationHeader string `json:"authorization_header"` } type JaegerSampling struct { diff --git a/otelx/config.schema.json b/otelx/config.schema.json index dff7d119..2593b89d 100644 --- a/otelx/config.schema.json +++ b/otelx/config.schema.json @@ -134,6 +134,10 @@ "examples": [0.4] } } + }, + "authorization_header": { + "type": "string", + "examples": ["Bearer 2389s8fs9d8fus9f"] } } } diff --git a/otelx/otlp.go b/otelx/otlp.go index 8fdc40d1..e05db7c7 100644 --- a/otelx/otlp.go +++ b/otelx/otlp.go @@ -29,6 +29,12 @@ func SetupOTLP(t *Tracer, tracerName string, c *Config) (trace.Tracer, error) { clientOpts = append(clientOpts, otlptracehttp.WithInsecure()) } + if c.Providers.OTLP.AuthorizationHeader != "" { + clientOpts = append(clientOpts, + otlptracehttp.WithHeaders(map[string]string{"Authorization": c.Providers.OTLP.AuthorizationHeader}), + ) + } + exp, err := otlptrace.New( ctx, otlptracehttp.NewClient(clientOpts...), )