diff --git a/CHANGELOG.md b/CHANGELOG.md index bd817ab8e9f..7c5f89ae12c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Generate server metrics with semantic conventions v1.26 in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http/dup`. (#6411) +### Fixed + +- Fix error logged by Jaeger remote sampler on empty or unset `OTEL_TRACES_SAMPLER_ARG` environment variable (#6511) + ## [1.33.0/0.58.0/0.27.0/0.13.0/0.8.0/0.6.0/0.5.0] - 2024-12-12 ### Added diff --git a/samplers/jaegerremote/sampler_remote_options.go b/samplers/jaegerremote/sampler_remote_options.go index 2922ec6484b..14ba52c044b 100644 --- a/samplers/jaegerremote/sampler_remote_options.go +++ b/samplers/jaegerremote/sampler_remote_options.go @@ -46,7 +46,12 @@ func getEnvOptions() ([]Option, []error) { // list of errors which will be logged once logger is set by the user var errs []error - args := strings.Split(os.Getenv("OTEL_TRACES_SAMPLER_ARG"), ",") + rawEnvArgs := os.Getenv("OTEL_TRACES_SAMPLER_ARG") + if rawEnvArgs == "" { + return nil, nil + } + + args := strings.Split(rawEnvArgs, ",") for _, arg := range args { keyValue := strings.Split(arg, "=") if len(keyValue) != 2 { diff --git a/samplers/jaegerremote/sampler_remote_test.go b/samplers/jaegerremote/sampler_remote_test.go index 93b16da4615..19ecb0c9b1d 100644 --- a/samplers/jaegerremote/sampler_remote_test.go +++ b/samplers/jaegerremote/sampler_remote_test.go @@ -22,6 +22,7 @@ import ( "encoding/binary" "errors" "fmt" + "os" "sync" "testing" "time" @@ -653,4 +654,33 @@ func TestEnvVarSettingForNewTracer(t *testing.T) { } }) } + + t.Run("No-op when env var not set or empty", func(t *testing.T) { + for _, test := range []struct { + desc string + envSetup func() + }{ + { + "env var empty", + func() { t.Setenv("OTEL_TRACES_SAMPLER_ARG", "") }, + }, + { + "env var unset", + func() { + // t.Setenv to restore this environment variable at the end of the test + t.Setenv("OTEL_TRACES_SAMPLER_ARG", "") + // unset it during the test + require.NoError(t, os.Unsetenv("OTEL_TRACES_SAMPLER_ARG")) + }, + }, + } { + t.Run(test.desc, func(t *testing.T) { + test.envSetup() + opts, errs := getEnvOptions() + + require.Empty(t, errs) + require.Empty(t, opts) + }) + } + }) }