From d6796c002f9ba0da81f8a5430fa18c3f260839f7 Mon Sep 17 00:00:00 2001 From: Christopher Petito Date: Wed, 17 Apr 2024 14:32:41 +0000 Subject: [PATCH] Fix OTLP env var overriding Signed-off-by: Christopher Petito --- cli/command/telemetry_docker.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/cli/command/telemetry_docker.go b/cli/command/telemetry_docker.go index 9f6253af48..5dc72e2bb5 100644 --- a/cli/command/telemetry_docker.go +++ b/cli/command/telemetry_docker.go @@ -41,24 +41,20 @@ func dockerExporterOTLPEndpoint(cli Cli) (endpoint string, secure bool) { otelCfg = m[otelContextFieldName] } - if otelCfg == nil { - return "", false + if otelCfg != nil { + otelMap, ok := otelCfg.(map[string]any) + if !ok { + otel.Handle(errors.Errorf( + "unexpected type for field %q: %T (expected: %T)", + otelContextFieldName, + otelCfg, + otelMap, + )) + } + // keys from https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/ + endpoint, _ = otelMap[otelExporterOTLPEndpoint].(string) } - otelMap, ok := otelCfg.(map[string]any) - if !ok { - otel.Handle(errors.Errorf( - "unexpected type for field %q: %T (expected: %T)", - otelContextFieldName, - otelCfg, - otelMap, - )) - return "", false - } - - // keys from https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/ - endpoint, _ = otelMap[otelExporterOTLPEndpoint].(string) - // Override with env var value if it exists AND IS SET // (ignore otel defaults for this override when the key exists but is empty) if override := os.Getenv(debugEnvVarPrefix + otelExporterOTLPEndpoint); override != "" {