Skip to content

feat(config): generic resource detector plugin loading for declarative config#5129

Draft
MikeGoldsmith wants to merge 3 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-resource-detector-plugin-loading
Draft

feat(config): generic resource detector plugin loading for declarative config#5129
MikeGoldsmith wants to merge 3 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-resource-detector-plugin-loading

Conversation

@MikeGoldsmith
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith commented Apr 20, 2026

Description

Extends resource detector support in declarative file configuration to handle custom (plugin) detectors, matching the spec's PluginComponentProvider mechanism.

Solution

_run_detectors() now iterates detector config dicts directly via _RESOURCE_DETECTOR_REGISTRY:

  • Known names (service, host, process) are bootstrapped directly from the SDK
  • Unknown names — including container and custom plugin detectors — are loaded via load_entry_point("opentelemetry_resource_detector", name)

The generated models are unchanged. Python dataclasses don't enforce field types at runtime, so the detectors list naturally accepts raw dicts (from the YAML loader) alongside typed ExperimentalResourceDetector instances. This preserves unknown plugin names as dict keys without diverging from codegen.

Behavior change

The container detector previously logged a warning when the contrib package was not installed. It now raises ConfigurationError, consistent with the fail-fast approach for declarative config (as discussed in the issue).

Custom detector example

resource:
  detection_development:
    detectors:
      - my_custom_detector: {}
[project.entry-points."opentelemetry_resource_detector"]
my_custom_detector = "my_package:MyResourceDetector"

Closes #5053

ExperimentalResourceDetector is changed from @DataClass to
TypeAlias = dict[str, Any] in models.py, preserving unknown detector
names as dict keys through the config pipeline.

_run_detectors() now iterates the dict's key-value pairs directly via
_RESOURCE_DETECTOR_REGISTRY. Known names (service, host, process) are
bootstrapped directly from the SDK. Unknown names — including container
and custom plugin detectors — are loaded via the
opentelemetry_resource_detector entry point group, matching the spec's
PluginComponentProvider mechanism.

The container detector behavior changes from warning-when-missing to
raising ConfigurationError, consistent with the fail-fast approach
agreed on in the issue discussion.

Assisted-by: Claude Opus 4.6
@MikeGoldsmith MikeGoldsmith requested a review from a team as a code owner April 20, 2026 11:52
_run_detectors() now iterates detector config dicts directly via
_RESOURCE_DETECTOR_REGISTRY. Known names (service, host, process) are
bootstrapped directly from the SDK. Unknown names — including container
and custom plugin detectors — are loaded via the
opentelemetry_resource_detector entry point group, matching the spec's
PluginComponentProvider mechanism.

The generated models are unchanged. Python dataclasses don't enforce
field types at runtime, so the detectors list naturally accepts raw
dicts (from the YAML loader) alongside typed ExperimentalResourceDetector
instances. This preserves unknown plugin names as dict keys without
diverging from codegen.

The container detector behavior changes from warning-when-missing to
raising ConfigurationError, consistent with the fail-fast approach
agreed on in the issue discussion.

Assisted-by: Claude Opus 4.6
@MikeGoldsmith MikeGoldsmith marked this pull request as draft April 20, 2026 13:52
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.

feat(config): generic resource detector loading in declarative config

1 participant