Skip to content

fix(sdk): check default-view fallback stream for conflicting metric identities - #5632

Open
somuai wants to merge 2 commits into
open-telemetry:mainfrom
somuai:fix-default-view-conflict-warning
Open

fix(sdk): check default-view fallback stream for conflicting metric identities#5632
somuai wants to merge 2 commits into
open-telemetry:mainfrom
somuai:fix-default-view-conflict-warning

Conversation

@somuai

@somuai somuai commented Sep 5, 2026

Copy link
Copy Markdown

Description

Fixes #5629

MetricReaderStorage creates metric streams for instruments either via matching user-configured views in _handle_view_instrument_match or via the _DEFAULT_VIEW fallback in _get_or_init_view_instrument_match when no view matches the instrument.

Previously, only _handle_view_instrument_match executed conflict scanning against existing matches. As a result, when an explicit view renamed an instrument to collide with an instrument taking the fallback path, the duplicate identity warning ("Views ... will cause conflicting metrics identities") was emitted only if the renamed instrument recorded second. If the renamed instrument recorded first, the fallback stream was appended without a conflict check, and two streams with identical identity were exported without warning.

Per the OpenTelemetry specification (https://opentelemetry.io/docs/specs/otel/metrics/sdk/#view):

If applying the View results in conflicting metric identities the implementation SHOULD apply the View and emit a warning.

This change extracts _check_conflicts_and_add_match to ensure both stream-creation paths (matching views and the _DEFAULT_VIEW fallback) perform conflict scanning against existing matches before appending, guaranteeing consistent, order-independent warning behavior.

Type of change

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

How Has This Been Tested?

  • Added test_view_instrument_match_conflict_default_view_order_independence testing both arrival orders (default view first vs renamed view first). Both orders reliably emit the warning.
  • Updated test_default_view_enabled to assert the conflict warning emitted when a second instrument with a mocked match is recorded.
  • Ran full test suite in opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py (18/18 passed).
  • Linted with ruff check (clean).

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

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

@somuai
somuai requested a review from a team as a code owner September 5, 2026 21:16
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 5, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

somuai pushed a commit to somuai/opentelemetry-python that referenced this pull request Sep 5, 2026
Signed-off-by: Soumyajit Ghosh <jobsoumyajit6124@gmail.com>
…ties

Fixes open-telemetry#5629

MetricReaderStorage creates metric streams for instruments either via matching
user-configured views in _handle_view_instrument_match or via the _DEFAULT_VIEW
fallback in _get_or_init_view_instrument_match when no views match.

Previously, only _handle_view_instrument_match executed conflict checking
against existing matches. As a result, when an explicit view renamed an
instrument to a name matching an instrument that uses the default-view fallback,
the conflict warning was only emitted if the renamed instrument arrived second.
If the renamed instrument arrived first, the default-view fallback stream was
appended without checking for conflicts, silently exporting duplicate metric
identities in violation of the OpenTelemetry specification.

Extract _check_conflicts_and_add_match to route both stream-creation paths
through conflict scanning, ensuring conflicting metric identities are reliably
warned regardless of instrument registration order.

Signed-off-by: Soumyajit Ghosh <jobsoumyajit6124@gmail.com>
Signed-off-by: Soumyajit Ghosh <jobsoumyajit6124@gmail.com>
@somuai
somuai force-pushed the fix-default-view-conflict-warning branch from 3e24b18 to 0b609ab Compare September 5, 2026 21:17
@somuai

somuai commented Sep 5, 2026

Copy link
Copy Markdown
Author

/dashboard route:reviewers

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@somuai, this pull request was routed to reviewers.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 5, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-09-05 23:20 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.

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.

Default-view fallback stream is never checked for conflicting metric identities (warning is order-dependent)

1 participant