Skip to content

fix(sdk): make instrumentation scope glob matching case-sensitive - #5584

Open
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:issue_5583_scope_glob_case_sensitivity
Open

fix(sdk): make instrumentation scope glob matching case-sensitive#5584
ocelotl wants to merge 2 commits into
open-telemetry:mainfrom
ocelotl:issue_5583_scope_glob_case_sensitivity

Conversation

@ocelotl

@ocelotl ocelotl commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #5583.

_scope_name_matches_glob in opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py used fnmatch.fnmatch, which normalizes both the scope name and the glob pattern through os.path.normcase. On Windows normcase lower-cases its argument, so instrumentation-scope name matching was case-insensitive there while staying case-sensitive on Linux.

That predicate backs scope name matching for the tracer, meter and logger configurators, so the host platform leaked into observable SDK behavior: the same configuration disabled a different set of scopes depending on the operating system.

The declarative configuration schema requires the opposite. From ExperimentalTracerMatcherAndConfig.name in opentelemetry-configuration/src/opentelemetry/configuration/schema.json (the meter and logger matchers carry the same wording):

Configure tracer names to match. Matching is case-sensitive, evaluated as follows:

  • If the tracer name exactly matches.
  • If the tracer name matches the wildcard pattern, where '?' matches any single character and '*' matches any number of characters including none.

This switches the predicate to fnmatchcase, which is what the rest of the SDK already does. opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py and opentelemetry-sdk/src/opentelemetry/sdk/trace/_sampling_experimental/_rule_based.py both use fnmatchcase, and view.py already documents the reason: "fnmatchcase is used instead of fnmatch so it does not rely on the host platform's filename case sensitivity (normcase)".

Reported by @lzchen while reviewing #5418: #5418 (comment)

Type of change

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

How Has This Been Tested?

Added two tests next to the existing _scope_name_matches_glob tests in opentelemetry-sdk/tests/metrics/test_metrics.py:

  • test_scope_name_matches_glob_is_case_sensitive_on_every_platform: a scope name that differs from the pattern only by case must not match, for both an exact pattern and a wildcard pattern.
  • test_scope_name_matches_glob_pattern_case_is_not_normalized: an upper-case pattern must not match a lower-case scope name.

Both assertions fail on Windows with fnmatch and pass with fnmatchcase. On Linux they pass either way, so I confirmed the regression coverage by running fnmatch and fnmatchcase with os.path.normcase patched to ntpath.normcase:

fnmatch('My.Meter', 'my.meter')     = True
fnmatchcase('My.Meter', 'my.meter') = False
fnmatch('MY.meter', 'my.*')     = True
fnmatchcase('MY.meter', 'my.*') = False
fnmatch('my.meter', 'MY.*')     = True
fnmatchcase('my.meter', 'MY.*') = False

The repository's Windows CI jobs cover the real case.

Local runs:

  • pytest opentelemetry-sdk/tests/metrics opentelemetry-sdk/tests/logs opentelemetry-sdk/tests/trace — 705 passed
  • pytest opentelemetry-configuration/tests — 381 passed
  • ruff check and ruff format --check on both changed files — clean

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

_scope_name_matches_glob used fnmatch.fnmatch, which normalizes both the
scope name and the glob pattern through os.path.normcase. On Windows
normcase lower-cases its argument, so scope name matching was
case-insensitive there while staying case-sensitive on Linux. The same
configuration therefore disabled a different set of instrumentation
scopes depending on the host operating system.

The declarative configuration schema requires case-sensitive matching for
the tracer, meter and logger configurator name matchers. Use fnmatchcase
so the behavior no longer depends on the host platform, matching what
metrics/_internal/view.py and trace/_sampling_experimental/_rule_based.py
already do.

Fixes open-telemetry#5583.
@ocelotl
ocelotl requested a review from a team as a code owner August 24, 2026 14:00
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 24, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-08-25 10:15 UTC

Investigate required status check failures.

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.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

Instrumentation scope glob matching is case-insensitive on Windows

2 participants