Skip to content

[SDK] Add fuzz tests for wildcard and resource attribute parsing, and fix the issues found - #8074

Merged
martincostello merged 7 commits into
open-telemetry:mainfrom
martincostello:fuzz-sdk
Nov 2, 2026
Merged

martincostello merged 7 commits into
open-telemetry:mainfrom
martincostello:fuzz-sdk

Conversation

@martincostello

@martincostello martincostello commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Changes

Adds property-based (FsCheck) fuzz tests to OpenTelemetry.FuzzTests for two areas of the SDK that parse user-supplied strings, and fixes the issues that they found.

Fuzz tests

  • WildcardHelper (AddSource() and AddMeter() patterns, and legacy activity names): the regular expression it produces is compared with a reference glob matcher for random patterns and names (including regex metacharacters and multiple patterns), a name with additional characters is checked not to be matched, and matching of adversarial patterns is checked to stay within a time bound. Arbitrary characters, including line feeds, are used by the properties which check that nothing is thrown, that a trailing line feed is not matched, and the time bound. The comparison with the reference matcher only uses names without line terminators, as whether * and ? should match line feeds is not part of this change (see below).
  • OtelEnvResourceDetector (OTEL_RESOURCE_ATTRIBUTES): percent-encoded values round-trip, characters other than the separators which are not encoded are not changed, and arbitrary input never throws.

Issues found and fixed (with dedicated non-fuzz tests)

  • The regular expression created for wildcard patterns anchored its end with $, which also matches before a trailing line feed, so a name with a trailing line feed was matched by a pattern that did not end in a wildcard (for example a*b matched axb\n). It is now anchored with \z. One existing test case relied on the old behaviour (a*b* matching a.b\n), so it has been changed.
  • OTEL_RESOURCE_ATTRIBUTES values were decoded with WebUtility.UrlDecode(), which decodes form data and so changed an unencoded + to a space. The Resource SDK specification only defines percent-encoding for the value (, and = must be percent-encoded, and other characters may be), so it is now decoded with Uri.UnescapeDataString().

The first commit only adds the fuzz tests, so some of them fail at that commit until the fix commits that follow it. The history includes commits which first changed * and ? to match line feeds, and the last commit narrows the scope of the PR to what is described here.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, successful build/tests, etc.)
  • Tests added/updated
  • CHANGELOG.md file(s) updated for non-trivial changes
  • Changes in public API reviewed (if applicable)
  • AI usage disclosure:
    • No AI used
    • AI-assisted
    • Bulk AI-generated
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR1

Note

This PR description was generated with Claude Code.

Footnotes

  1. Yes, I can answer maintainer questions about the content of this PR without using AI. ↩

Add property-based tests for:

- `WildcardHelper`, which are compared with a reference glob matcher and
  also check that matching is bounded in time.
- `OtelEnvResourceDetector`, which round-trips percent-encoded
  `OTEL_RESOURCE_ATTRIBUTES` values.

Some of these tests fail until the issues they find are fixed.

Assisted-by: Claude Code <noreply@anthropic.com>
The regular expression created for source, meter and view name patterns
did not use `RegexOptions.Singleline`, so `*` and `?` did not match line
feeds, and used `$` to anchor the end, which also matched before a
trailing line feed. For example, `foo` matched `foo\n`, and `a*b` did not
match `a\nb`.

This also made the result differ from that of a pattern which is just a
prefix, which is matched by `StartsWith()` instead.

Use `RegexOptions.Singleline` and anchor the end of the pattern with
`\z`. Update the two existing test cases that asserted the previous
behaviour.

Assisted-by: Claude Code <noreply@anthropic.com>
`OTEL_RESOURCE_ATTRIBUTES` values were decoded with
`WebUtility.UrlDecode()`, which decodes form data and so changed an
unencoded `+` (a valid character in the W3C Baggage format that the
value uses) to a space.

Use `Uri.UnescapeDataString()` so that values are only percent-decoded.

Assisted-by: Claude Code <noreply@anthropic.com>
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Oct 30, 2026
@opentelemetry-pr-dashboard

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

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-11-02 08:51 UTC

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

Assisted-by: Claude Code <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.77%. Comparing base (99d3c02) to head (ac3f4c0).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #8074    +/-   ##
========================================
  Coverage   90.76%   90.77%            
========================================
  Files         382      382            
  Lines       22580    22680   +100     
  Branches     4178     4207    +29     
========================================
+ Hits        20494    20587    +93     
- Misses       1503     1507     +4     
- Partials      583      586     +3     
Flag Coverage Δ
unittests-Project-Experimental 90.71% <100.00%> (-0.08%) ⬇️
unittests-Project-Stable 90.75% <100.00%> (-0.05%) ⬇️

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 94.87% <100.00%> (ø)
...OpenTelemetry/Resources/OtelEnvResourceDetector.cs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

Assisted-by: Claude Code <noreply@anthropic.com>
Wildcards:

- Do not use `RegexOptions.Singleline` for source and meter name patterns,
  or for view name patterns (which are restored to what they were), so
  whether `*` and `?` match line feeds is not changed. Only the anchor at
  the end of the pattern (`\z` instead of `$`) is, so that a name with a
  trailing line feed is not matched by a pattern that does not end in a
  wildcard.
- Remove the tests that required wildcards to match line feeds. The
  properties that compare with a reference matcher only use names without
  line terminators, and arbitrary characters (including line feeds) are
  still used by the properties that check that nothing is thrown, that a
  name with additional characters is not matched, and that matching is
  bounded in time.
- A trailing line feed was only matched by a pattern that does not end in
  a wildcard because of the anchor, so the existing test case that asserted
  that is changed.

Resource attributes:

- Describe `OTEL_RESOURCE_ATTRIBUTES` as the Resource SDK specification
  does, which only defines percent-encoding (the `,` and `=` characters
  must be encoded and others may be), and not as W3C Baggage. The test of
  unencoded characters now allows any character that is not a separator.

Update the CHANGELOG entries to match.

Assisted-by: Claude Code <noreply@anthropic.com>
@martincostello
martincostello marked this pull request as ready for review October 31, 2026 11:06
Copilot AI balanced review requested due to automatic review settings October 31, 2026 11:06
@martincostello
martincostello requested a review from a team as a code owner October 31, 2026 11:06

This comment was marked as resolved.

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.

🟡 Changes recommended

The stopwatch includes the line-feed scan and reference glob comparison in the 500 ms regex-matching limit, causing potential false failures unless it is stopped immediately after regex.IsMatch().

1 open issue

Review effort: Balanced

try
{
// Deliberately not WildcardHelper.IsMatch(), which swallows timeouts and would hide them.
var actual = regex.IsMatch(scenario.Input);
Stop the stopwatch immediately after `regex.IsMatch()` so that the line
feed scan and the reference glob matcher do not count towards the
bounded-time limit.

Assisted-by: Claude Code <noreply@anthropic.com>
This was referenced Nov 16, 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.

3 participants