Skip to content

Commit

Permalink
Fix: error logged on empty OTEL_TRACES_SAMPLER_ARG (#6511)
Browse files Browse the repository at this point in the history
Co-authored-by: Damien Mathieu <[email protected]>
  • Loading branch information
matthewhughes934 and dmathieu authored Jan 6, 2025
1 parent dee94b1 commit 96acbc0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion samplers/jaegerremote/sampler_remote_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 30 additions & 0 deletions samplers/jaegerremote/sampler_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"os"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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)
})
}
})
}

0 comments on commit 96acbc0

Please sign in to comment.