Skip to content

Match trace sampling globs with GlobMatcher - #13602

Draft
dougqh wants to merge 4 commits into
dougqh/toolbox-glob-matcherfrom
dougqh/sampling-glob-matcher
Draft

dougqh wants to merge 4 commits into
dougqh/toolbox-glob-matcherfrom
dougqh/sampling-glob-matcher

Conversation

@dougqh

@dougqh dougqh commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Trace and span sampling rules now match service, operation, resource and tag globs with GlobMatcher, the toolbox's engine-free matcher from #13597, instead of a regex. Matchers.compileGlob still handles * and exact names on their own; only the wildcard globs change. GlobPattern, which built the regexes, has no other users and is removed.

Adds SamplingRuleMatchBenchmark (dd-trace-core JMH) in its own commit, ahead of the change, so the same benchmark measures before and after.

Motivation

Every wildcard glob was a case-insensitive java.util.regex.Pattern, so every match against a span created a Matcher. RuleBasedTraceSampler walks the rules until one matches, which means the rules ahead of a match, or every rule when none matches, all pay that cost on every trace's sampling decision. GlobMatcher gives the same results without allocating.

Additional Notes

  • One behavior change, +: GlobPattern.globToRegex didn't escape +, so it reached the regex as a quantifier. The glob a+b* matched aabc, and c++* couldn't match the text c++17. + is now the literal it is in glob syntax. MatchersTest pins the new behavior.

  • Same results otherwise: GlobMatcher matches the regex the glob translates to, including its handling of line terminators, surrogate pairs and ASCII-only case folding (see Add an engine-free GlobMatcher to the toolbox #13597's differential tests).

  • Benchmark: five TraceSamplingRules mixing any, exact and wildcard globs, so the Matcher call sites see the same mix of receiver types as in production. Cases: the first rule matches, only the last, none, and none with a 500-character resource.

  • Timing: SamplingRuleMatchBenchmark on JDK 21, 3 forks per commit alternated, 4 threads, 3×5 s warmup, 5×5 s measurement, -prof gc, steal 0.2%. Median fork in ns/op per thread (min–max). Before is the benchmark commit; after is the switch to GlobMatcher. Later commits on this branch don't change matching.

    matching before after change B/op before → after
    first 448 (446–474) 139 (138–141) −69% 416 → 0
    last 752 (715–759) 158 (153–161) −79% 832 → 0
    none 955 (879–966) 212 (212–216) −78% 1,040 → 0
    none-long 6,602 (6,585–7,340) 3,015 (2,928–3,104) −54% 1,040 → 0
    • No fork ranges overlap. Matching the rules now allocates nothing; before, each wildcard glob created a Matcher per span.
    • none-long still costs about 3 µs: one rule's * /health* searches the 500-character resource, at about 5 ns per character. That's more than GlobMatcherBenchmark's 1.4 ns per character on a String. The span's resource is a CharSequence, so each character read is an interface call, which may explain the difference. I haven't profiled it.
  • Stacked on Add an engine-free GlobMatcher to the toolbox #13597.

Contributor Checklist

🤖 Generated with Claude Code

dougqh and others added 4 commits November 20, 2026 17:46
Matches a span against five TraceSamplingRules that mix the matcher
kinds Matchers.compileGlob produces (any, exact and wildcard globs):
the first rule matching, only the last, none, and none with a
500-character resource.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matchers.compileGlob turned every glob other than "*" and an exact name
into a case-insensitive java.util.regex Pattern, which created a
Matcher on every match. It now uses the toolbox's GlobMatcher, which
gives the same results without allocating. GlobPattern, which built
those regexes, has no other users and is removed.

One result changes: GlobPattern didn't escape '+', so it reached the
regex as a quantifier. The glob a+b* matched aabc, and c++* couldn't
match the text c++17. '+' is now the literal it is in glob syntax.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matchers.compileGlob no longer matches with a regex, and GlobPattern,
which built it, is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: feature Enhancements and improvements comp: core Tracer core tag: performance Performance related changes tag: ai generated Largely based on code generated by an AI or LLM labels Nov 21, 2026
@pr-commenter

pr-commenter Bot commented Nov 21, 2026

Copy link
Copy Markdown

LLM Validation

LLM Validation Gate — java-agent-instructions

✅ PASS

  • No blocking-case regressions; the quality change is within noise (baseline/candidate confidence intervals overlap).

6 case(s) · quality 81.5 → 81.9 (+0.4) · win-rate 50% [47%–53%]

Details — analysis and per-case results

Analysis

Changed instruction file(s): AGENTS.md.

No safety or blocking-case regressions across 6 case(s). Overall pairwise win-rate 50% [47%–53%], quality +0.4 — see the verdict above for whether that clears the noise band.

Results

  • Pairwise win-rate: 50% [47%–53%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 81.5 → 81.9 (/100, +0.4)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 23/27 (85%) — expected_criteria the candidate met; does not affect the gate
  • Blocking-case regressions: 0

Cases

Case Mode Quality Δ Win-rate (90% CI) Safety
java-core-validation-001 warn +1.1 50% [50%–50%] ok
java-unit-test-conventions-001 warn +0.3 50% [50%–50%] ok
java-premain-safety-001 warn +1.9 58% [45%–72%] ok
java-ci-download-guidance-001 warn -0.8 50% [50%–50%] ok
java-documentation-only-validation-001 warn -1.9 42% [28%–55%] ok
java-existing-spock-maintenance-001 warn +1.7 50% [50%–50%] ok

Per-dimension scores, token usage, latency, and estimated cost are in the CI job logs.

@datadog-official

datadog-official Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 60.83% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e2ee400 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.98 s 14.07 s [-1.4%; +0.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.92 s 13.08 s [-2.0%; -0.4%] (maybe better)
startup:petclinic:appsec:Agent 17.83 s 17.52 s [+1.1%; +2.5%] (significantly worse)
startup:petclinic:iast:Agent 17.68 s 17.74 s [-1.2%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 17.45 s 17.59 s [-2.2%; +0.6%] (no difference)
startup:petclinic:sca:Agent 17.88 s 17.74 s [-0.2%; +1.7%] (no difference)
startup:petclinic:tracing:Agent 16.77 s 16.95 s [-2.2%; +0.0%] (no difference)

Commit: e2ee400e · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant