Skip to content

[OpenTelemetry] Fix NotSupportedException - #7788

Merged
martincostello merged 3 commits into
open-telemetry:mainfrom
martincostello:gh-7787
Sep 21, 2026
Merged

martincostello merged 3 commits into
open-telemetry:mainfrom
martincostello:gh-7787

Conversation

@martincostello

@martincostello martincostello commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Fixes #7787

Changes

The internal limit on automata in .NET 8 is 1,000 but for .NET 9+ it's 10,000, which could cause NotSupportedException on .NET 8 when building the wildcard Regex for a large number of activity sources.

In usage with a lot of TracerProvider instances being created, non-backtracking could also cause OutOfMemoryException to be thrown, as it consumes ~35x more memory per Regex.

The fix is to stop using RegexOptions.NonBacktracking and use RegexOptions.Compiled for all TFMs. The match timeout should guard against the scenarios that prompted the original change.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Handle `NotSupportedException` when building the wildcard Regex for a large number of activity sources.

Fixes open-telemetry#7787.
@martincostello
martincostello requested a balanced review from Copilot September 19, 2026 08:05
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Sep 19, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-21 06:30 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fix handles the reported exception with bounded fallback behavior and regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes wildcard regex construction failures on .NET 8.

Changes:

  • Falls back to a timeout-bounded backtracking regex.
  • Adds regression coverage and changelog documentation.
File Description
src/​OpenTelemetry/​Internal/​WildcardHelper.cs Adds safe regex fallback.
test/​OpenTelemetry.Tests/​Internal/​WildcardHelperTests.cs Tests large pattern collections.
src/​OpenTelemetry/​CHANGELOG.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (7d1bd16) to head (1cb15a9).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7788      +/-   ##
==========================================
- Coverage   91.90%   91.87%   -0.04%     
==========================================
  Files         339      339              
  Lines       18543    18545       +2     
==========================================
- Hits        17042    17038       -4     
- Misses       1501     1507       +6     
Flag Coverage Δ
unittests-Project-Experimental 91.94% <100.00%> (-0.07%) ⬇️
unittests-Project-Stable 91.91% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry/Internal/WildcardHelper.cs 100.00% <ø> (ø)
.../Metrics/Builder/MeterProviderBuilderExtensions.cs 98.60% <100.00%> (+0.02%) ⬆️

... and 3 files with indirect coverage changes

@martincostello
martincostello marked this pull request as ready for review September 19, 2026 08:25
@martincostello
martincostello requested a review from a team as a code owner September 19, 2026 08:25
`RegexOptions.NonBacktracking` causes significantly more memory for the same patterns, so rely solely on the match timeout to avoid `OutOfMemoryException` in consumers in large patterns.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation directly addresses the reported failures with appropriate timeout protection, regression tests, and changelog coverage.

Review effort: Balanced
Findings: None

Extend the same fix to views for the only other usage of `RegexOptions.NonBacktracking` too.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation addresses the reported failure with appropriate timeout protection, regression coverage, and changelog documentation.

Review effort: Balanced
Findings: None

@martincostello
martincostello added this pull request to the merge queue Sep 21, 2026
@martincostello martincostello removed the review-priority Should be prioritized for review label Sep 21, 2026
Merged via the queue into open-telemetry:main with commit a90ce5c Sep 21, 2026
80 checks passed
This was referenced Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] NotSupportedException thrown by WildcardHelper.GetWildcardRegex() for large number of sources

3 participants