Skip to content

fix(configuration): skip a resource detector that fails instead of losing every provider - #159

Draft
ocelotl wants to merge 13 commits into
mainfrom
issue_145_contain_detector_failure
Draft

ocelotl wants to merge 13 commits into
mainfrom
issue_145_contain_detector_failure

Conversation

@ocelotl

@ocelotl ocelotl commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #145

What was broken

_sdk.configure_sdk builds the resource before it installs the tracer, meter and logger providers and before it sets the propagator. _resource._run_detectors called load_entry_point with nothing around it, and load_entry_point raises ConfigurationError when the named entry point is not registered. A configuration file naming a detector whose package is not installed therefore cost the application traces, metrics, logs and propagation, and not only the attributes that detector would have added.

container is a first-class schema field under $defs.ExperimentalResourceDetector, and this distribution does not ship opentelemetry-resource-detector-container. The installed entry points are dash0_distribution, dash0_kubernetes, dash0_service_name, host, os, otel, process and service_instance. For example, a file copied from the schema, or from another language's example, reaches the failure:

resource:
  detection/development:
    detectors:
      - container: {}
ConfigurationError: Plugin 'container' not found in group 'opentelemetry_resource_detector'
tracer provider after failure: ProxyTracerProvider

A detector whose entry point loads and whose detect() then raises escaped the same way, and load_entry_point never sees that one at all.

What changed

scripts/vendor_configuration.py generates packages/dash0-opentelemetry-configuration/ from the dash0-v1.45.2 branch of https://github.com/dash0hq/opentelemetry-python, so the code change was made there and vendored in. The fork pull request is dash0hq/opentelemetry-python#5, and UPSTREAM now names its head commit e68f4b9.

_run_detectors runs every detector in a detector entry under a handler. ConfigurationError logs a warning naming the detector, _run_detectors logs any other exception through _logger.exception, and the detectors listed after the failing one still run. instrumentation.configure_instrumentation already handles an absent instrumentor that way, so the two paths now agree.

The configuration package moves to 0.66b2.post2 and the distribution to 0.4.2, because the wheels for 0.66b2.post1 and 0.4.1 are already in scripts/index-manifest.json.

Verification

packages/dash0-opentelemetry-configuration/tests/test_resource_detector_failures.py holds eight tests, and all eight fail against the previously vendored tree.

Four call create_resource with container listed, two per failure route. On the route where load_entry_point cannot find the entry point, one asserts a single WARNING record whose rendered message starts with the detector name and still carries the sentence telling an operator to install the package, and the other lists host after container and asserts host.name is still detected. On the route where detect() raises, one asserts a single ERROR record carrying a traceback, and the other again asserts host.name.

Two cover the branches container never reaches. _run_detectors resolves host, process and service through _RESOURCE_DETECTOR_REGISTRY and everything else through the entry point group, and it reads the four schema fields and additional_properties into one list. container is a schema field resolved by entry point, so one test lists aws_ecs, which the schema does not declare and which therefore arrives through additional_properties, and the other makes the registry entry for process raise.

Two run configure_sdk in a subprocess, because a process accepts global providers only once, and assert the global tracer provider is a TracerProvider rather than the ProxyTracerProvider left behind when resource creation failed.

Five mutations of _run_detectors survived an earlier shape of these tests and are now killed: hoisting the generic handler outside the loop, dropping the exception from the warning message, dropping the detector name from it, restoring the separate unguarded loop over additional_properties, and running the registry detectors ahead of the try.

Every check below ran on issue_145_contain_detector_failure.

check result
uvx ruff@latest check packages/dash0-opentelemetry examples scripts passed
uvx ruff@latest format --check packages/dash0-opentelemetry examples scripts 40 files already formatted
uv lock --check passed
uv run --no-project --python 3.13 scripts/check_pinned_dependencies.py passed
uv run --no-project --python 3.13 scripts/check_version_bumped.py passed
uv run --no-project --python 3.13 python scripts/vendor_configuration.py --check matches the fork at e68f4b9
uv run --no-project --with packaging --python 3.13 python scripts/refresh_injector_manifest.py --check passed
pytest packages/dash0-opentelemetry-configuration/tests packages/dash0-opentelemetry/tests 252 passed, 27 subtests
pytest scripts/tests 60 passed
make chlog-validate passed

The fork's own suite passes too, 453 tests and 46 subtests under pytest opentelemetry-configuration/tests, with pylint rating _resource.py 10.00/10.

Why this is a draft, and what has to happen before it merges

UPSTREAM names e68f4b9, the head commit of the open fork pull request. git branch -a --contains e68f4b9 on the fork lists only contain-resource-detector-failures, so UPSTREAM currently records a commit that the branch it also records, dash0-v1.45.2, does not contain. scripts/vendor_configuration.py fetches by bare SHA and never reads the branch field, so --check passes anyway and nothing in CI reports the mismatch. A maintainer who later runs the script with no --commit would regenerate from the fork pull request's head ref instead of from dash0-v1.45.2.

So, in order:

  1. Review and merge Skip a failing resource detector instead of losing every provider opentelemetry-python#5 into dash0-v1.45.2.
  2. Run uv run --no-project --python 3.13 python scripts/vendor_configuration.py --commit <sha on dash0-v1.45.2> here and commit the result.
  3. Confirm with git branch -a --contains <that sha> on the fork that origin/dash0-v1.45.2 is listed.
  4. Take this pull request out of draft.

#126 pinned 90f23ad the same way, and the fork pull request carrying 90f23ad had already merged when it did.

…sing every provider

Re-vendor the configuration package from dash0hq/opentelemetry-python
dash0-v1.45.2 at e68f4b9, which runs each resource detector under a
handler.

_sdk.configure_sdk builds the resource before the tracer, meter and logger
providers and before the propagator, and _resource._run_detectors let a
ConfigurationError out of load_entry_point. A configuration file naming a
detector whose package is not installed, such as container on a host
without opentelemetry-resource-detector-container, therefore cost the
application traces, metrics, logs and propagation.

A detector that cannot be loaded now logs a warning naming it, one that
raises inside detect() logs an exception, and the detectors after it still
run. instrumentation.configure_instrumentation already did this for an
absent instrumentor.
…e distro to 0.4.2

The wheels for 0.66b2.post1 and 0.4.1 are already in
scripts/index-manifest.json, so the release workflow would skip rebuilding
them and consumers would keep resolving the published bytes. The distro's
exact pin on the configuration package moves with it.
Four tests, all of which fail against the previously vendored tree. Two
call create_resource with container listed and no container package
installed, once letting load_entry_point fail and once letting detect()
raise, and assert the resource still carries the SDK defaults. Two run
configure_sdk in a subprocess, because a process accepts global providers
only once, and assert the global tracer provider is a TracerProvider
rather than the ProxyTracerProvider left behind when resource creation
failed.
…installed

The page tells a reader to name detectors in a configuration file without
saying what an absent one does. It now says the detector is skipped with a
warning, and names container as the schema field whose package this
distribution does not ship.
… the file

The changelog entry and docs/resource-detection.md both promise that the
detectors after a failing one still run, and nothing in this repository
held the vendored tree to it. A re-vendor from a fork commit that moved
the handler to wrap the whole loop would pass every check here. The new
test lists container ahead of host and asserts host.name is detected.

The annotations bring the file in line with test_propagator.py and
test_vendoring.py, the two files beside it.
Without a timeout, a child process that never exits leaves subprocess.run
waiting, and the test job in .github/workflows/ci.yml declares no
timeout-minutes, so all six matrix entries would run to the six-hour
GitHub default and report a cancellation rather than a failure.
caplog.at_level sets a minimum, so the ERROR a collapsed handler emits
also landed in caplog.text and the warning test stayed green. Collapsing
the two except clauses into one _logger.exception would print a stack
trace on every start for the container case this change exists for.
Asserting the level and whether the record carries exc_info fails that
edit: experimentally, with the clauses collapsed, the warning test reports
assert ['ERROR'] == ['WARNING'].
…lked through

Hoisting the generic handler outside the loop, dropping the exception from
the warning message, and dropping the detector name from it all left the
suite green. A sixth test lists host after a container detector whose
detect() raises, and the warning test now asserts the rendered message
starts with the detector name and still carries the sentence telling an
operator to install the package.

The subprocess helper asserts on returncode with stderr as the message
instead of passing check=True. CalledProcessError reports the exit status
and echoes the program source, so a CI log for a future regression carried
nothing about why the child failed.
Neither test read caplog.records, so the fixture and the at_level block
changed no outcome while telling a reader the test checks the log. The
ERROR one also raised the logger above WARNING for the duration of the
call, which would have hidden a downgrade of the generic handler. The two
tests above them already pin the level and the message for both routes.
The four in-process tests all list `container`, a declared field of
`ExperimentalResourceDetector`, so nothing pinned the other route into
`_run_detectors`: a name the schema omits, which arrives through
`additional_properties`. Restoring the separate unguarded loop for that
route left the whole suite passing, and the three detectors the documented
example lists travel it.
Every test that makes a detector fail makes `container` fail, which takes
the entry-point branch. The `_RESOURCE_DETECTOR_REGISTRY` branch was only
ever reached by `host`, which always succeeds, so guarding the entry-point
branch alone left the suite green. `ProcessResourceDetector.detect` calls
`psutil.Process().username()` unguarded, so `AccessDenied` from a
sandboxed runtime reaches that branch.
`ruff.toml` sets `line-length = 88` and excludes only the configuration
package's `src`, so the tests are in scope. Both docstrings were 90 columns.
CI never passes this directory to ruff, so nothing reported it.

This branch has not been deployed

No deployments
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.

A resource detector named in a configuration file but not installed destroys all telemetry

1 participant