Skip to content

Keep the Jetty 9 request URL when its query can't be read (quick fix) - #13359

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
dougqh/jetty9-unreadable-query
Nov 18, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
dougqh/jetty9-unreadable-query

Conversation

@dougqh

@dougqh dougqh commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Keeps http.url on Jetty 9 server spans when Jetty itself can't produce the request's query string.

  • Fix: jetty9.RequestURIDataAdapter.innerRawQuery catches the StringIndexOutOfBoundsException that Request.getQueryString() can throw, and treats the query as absent. The scheme, host, port and path are still read and tagged.
  • Test: a new JUnit 5 RequestURIDataAdapterTest uses a mocked Jetty Request. It checks that a readable query passes through, and that an unreadable one yields a null raw and decoded query while the rest of the URL is still read. The module didn't have Mockito, so the PR adds libs.bundles.mockito as a test dependency.

Motivation

Instrumentation telemetry (Error Tracking issue 5edd9a7e-c73b-11f1-b9e2-da7ad0900002, first seen in 1.64.0, JDK 8):

java.lang.StringIndexOutOfBoundsException
  at (redacted: 2 frames)
  at datadog.trace.instrumentation.jetty9.RequestURIDataAdapter.innerRawQuery(RequestURIDataAdapter.java:41)
  at datadog.trace.bootstrap.instrumentation.api.URIRawDataAdapter.rawQuery(URIRawDataAdapter.java:51)
  at datadog.trace.bootstrap.instrumentation.api.http.HttpServerUrl$Request.query(HttpServerUrl.java:148)
  at datadog.trace.bootstrap.instrumentation.api.http.DatadogServerUrl.extract(DatadogServerUrl.java:32)
"Error tagging url"

Line 41 is return request.getQueryString();, so the exception comes from Jetty. In Jetty 9.0 (checked in the 9.0.0.v20130308 jar), HttpURI.getQuery() is new String(_raw, _query + 1, _fragment - _query - 1, charset). When the parser leaves those offsets inconsistent for a malformed request URI, the constructor throws. The tracer can't fix Jetty, but the failure shouldn't cost the whole URL tag.

Without the fix, the new test fails with StringIndexOutOfBoundsException: String index out of range: -1. With it, the new tests pass, as do the module's test (Jetty9InactiveAppSecTest) and forkedTest suites (Jetty9V0/V1ForkedTest and JettyContinuationHandlerV0/V1ForkedTest, 302 tests).

Additional Notes

  • The exception still occurs inside Jetty. This change only stops it from aborting URL tagging. I didn't find the exact malformed URI that produces the bad offsets, so the test simulates getQueryString() throwing rather than parsing a real bad request.
  • Only StringIndexOutOfBoundsException is caught, the one observed. Other failures still propagate as before.
  • Low volume: a single event in the sample.

🤖 Generated with Claude Code

Jetty 9's HttpURI.getQuery() builds the query as
new String(_raw, _query + 1, _fragment - _query - 1, charset). For some
malformed request URIs the parsed offsets are inconsistent and it throws
StringIndexOutOfBoundsException. The exception escaped
RequestURIDataAdapter.innerRawQuery, so URL tagging failed ("Error
tagging url") and the span lost http.url altogether.

Treat an unreadable query as absent, so the scheme, host, port and path
are still tagged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: bug fix Bug fix inst: jetty Jetty instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: telemetry error reported Reported by error telemetry labels Nov 10, 2026
@dougqh
dougqh marked this pull request as ready for review November 10, 2026 21:34
@dougqh
dougqh requested review from a team as code owners November 10, 2026 21:35
@dougqh
dougqh requested review from bric3 and ygree and removed request for a team November 10, 2026 21:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T21:38:07.958644Z df550b6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df550b6fb7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot 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.

Bits Code Review: WARN

The gradle.lockfile for jetty-server-9.0 must be regenerated after adding the Mockito bundle, as it currently omits mockito-junit-jupiter and incompletely records mockito-core, violating the repository's dependency-change requirements in CONTRIBUTING.md.

Open Bits AI session

🤖 Bits Code Review · Commit df550b6

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 68.82% (+8.19%)

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

@dougqh dougqh changed the title Keep the Jetty 9 request URL when its query can't be read Keep the Jetty 9 request URL when its query can't be read (quick fix) Nov 10, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 10, 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 14.06 s 14.05 s [-0.8%; +1.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 12.98 s [-1.3%; +0.0%] (no difference)
startup:petclinic:appsec:Agent 17.16 s 17.00 s [-0.1%; +2.0%] (no difference)
startup:petclinic:iast:Agent 16.66 s 16.59 s [-5.9%; +6.8%] (unstable)
startup:petclinic:profiling:Agent 16.60 s 16.76 s [-1.9%; -0.0%] (maybe better)
startup:petclinic:sca:Agent 17.10 s 16.93 s [+0.1%; +1.9%] (maybe worse)
startup:petclinic:tracing:Agent 16.09 s 16.27 s [-1.8%; -0.3%] (maybe better)

Commit: ccdc1a69 · 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.

Adding libs.bundles.mockito puts mockito-core on the test compile classpath and
adds mockito-junit-jupiter; record both in the module's lockfile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot 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.

Bits Code Review: PASS

More details

The PR preserves Jetty 9 URL tags when query extraction throws StringIndexOutOfBoundsException and adds mocked regression coverage. The latest commit records both Mockito dependencies on the test classpaths, resolving the earlier lockfile finding; no findings remain open, with validation limited to static review.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 4bc1958

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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.

LGTM. One small request for the PR description. The base code already sets http.url before reading the query. The behavior this PR changes is what happens next. Treating the unreadable query as absent lets request decoration continue after the query read fails. Could you update the description to reflect that?

@dougqh

dougqh commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-18 18:28:12 UTC ℹ️ Start processing command /merge


2026-11-18 18:28:19 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-11-18 18:59:09 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-18 19:41:53 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit d930ebf into master Nov 18, 2026
687 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/jetty9-unreadable-query branch November 18, 2026 19:41
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: jetty Jetty instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: telemetry error reported Reported by error telemetry type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants