@@ -45,6 +45,7 @@ const (
45
45
envProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL"
46
46
envHeaders = "OTEL_EXPORTER_OTLP_HEADERS"
47
47
envTracesHeaders = "OTEL_EXPORTER_OTLP_TRACES_HEADERS"
48
+ envMetricsHeaders = "OTEL_EXPORTER_OTLP_METRICS_HEADERS"
48
49
envResourceAttrs = "OTEL_RESOURCE_ATTRIBUTES"
49
50
)
50
51
@@ -229,8 +230,7 @@ type otlpOptions struct {
229
230
BaseURLPath string
230
231
URLPath string
231
232
SkipTLSVerify bool
232
- HTTPHeaders map [string ]string
233
- GRPCHeaders map [string ]string
233
+ Headers map [string ]string
234
234
}
235
235
236
236
func (o * otlpOptions ) AsMetricHTTP () []otlpmetrichttp.Option {
@@ -246,8 +246,8 @@ func (o *otlpOptions) AsMetricHTTP() []otlpmetrichttp.Option {
246
246
if o .SkipTLSVerify {
247
247
opts = append (opts , otlpmetrichttp .WithTLSClientConfig (& tls.Config {InsecureSkipVerify : true }))
248
248
}
249
- if len (o .HTTPHeaders ) > 0 {
250
- opts = append (opts , otlpmetrichttp .WithHeaders (o .HTTPHeaders ))
249
+ if len (o .Headers ) > 0 {
250
+ opts = append (opts , otlpmetrichttp .WithHeaders (o .Headers ))
251
251
}
252
252
return opts
253
253
}
@@ -262,8 +262,8 @@ func (o *otlpOptions) AsMetricGRPC() []otlpmetricgrpc.Option {
262
262
if o .SkipTLSVerify {
263
263
opts = append (opts , otlpmetricgrpc .WithTLSCredentials (credentials .NewTLS (& tls.Config {InsecureSkipVerify : true })))
264
264
}
265
- if len (o .GRPCHeaders ) > 0 {
266
- opts = append (opts , otlpmetricgrpc .WithHeaders (o .GRPCHeaders ))
265
+ if len (o .Headers ) > 0 {
266
+ opts = append (opts , otlpmetricgrpc .WithHeaders (o .Headers ))
267
267
}
268
268
return opts
269
269
}
@@ -281,8 +281,8 @@ func (o *otlpOptions) AsTraceHTTP() []otlptracehttp.Option {
281
281
if o .SkipTLSVerify {
282
282
opts = append (opts , otlptracehttp .WithTLSClientConfig (& tls.Config {InsecureSkipVerify : true }))
283
283
}
284
- if len (o .HTTPHeaders ) > 0 {
285
- opts = append (opts , otlptracehttp .WithHeaders (o .HTTPHeaders ))
284
+ if len (o .Headers ) > 0 {
285
+ opts = append (opts , otlptracehttp .WithHeaders (o .Headers ))
286
286
}
287
287
return opts
288
288
}
@@ -297,8 +297,8 @@ func (o *otlpOptions) AsTraceGRPC() []otlptracegrpc.Option {
297
297
if o .SkipTLSVerify {
298
298
opts = append (opts , otlptracegrpc .WithTLSCredentials (credentials .NewTLS (& tls.Config {InsecureSkipVerify : true })))
299
299
}
300
- if len (o .GRPCHeaders ) > 0 {
301
- opts = append (opts , otlptracegrpc .WithHeaders (o .GRPCHeaders ))
300
+ if len (o .Headers ) > 0 {
301
+ opts = append (opts , otlptracegrpc .WithHeaders (o .Headers ))
302
302
}
303
303
return opts
304
304
}
@@ -359,7 +359,7 @@ func (l *LogrAdaptor) WithName(name string) logr.LogSink {
359
359
return & LogrAdaptor {inner : l .inner .With ("name" , name )}
360
360
}
361
361
362
- func headersFromEnv (varName string ) map [string ]string {
362
+ func HeadersFromEnv (varName string ) map [string ]string {
363
363
headers := map [string ]string {}
364
364
365
365
addToMap := func (k string , v string ) {
@@ -404,3 +404,19 @@ func ResourceAttrsFromEnv(svc *svc.Attrs) []attribute.KeyValue {
404
404
parseOTELEnvVar (svc , envResourceAttrs , apply )
405
405
return otelResourceAttrs
406
406
}
407
+
408
+ func ResolveOTLPEndpoint (endpoint , common string , grafana * GrafanaOTLP ) (string , bool ) {
409
+ if endpoint != "" {
410
+ return endpoint , false
411
+ }
412
+
413
+ if common != "" {
414
+ return common , true
415
+ }
416
+
417
+ if grafana != nil && grafana .CloudZone != "" && grafana .Endpoint () != "" {
418
+ return grafana .Endpoint (), true
419
+ }
420
+
421
+ return "" , false
422
+ }
0 commit comments