Skip to content

Do not use null parent context on tomcat advice#11968

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
andrea.marziali/npe-inferred
Jul 16, 2026
Merged

Do not use null parent context on tomcat advice#11968
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
andrea.marziali/npe-inferred

Conversation

@amarziali

@amarziali amarziali commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

HttpServerDecorator is doing a couple of actions concerning the inferred proxy spans that assumes that the parent context used to extract this information is not null but actually the tomcat 5.5 instrumentation passes a null context

java.lang.NullPointerException
  at gateway.InferredProxySpan.fromContext(InferredProxySpan.java:65)
  at decorator.HttpServerDecorator.registerServiceEntrySpanInInferredProxy(HttpServerDecorator.java:218)
  at decorator.HttpServerDecorator.startSpan(HttpServerDecorator.java:181)

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali amarziali added the type: bug fix Bug fix label Jul 16, 2026
@amarziali amarziali requested a review from a team as a code owner July 16, 2026 08:21
@amarziali amarziali added the comp: core Tracer core label Jul 16, 2026
@amarziali amarziali requested review from vandonr and removed request for a team July 16, 2026 08:21
@amarziali amarziali added the tag: telemetry error reported Reported by error telemetry label Jul 16, 2026
@amarziali amarziali requested a review from jandro996 July 16, 2026 08:21

@jandro996 jandro996 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks for the fix

@amarziali amarziali marked this pull request as draft July 16, 2026 08:23

@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: e10a139f87

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amarziali amarziali force-pushed the andrea.marziali/npe-inferred branch from e10a139 to 0ee35f5 Compare July 16, 2026 08:26
@amarziali amarziali marked this pull request as ready for review July 16, 2026 08:27
@jandro996 jandro996 self-requested a review July 16, 2026 08:27
@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

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

Datadog Autotest: PASS

More details

The PR correctly guards against null parentContext when accessing inferred proxy span operations. The original code would NPE when parentContext was null because InferredProxySpan.fromContext(parentContext) calls .get() on a null object. The fix wraps the two affected operations in an if (parentContext != null) check and handles the null case in the return statement by returning the span directly (AgentSpan extends Context, so it's type-safe). This is a focused defensive programming fix that resolves a real production crash with no unintended side effects.

Was this helpful? React 👍 or 👎

📊 Validated against 3 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 0ee35f5 · What is Autotest? · Any feedback? Reach out in #autotest

@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: 0ee35f5166

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amarziali amarziali requested a review from a team as a code owner July 16, 2026 08:40
@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: be05cbf09a

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-prod-us1-6

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Jul 16, 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.97 s 14.01 s [-1.0%; +0.3%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 13.01 s [-1.0%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 16.87 s 16.56 s [+0.7%; +3.0%] (maybe worse)
startup:petclinic:iast:Agent 16.93 s 16.88 s [-0.4%; +1.0%] (no difference)
startup:petclinic:profiling:Agent 16.78 s 16.77 s [-1.3%; +1.5%] (no difference)
startup:petclinic:sca:Agent 16.87 s 16.75 s [-0.4%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.03 s 16.12 s [-1.5%; +0.4%] (no difference)

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

@jandro996 jandro996 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix itself looks solid (defense in depth: normalizing parentContext to root() at the top of startSpan, plus a null-tolerant fromContext). One request before merging: add a regression test.

Comment thread internal-api/src/main/java/datadog/trace/api/gateway/InferredProxySpan.java Outdated

@PerfectSlayer PerfectSlayer 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.

I don't think this is the right wait to fix the issue. Added a comment about it

@jandro996 jandro996 self-requested a review July 16, 2026 09:15
@amarziali amarziali force-pushed the andrea.marziali/npe-inferred branch from be05cbf to bd8e1cd Compare July 16, 2026 09:33
@amarziali amarziali changed the title Guard from null parentContext when accessing inferred proxy span Do not use null parent context on tomcat advice Jul 16, 2026
@amarziali amarziali removed the comp: core Tracer core label Jul 16, 2026
@amarziali amarziali added the inst: others All other instrumentations label Jul 16, 2026
@amarziali amarziali requested a review from PerfectSlayer July 16, 2026 09:36
@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: ad0cff3df2

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jandro996 jandro996 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch on the real root cause, much cleaner fix. Since this was a production NPE, could you add a small regression test for it? Even a unit test on ServiceAdvice.onService with a non-Context attribute would do.

@PerfectSlayer PerfectSlayer 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.

Thanks for the follow up change

@amarziali amarziali enabled auto-merge July 16, 2026 10:21
@amarziali amarziali added this pull request to the merge queue Jul 16, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 16, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-16 10:30:57 UTC ℹ️ Start processing command /merge


2026-07-16 10:31:01 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-07-16 11:35:21 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit 47a760b into master Jul 16, 2026
586 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the andrea.marziali/npe-inferred branch July 16, 2026 11:35
@github-actions github-actions Bot added this to the 1.65.0 milestone Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: others All other instrumentations 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.

3 participants