Repository navigation
[SDK] Add fuzz tests for wildcard and resource attribute parsing, and fix the issues found - #8074
Merged
Merged
Conversation
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>
Pull request dashboard statusMerged · refreshed 2026-11-02 08:51 UTC Status above doesn't look right?
|
Assisted-by: Claude Code <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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>
Contributor
There was a problem hiding this comment.
🟡 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>
Kielek
approved these changes
Nov 2, 2026
This was referenced Nov 11, 2026
This was referenced Nov 16, 2026
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Changes
Adds property-based (FsCheck) fuzz tests to
OpenTelemetry.FuzzTestsfor two areas of the SDK that parse user-supplied strings, and fixes the issues that they found.Fuzz tests
WildcardHelper(AddSource()andAddMeter()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)
$, 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 examplea*bmatchedaxb\n). It is now anchored with\z. One existing test case relied on the old behaviour (a*b*matchinga.b\n), so it has been changed.OTEL_RESOURCE_ATTRIBUTESvalues were decoded withWebUtility.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 withUri.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
CHANGELOG.mdfile(s) updated for non-trivial changesChanges in public API reviewed (if applicable)Note
This PR description was generated with Claude Code.
Footnotes
Yes, I can answer maintainer questions about the content of this PR without using AI. ↩