diff --git a/cmd/relayproxy/api/opentelemetry/otel.go b/cmd/relayproxy/api/opentelemetry/otel.go index a7ff6498d93..4a331a3e433 100644 --- a/cmd/relayproxy/api/opentelemetry/otel.go +++ b/cmd/relayproxy/api/opentelemetry/otel.go @@ -30,7 +30,7 @@ func NewOtelService() OtelService { func (s *OtelService) Init(ctx context.Context, zapLog *zap.Logger, config config.Config) error { // Require the endpoint to be set either by the openTelemetryOtlpEndpoint // config element or otel.exporter.otlp.endpoint - if config.OpenTelemetryOtlpEndpoint == "" && config.OtelConfig.Exporter.Otlp.Endpoint == "" { + if (config.OpenTelemetryOtlpEndpoint == "" && config.OtelConfig.Exporter.Otlp.Endpoint == "") || config.OtelConfig.SDK.Disabled { otel.SetTracerProvider(noop.NewTracerProvider()) return nil } diff --git a/cmd/relayproxy/api/opentelemetry/otel_test.go b/cmd/relayproxy/api/opentelemetry/otel_test.go index 7e04622c6e8..328d0012dae 100644 --- a/cmd/relayproxy/api/opentelemetry/otel_test.go +++ b/cmd/relayproxy/api/opentelemetry/otel_test.go @@ -177,6 +177,7 @@ func TestInit(t *testing.T) { t.Run("disabled", func(t *testing.T) { t.Setenv("OTEL_SDK_DISABLED", "true") + t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "https://example.com:4318") f := pflag.NewFlagSet("config", pflag.ContinueOnError) c, errC := config.New(f, zap.L(), "1.X.X") require.NoError(t, errC)