mirror of
https://github.com/moby/buildkit.git
synced 2026-08-09 01:01:08 +00:00
detect: read OTEL_IGNORE_ERROR from environment
Signed-off-by: Simon Aguilera <saguilera1608@gmail.com>
This commit is contained in:
@@ -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]
|
||||
|
||||
43
util/tracing/detect/detect_test.go
Normal file
43
util/tracing/detect/detect_test.go
Normal file
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user