Skip to content

Commit

Permalink
Handle empty strings from environment variables (#15)
Browse files Browse the repository at this point in the history
I misread strings.Split and hadn't picked up splitting `""` gives back `[""]`.
  • Loading branch information
greed42 authored Jan 9, 2023
1 parent 8fe9dfd commit 83d36de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/tracing/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func NewOTLPExporterFromEnv(ctx context.Context) (sdktrace.SpanExporter, error)
}

func NewProcessorsFromEnv(ctx context.Context) ([]sdktrace.SpanProcessor, error) {
enabled := strings.Split(strings.TrimSpace(os.Getenv("OTEL_TRACES_EXPORTER")), ",")
var enabled []string
if s := strings.TrimSpace(os.Getenv("OTEL_TRACES_EXPORTER")); s != "" {
enabled = strings.Split(s, ",")
}

// https://opentelemetry.io/docs/reference/specification/sdk-environment-variables/#exporter-selection
// Default exporter should be "otlp"; however to preserve compatibiltiy
Expand Down
7 changes: 6 additions & 1 deletion pkg/tracing/propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ func NewPropagatorsFromEnv() (propagation.TextMapPropagator, error) {
enabled := []string{"tracecontext", "baggage"}

if v, ok := os.LookupEnv("OTEL_PROPAGATORS"); ok {
enabled = strings.Split(strings.TrimSpace(v), ",")
if s := strings.TrimSpace(v); s != "" {
enabled = strings.Split(s, ",")
} else {
// Explicit empty string in the environment: clear the default.
enabled = nil
}
}

var propagators []propagation.TextMapPropagator
Expand Down

0 comments on commit 83d36de

Please sign in to comment.