Declarative BatchSpanProcessor inherits ambient OTEL_BSP_* environment variables
Describe your environment
- Repository: open-telemetry/opentelemetry-python
- Tested commit: bc3bd9ce95a4772fe5ddb9e0edbeb313f4fcb1eb
- Branch: main, synchronized with upstream/main
- Operating system: Windows
- Python version: 3.14.3
- Package environment: uv workspace environment
The working tree was clean when the behavior was reproduced. I also checked that the issue is still present on the latest upstream/main commit listed above.
What happened?
When a BatchSpanProcessor is created through declarative configuration and one or more batch properties are omitted or set to null, the processor inherits values from the ambient OTEL_BSP_* environment variables.
The affected variables are:
- OTEL_BSP_MAX_QUEUE_SIZE
- OTEL_BSP_SCHEDULE_DELAY
- OTEL_BSP_MAX_EXPORT_BATCH_SIZE
- OTEL_BSP_EXPORT_TIMEOUT
The declarative configuration schema specifies defaults for omitted or null properties. However, create_span_processor passes None to the SDK BatchSpanProcessor constructor. The SDK constructor then reads the corresponding OTEL_BSP* environment variables.
Explicit values provided in the declarative configuration work correctly and take precedence.
Equivalent declarative logging and metrics configuration paths use explicit defaults and do not inherit their corresponding ambient SDK environment variables.
Steps to Reproduce
- Use the following minimal declarative configuration:
file_format: "1.0-rc.1"
tracer_provider:
processors:
- batch:
exporter:
console: {}
- Set the following environment variables before loading the configuration:
$env:OTEL_BSP_MAX_QUEUE_SIZE = "9999"
$env:OTEL_BSP_SCHEDULE_DELAY = "88888"
$env:OTEL_BSP_MAX_EXPORT_BATCH_SIZE = "777"
$env:OTEL_BSP_EXPORT_TIMEOUT = "66666"
-
Load the configuration using the public declarative configuration loader and configure the SDK.
-
Inspect the effective BatchSpanProcessor settings.
The effective values are:
max_queue_size: 9999
schedule_delay_millis: 88888
max_export_batch_size: 777
export_timeout_millis: 66666
-
Repeat the test with the four properties explicitly set to null. The ambient environment values are inherited again.
-
Unset all four environment variables and repeat the test. The expected defaults are then used:
max_queue_size: 2048
schedule_delay_millis: 5000
max_export_batch_size: 512
export_timeout_millis: 30000
I repeated the reproduction in separate Python processes and received the same result each time.
Expected Result
When the BatchSpanProcessor properties are omitted or set to null, declarative configuration should use the defaults defined by the configuration schema:
- max_queue_size: 2048
- schedule_delay: 5000
- max_export_batch_size: 512
- export_timeout: 30000
Ambient OTEL_BSP_* environment variables should not affect these values unless they are explicitly referenced through environment-variable substitution within the configuration file.
Explicit values provided in the configuration file should continue to take precedence.
Actual Result
When the properties are omitted or set to null, the resulting BatchSpanProcessor reads and uses the ambient OTEL_BSP_* environment variables.
With the reproduction values, the processor uses:
- max_queue_size: 9999
- schedule_delay_millis: 88888
- max_export_batch_size: 777
- export_timeout_millis: 66666
The issue appears to occur because opentelemetry-configuration/src/opentelemetry/configuration/_tracer_provider.py passes None values to the SDK BatchSpanProcessor constructor, which then performs its normal environment-variable fallback.
Additional context
I verified the following control cases:
- No OTEL_BSP_* variables and omitted properties: schema defaults are used.
- OTEL_BSP_* variables with explicit configuration values: explicit configuration values are used.
- OTEL_BSP_* variables with omitted properties: ambient values are inherited.
- OTEL_BSP_* variables with properties set to null: ambient values are inherited.
- Equivalent declarative logging and metrics configurations suppress their corresponding ambient environment variables.
The existing opentelemetry-configuration test suite passes, but I could not find regression coverage for OTEL_BSP_* suppression in the declarative tracer provider.
I searched open and closed issues and pull requests using OTEL_BSP, _create_span_processor, BatchSpanProcessor, and declarative configuration terms, but I did not find existing work covering this behavior.
I can prepare a focused fix and regression test if the expected behavior is confirmed.
Would you like to implement a fix?
Yes
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
I have reproduced this issue on the latest main branch and would like to work on the fix. If this approach sounds correct, could this issue please be assigned to me?
Yes, this is a known issue for all environment variables. We still need to align on a design approach before proceeding further.
Thanks for confirming. I’ll hold off on implementing the fix until the design approach is agreed upon.
Is there an existing issue, PR, or discussion tracking the broader environment-variable handling design? I’d be happy to help investigate the affected configuration paths, add test coverage, or contribute to the implementation once the preferred approach is clear.