diff --git a/util/tracing/detect/detect.go b/util/tracing/detect/detect.go index 7dece5b2f..3dbbeb6f4 100644 --- a/util/tracing/detect/detect.go +++ b/util/tracing/detect/detect.go @@ -45,7 +45,7 @@ func (fn TraceExporterDetector) DetectMetricExporter() (sdkmetric.Exporter, erro } func detectExporter[T any](envVar string, fn func(d ExporterDetector) (T, bool, error)) (exp T, err error) { - ignoreErrors, _ := strconv.ParseBool("OTEL_IGNORE_ERROR") + ignoreErrors, _ := strconv.ParseBool(os.Getenv("OTEL_IGNORE_ERROR")) if n := os.Getenv(envVar); n != "" { d, ok := detectors[n] diff --git a/util/tracing/detect/detect_test.go b/util/tracing/detect/detect_test.go new file mode 100644 index 000000000..c5dcfde62 --- /dev/null +++ b/util/tracing/detect/detect_test.go @@ -0,0 +1,43 @@ +package detect + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDetectExporterIgnoreErrors(t *testing.T) { + for _, tc := range []struct { + name string + ignoreErrors string + wantErr bool + }{ + { + name: "error by default", + wantErr: true, + }, + { + name: "ignore errors", + ignoreErrors: "true", + }, + } { + t.Run(tc.name, func(t *testing.T) { + t.Setenv("OTEL_TRACES_EXPORTER", "invalid") + t.Setenv("OTEL_METRICS_EXPORTER", "invalid") + t.Setenv("OTEL_IGNORE_ERROR", tc.ignoreErrors) + + spanExp, spanErr := NewSpanExporter(context.Background()) + metricExp, metricErr := NewMetricExporter(context.Background()) + if tc.wantErr { + require.Error(t, spanErr) + require.Error(t, metricErr) + } else { + require.NoError(t, spanErr) + require.NoError(t, metricErr) + } + require.Nil(t, spanExp) + require.Nil(t, metricExp) + }) + } +}