Skip to content

feat(config): Add LoggerProvider support for declarative config#4990

Draft
MikeGoldsmith wants to merge 11 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-logger-provider
Draft

feat(config): Add LoggerProvider support for declarative config#4990
MikeGoldsmith wants to merge 11 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-logger-provider

Conversation

@MikeGoldsmith
Copy link
Member

Description

Implements `create_logger_provider()` and `configure_logger_provider()` for the declarative configuration pipeline, as part of the ongoing work tracked in the following issue:

Note

This PR is based on #4979 (Resource & Propagator creation) which must be merged first. The extra commits at the base of this branch will be dropped once that PR lands.

What's included

  • `_logger_provider.py`: creates an SDK `LoggerProvider` from declarative config
  • Supports `BatchLogRecordProcessor` with schedule_delay/export_timeout/max_queue_size/max_export_batch_size config
  • Supports `SimpleLogRecordProcessor`
  • Supports OTLP HTTP, OTLP gRPC, and Console log exporters
  • Lazy imports for optional OTLP packages with a `ConfigurationError` if not installed
  • `configure_logger_provider(None)` is a no-op per spec/Java/JS behavior
  • `otlp_file_development` raises `ConfigurationError` (experimental; not yet supported)
  • `log_record_limits` logs a warning if specified — Python SDK `LoggerProvider` constructor does not accept limits
  • 28 new tests covering all paths including env-var suppression

Env-var suppression

Python's `BatchLogRecordProcessor` reads `OTEL_BLRP_*` env vars when params are `None`. To match the spec's "what you see is what you get" semantics, we always pass explicit values — defaulting to spec defaults. Notably, the Python SDK's default for `OTEL_BLRP_SCHEDULE_DELAY` is 5000ms (incorrect per spec); we pass 1000ms per the OTel spec.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • 28 unit tests in `tests/_configuration/test_logger_provider.py`
  • Includes explicit test that `OTEL_BLRP_SCHEDULE_DELAY` env var is not read when config is used

Does This PR Require a Contrib Repo Change?

No.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Implements create_resource() and create_propagator()/configure_propagator()
for the declarative file configuration. Resource creation does not read
OTEL_RESOURCE_ATTRIBUTES or run any detectors (matches Java/JS SDK behavior).
Propagator configuration always calls set_global_textmap to override Python's
default tracecontext+baggage, setting a noop CompositePropagator when no
propagator is configured.

Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
- _resource.py: refactor _coerce_attribute_value to dispatch table to
  avoid too-many-return-statements; fix short variable names k/v ->
  attr_key/attr_val; fix return type of _sdk_default_attributes to
  dict[str, str] to satisfy pyright
- _propagator.py: rename short variable names e -> exc, p -> propagator
- test_resource.py: move imports to top level; split TestCreateResource
  (25 methods) into three focused classes to satisfy too-many-public-methods
- test_propagator.py: add pylint disable for protected-access

Assisted-by: Claude Sonnet 4.6
- replace _sdk_default_attributes() with _DEFAULT_RESOURCE from resources module
- move _coerce_bool into dispatch tables for both scalar and array bool types,
  fixing a bug where bool_array with string values like "false" would coerce
  incorrectly via plain bool() (non-empty string -> True)
- add test for bool_array with string values to cover the bug

Assisted-by: Claude Sonnet 4.6
…erge

- collapse _SCALAR_COERCIONS and _ARRAY_COERCIONS into a single _COERCIONS
  dict using an _array() factory, reducing _coerce_attribute_value to two lines
- process attributes_list before attributes so explicit attributes naturally
  overwrite list entries without needing an explicit guard

Assisted-by: Claude Sonnet 4.6
…config

Implements LoggerProvider instantiation from declarative config files,
following the same env-var-suppression pattern as create_meter_provider.
BatchLogRecordProcessor defaults use spec values (1000ms schedule_delay),
overriding the Python SDK's incorrect 5000ms env-var default.

Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith MikeGoldsmith changed the title feat(config): add create_logger_provider/configure_logger_provider for declarative config feat(config): Add LoggerProvider support for declarative config Mar 18, 2026
Copy link

@themavik themavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition. In _logger_provider.py, _parse_headers: when headers_list has a pair like "key=", the split gives value="" — that's fine. But if someone passes "key" (no equals), you warn and skip. Consider whether an empty value should be allowed for "key=" or if that should also warn. Minor — the current behavior is reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants