Skip to content

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

Merged
xrmx merged 30 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-logger-provider
Apr 13, 2026
Merged

feat(config): Add LoggerProvider support for declarative config#4990
xrmx merged 30 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-logger-provider

Conversation

@MikeGoldsmith
Copy link
Copy Markdown
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
MikeGoldsmith added a commit to MikeGoldsmith/opentelemetry-python that referenced this pull request Mar 17, 2026
@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
Assisted-by: Claude Sonnet 4.6
Adds _run_detectors() stub and _filter_attributes() to create_resource(),
providing the shared scaffolding for detector PRs to build on. Detectors
are opt-in: nothing runs unless explicitly listed under
detection_development.detectors in the config. The include/exclude
attribute filter mirrors other SDK behaviour.

Assisted-by: Claude Sonnet 4.6
Merges service.name=unknown_service into base before running detectors,
so detectors (e.g. service) can override it. Previously it was added to
config_attrs and merged last, which would have silently overridden any
detector-provided service.name.

Assisted-by: Claude Sonnet 4.6
MikeGoldsmith added a commit to MikeGoldsmith/opentelemetry-python that referenced this pull request Mar 20, 2026
@MikeGoldsmith MikeGoldsmith force-pushed the mike/config-logger-provider branch from 90ab88b to d149d79 Compare March 20, 2026 14:30
…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 force-pushed the mike/config-logger-provider branch from d149d79 to 31933ef Compare March 20, 2026 19:40
Import directly from _exceptions.py since this is new code with no existing
dependents on the _loader module path.

Assisted-by: Claude Sonnet 4.6
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_propagator.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_propagator.py Outdated
@MikeGoldsmith MikeGoldsmith marked this pull request as ready for review April 3, 2026 15:24
@MikeGoldsmith MikeGoldsmith requested a review from a team as a code owner April 3, 2026 15:24
Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith MikeGoldsmith added the config Issues and PRs related to implementing Declarative Config label Apr 8, 2026
@MikeGoldsmith MikeGoldsmith moved this to Approved PRs in Python PR digest Apr 8, 2026
Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_logger_provider.py Outdated
@MikeGoldsmith MikeGoldsmith force-pushed the mike/config-logger-provider branch from 9af2cfe to 44f7a5f Compare April 13, 2026 10:17
@xrmx xrmx requested a review from tammy-baylis-swi April 13, 2026 15:06
@xrmx xrmx enabled auto-merge (squash) April 13, 2026 15:39
@xrmx xrmx merged commit 7477b10 into open-telemetry:main Apr 13, 2026
465 of 466 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Apr 13, 2026
chimchim89 pushed a commit to chimchim89/opentelemetry-python that referenced this pull request Apr 15, 2026
…-telemetry#4990)

* config: add resource and propagator creation from declarative config

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

* update changelog with PR number

Assisted-by: Claude Sonnet 4.6

* fix pylint, pyright and ruff errors in resource/propagator config

- _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

* address review feedback: use _DEFAULT_RESOURCE, fix bool_array coercion

- 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

* fix linter

* address review feedback: single coercion table, simplify attributes merge

- 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

* use Callable type annotation on _array helper

Assisted-by: Claude Sonnet 4.6

* add detection infrastructure foundations for resource detectors

Adds _run_detectors() stub and _filter_attributes() to create_resource(),
providing the shared scaffolding for detector PRs to build on. Detectors
are opt-in: nothing runs unless explicitly listed under
detection_development.detectors in the config. The include/exclude
attribute filter mirrors other SDK behaviour.

Assisted-by: Claude Sonnet 4.6

* move service.name default into base resource

Merges service.name=unknown_service into base before running detectors,
so detectors (e.g. service) can override it. Previously it was added to
config_attrs and merged last, which would have silently overridden any
detector-provided service.name.

Assisted-by: Claude Sonnet 4.6

* remove unused logging import from _propagator.py

Assisted-by: Claude Sonnet 4.6

* add create_logger_provider/configure_logger_provider for declarative 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

* add changelog entry for logger provider declarative config (open-telemetry#4990)

Assisted-by: Claude Sonnet 4.6

* fix linter errors

* add test verifying OTEL_PROPAGATORS env var is ignored by configure_propagator

Assisted-by: Claude Sonnet 4.6

* remove backwards compat re-export of ConfigurationError from _loader.py

Import directly from _exceptions.py since this is new code with no existing
dependents on the _loader module path.

Assisted-by: Claude Sonnet 4.6

* address review feedback: simplify resource filter and propagator loading

Assisted-by: Claude Sonnet 4.6

* fix ruff formatting

Assisted-by: Claude Sonnet 4.6

* fix pyright: wrap EntryPoints in iter() for next() compatibility

Assisted-by: Claude Sonnet 4.6

* remove stale SDK bug note fixed in v1.41.0

Assisted-by: Claude Sonnet 4.6

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Issues and PRs related to implementing Declarative Config

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants