Skip to content

Record error.type for failed metric reader collections - #5778

Open
RichardoMrMu wants to merge 2 commits into
open-telemetry:mainfrom
RichardoMrMu:fix/metric-reader-collection-error-type
Open

RichardoMrMu wants to merge 2 commits into
open-telemetry:mainfrom
RichardoMrMu:fix/metric-reader-collection-error-type

Conversation

@RichardoMrMu

@RichardoMrMu RichardoMrMu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

otel.sdk.metric_reader.collection.duration is documented with the note that
error.type MUST NOT be set for successful collections and SHOULD contain the
failure cause for failed ones. MetricReader.collect only recorded the
duration, so a failed collection was indistinguishable from a successful one on
that metric.

This passes the failure cause from collect down to record_collection, which
sets error.type to the exception type name when the collection raised. The
exception is still re-raised, and successful collections still record without
error.type.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added TestPeriodicExportingMetricReader.test_metric_reader_metrics_failed_collection_records_error_type.
It fails on main with AssertionError: 'MetricsTimeoutError' not found in [None]
and passes after the change.

  • pytest opentelemetry-sdk/tests (after the change): 893 passed, 20 skipped
  • ruff check, ruff format --check, pylint on the touched files

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

I used AI assistance (Doubao) to prepare this change. I reviewed the diff, ran
the tests listed above myself, and I am responsible for this submission.

`otel.sdk.metric_reader.collection.duration` is documented to leave
`error.type` unset for successful collections and to set it to the
failure cause for failed ones. `MetricReader.collect` only recorded the
duration, so a failed collection looked the same as a successful one.

Pass the failure cause from `collect` to `record_collection` and set
`error.type` from the exception type name.

Assisted-by: Doubao
@RichardoMrMu
RichardoMrMu requested a review from a team as a code owner October 13, 2026 10:08
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-10-13 10:17 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

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

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant