feat(config): sampler plugin loading via entry points for declarative config#5095
Draft
MikeGoldsmith wants to merge 6 commits intoopen-telemetry:mainfrom
Draft
feat(config): sampler plugin loading via entry points for declarative config#5095MikeGoldsmith wants to merge 6 commits intoopen-telemetry:mainfrom
MikeGoldsmith wants to merge 6 commits intoopen-telemetry:mainfrom
Conversation
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
Assisted-by: Claude Sonnet 4.6
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
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
This was referenced Apr 20, 2026
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Extends sampler support in declarative file configuration to handle custom (plugin) samplers, matching the spec's PluginComponentProvider mechanism.
Solution
_create_sampler()now has a single code path: extract the one key as the sampler name, look it up in_SAMPLER_REGISTRY(known names:always_on,always_off,trace_id_ratio_based,parent_based), then fall back toload_entry_point("opentelemetry_sampler", name)for unknown names.The generated models are unchanged. Python dataclasses don't enforce field types at runtime, so parent fields like
TracerProvider.samplernaturally accept raw dicts (from the YAML loader) alongside typedSamplerinstances. This preserves unknown plugin names as dict keys without diverging from codegen.Custom sampler example
Closes #5071