Skip to content

Commit

Permalink
feat: add Authorization header to OTEL config (CORE-2291) (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
splaunov authored Aug 3, 2023
1 parent 19829a9 commit 21b1639
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions configx/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
}
Expand Down
7 changes: 4 additions & 3 deletions otelx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions otelx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
"examples": [0.4]
}
}
},
"authorization_header": {
"type": "string",
"examples": ["Bearer 2389s8fs9d8fus9f"]
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions otelx/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
)
Expand Down

0 comments on commit 21b1639

Please sign in to comment.