Skip to content

fix(telemetry): add wildcard-aware instrument name matcher for metric views#9809

Open
apollo-mateuswgoettems wants to merge 5 commits into
devfrom
fix/telemetry-metric-view-wildcard-matching
Open

fix(telemetry): add wildcard-aware instrument name matcher for metric views#9809
apollo-mateuswgoettems wants to merge 5 commits into
devfrom
fix/telemetry-metric-view-wildcard-matching

Conversation

@apollo-mateuswgoettems

Copy link
Copy Markdown
Contributor

Motivation

Since v2.13.0 (the OpenTelemetry SDK 0.24 → 0.31 migration), metric views configured under telemetry.exporters.metrics.common.views only match instruments by exact name. Wildcard patterns (cost.*), single-character wildcards (?), and catch-all names (* or an empty string) — all of which the pre-0.31 SDK matched natively — silently stopped matching.

Concretely, a config like:

telemetry:
  exporters:
    metrics:
      common:
        views:
          - name: cost.*
            aggregation:
              histogram:
                buckets: [0, 10, 100, 1000]
          - name: "*"
            aggregation: drop

no longer applied the custom buckets to cost.* metrics and no longer dropped the unlisted metrics, leaking 80+ router-internal metrics to the exporter. This was reported by a user who relied on this exact pattern before upgrading from v2.11.0.

Root cause

The 0.31 migration replaced the SDK's pattern-aware new_view(Instrument, Stream) (which matched instrument-name selectors with */? wildcards natively) with a closure that does a plain instrument.name() != name comparison, and resolve_view looked user views up in a HashMap<String, MetricView> keyed by exact name. Neither replicated the wildcard matching the SDK used to provide, so every wildcard/catch-all pattern silently fell through.

What changed

  • Shared InstrumentNameMatcher (backed by regex, already a dependency — no new crate) that restores the semantics: escape the name, translate *.* and ?. into an anchored pattern; an empty name or a bare * matches everything; names without a wildcard match exactly. Any other character (including .) stays literal.
  • Single source of truth: both matching sites — MetricView::into_view_fn and resolve_view — now route through the matcher, so the wildcard behavior can't silently diverge between them again (the pre-fix wiring had already oscillated between these two paths across releases).
  • Declaration order honored: configure_views builds an ordered Vec<(matcher, view)> and resolve_view selects by first match instead of a HashMap lookup, so users can place more-specific views before wildcards to control precedence.

No configuration schema change → no migration and no breaking config change. This restores the behavior the documentation already describes.

How to verify

  • Wildcard buckets, catch-all drop, exact-before-wildcard precedence, and a combined test mirroring a real user config are covered by new unit + integration tests.
  • Full telemetry lib suite passes (573/573).
  • Manual end-to-end run against a live router (details under Exceptions): custom buckets applied through a http.server.* wildcard, and internal metrics dropped by the catch-all (62 → 19 exported metric families).

Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • PR description explains the motivation for the change and relevant context for reviewing
  • PR description links appropriate GitHub/Jira tickets (creating when necessary)
  • Changeset is included for user-facing changes
  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit tests
    • Integration tests
    • Manual tests, as necessary

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

… views

The OpenTelemetry 0.31 View API migration replaced the SDK pattern-aware view selection with a closure doing exact string comparison, so wildcard (*, ?) and catch-all view names silently stopped matching. Add a shared InstrumentNameMatcher (regex-backed) and route into_view_fn through it.
…f exact-name map

Build user views into an ordered Vec of (matcher, view) and select by first match instead of an exact-name HashMap lookup, so wildcard and catch-all patterns apply again and declaration order controls precedence.
@apollo-mateuswgoettems
apollo-mateuswgoettems requested a review from a team as a code owner July 14, 2026 19:20
@github-actions

This comment has been minimized.

@apollo-librarian

apollo-librarian Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: e92649675b37cb051e190048
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@apollo-mateuswgoettems
apollo-mateuswgoettems requested review from aaronArinder and removed request for aaronArinder July 14, 2026 19:48
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.

1 participant