SIGN IN SIGN UP

feat(config): sampler plugin loading via entry points for declarative config (#5095)

* add shared load_entry_point util for declarative config plugin loading

Extracts a generic `load_entry_point(group, name)` helper into `_common`
so that resource detector, exporter, propagator, and sampler plugin loading
in declarative file config can all use the same entry point lookup pattern
rather than duplicating it.

Refactors `_propagator.py` to use the new util, removing its inline
entry point lookup.

Assisted-by: Claude Sonnet 4.6

* update CHANGELOG with PR number #5093

Assisted-by: Claude Sonnet 4.6

* add sampler plugin loading to declarative config via entry points

Extends _create_sampler() to accept raw dicts (from the YAML path) in
addition to typed dataclasses (from the direct API path). Unknown sampler
names fall back to load_entry_point("opentelemetry_sampler", name),
matching the spec's PluginComponentProvider mechanism and Java SDK
behaviour.

_create_parent_based_sampler() gets the same dict-path treatment so
custom samplers can be used as delegate samplers inside parent_based.

Assisted-by: Claude Sonnet 4.6

* add sampler plugin loading to declarative config via entry points

Sampler and ParentBasedSampler are changed from @dataclass to
TypeAlias = dict[str, Any] in models.py. The generated dataclass
representation dropped unknown keys, making plugin sampler names
unrecoverable before reaching the factory. The dict type preserves
the raw YAML key, which is the plugin name.

_create_sampler() now has a single code path: extract the single key
as the sampler name, look it up in _SAMPLER_REGISTRY (always_on,
always_off, trace_id_ratio_based, parent_based), and fall back to
load_entry_point("opentelemetry_sampler", name) for unknown names.
This matches the spec's PluginComponentProvider mechanism.

Assisted-by: Claude Sonnet 4.6

* revert models.py changes, use raw dicts without modifying codegen

Python dataclasses don't enforce types at runtime, so factory functions
can accept raw dicts without changing the generated models. This keeps
models.py identical to the codegen output.

Assisted-by: Claude Opus 4.6 (1M context)

* update sampler plugin loading to use additional_properties

Use typed SamplerConfig and ParentBasedSamplerConfig with
additional_properties from the @_additional_properties decorator
instead of raw dict iteration. Known sampler types are checked via
typed fields. Unknown plugin names from additional_properties are
loaded via the opentelemetry_sampler entry point group.

Assisted-by: Claude Opus 4.6

---------

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
M
Mike Goldsmith committed
e9ca270fad5c88a38c8c079b5a37c550fb070086
Parent: 2397a22
Committed by GitHub <noreply@github.com> on 5/8/2026, 9:15:31 PM