sdk/trace: NewBatchSpanProcessor panics on negative OTEL_BSP_MAX_QUEUE_SIZE or OTEL_BSP_MAX_EXPORT_BATCH_SIZE

Author: aman99dexCreated Sep 22, 2026Updated Sep 22, 2026

Description

sdktrace.NewBatchSpanProcessor panics when OTEL_BSP_MAX_QUEUE_SIZE or OTEL_BSP_MAX_EXPORT_BATCH_SIZE is set to a negative integer.

The environment values are only parsed with strconv.Atoi (sdk/trace/internal/env/env.go) and are not range-checked. They are then used directly as the capacity in make([]ReadOnlySpan, 0, o.MaxExportBatchSize) in NewBatchSpanProcessor:

  • OTEL_BSP_MAX_EXPORT_BATCH_SIZE=-1 gives a batch capacity of -1.
  • OTEL_BSP_MAX_QUEUE_SIZE=-1 gives maxExportBatchSize > maxQueueSize, so the batch size becomes min(DefaultMaxExportBatchSize, -1) = -1.

A misconfigured environment variable can therefore crash the host application during SDK setup.

The spec says valid values are positive for both variables. The log SDK's BatchProcessor already ignores values below 1 for the equivalent OTEL_BLRP_* variables (clearLessThanOne in sdk/log/batch.go).

Environment

  • OS: Windows
  • Architecture: amd64
  • Go Version: 1.27.0
  • opentelemetry-go version: 29413a626 (sdk/trace/batch_span_processor.go and sdk/trace/internal/env/env.go are unchanged on current main)

Steps To Reproduce

go
package main

import (
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"go.opentelemetry.io/otel/sdk/trace/tracetest"
)

func main() {
	sdktrace.NewBatchSpanProcessor(tracetest.NewInMemoryExporter())
}
bash
$ OTEL_BSP_MAX_QUEUE_SIZE=-1 go run .
panic: runtime error: makeslice: cap out of range

$ OTEL_BSP_MAX_EXPORT_BATCH_SIZE=-1 go run .
panic: runtime error: makeslice: cap out of range

Expected behavior

Invalid (non-positive) OTEL_BSP_* values should not panic. They should be ignored and the defaults used, as the log SDK's BatchProcessor does for OTEL_BLRP_*, ideally with a warning as the spec's numeric guidance suggests.

Source: open-telemetry/opentelemetry-go