Skip to content

InternalTagAdder: defensively guard against null prebuilt tagmap entry#11958

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
andrea.marziali/npe-tag
Jul 15, 2026
Merged

InternalTagAdder: defensively guard against null prebuilt tagmap entry#11958
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
andrea.marziali/npe-tag

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

There is a codepath where, if DD_SERVICE is set empty, the prebuilt tagmap entry for _dd.base_service is null and can break the advice from the span finish callsite

Having an empty service name is not something we should allow. We prevent only null becoming unnamed-java-service but when it's set to the config it can be empty.

This PR implements a defensive fix

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali
amarziali requested a review from a team as a code owner July 15, 2026 12:28
@amarziali
amarziali requested a review from dougqh July 15, 2026 12:28
@amarziali amarziali added type: bug fix Bug fix comp: core Tracer core labels Jul 15, 2026

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

PR adds a defensive null check to prevent NullPointerException when DD_SERVICE is empty. The baseServiceEntry field becomes null due to TagMap.Entry.create() returning null for empty CharSequences; without the guard, calling unsafeTags.set(null) would crash. The fix is minimal, targeted, and correct — tested with new case for empty DD_SERVICE configuration.

Was this helpful? React 👍 or 👎

📊 Validated against 3 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 041bd68 · What is Autotest? · Any feedback? Reach out in #autotest

@amarziali
amarziali enabled auto-merge July 15, 2026 12:33
@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Jul 15, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 50.00%
Overall Coverage: 56.88% (-0.29%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 041bd68 | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 15, 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.96 s 13.99 s [-0.9%; +0.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.04 s [-1.8%; -0.5%] (maybe better)
startup:petclinic:appsec:Agent 16.98 s 16.80 s [+0.0%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 16.43 s 17.04 s [-7.9%; +0.7%] (no difference)
startup:petclinic:profiling:Agent 16.81 s 16.80 s [-0.7%; +0.9%] (no difference)
startup:petclinic:sca:Agent 16.97 s 16.80 s [+0.1%; +1.9%] (maybe worse)
startup:petclinic:tracing:Agent 16.16 s 16.01 s [-0.2%; +2.1%] (no difference)

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

@amarziali
amarziali added this pull request to the merge queue Jul 15, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

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

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-15 13:13:48 UTC ℹ️ Start processing command /merge


2026-07-15 13:13:53 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-07-15 14:23:14 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 15, 2026
@bric3

bric3 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Related to #11555

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit d3d2e12 into master Jul 15, 2026
588 of 594 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the andrea.marziali/npe-tag branch July 15, 2026 14:23
@github-actions github-actions Bot added this to the 1.65.0 milestone Jul 15, 2026
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Jul 15, 2026
Make the TagMap Entry pathway null-tolerant

create(Object)/create(CharSequence) may return null for a null or empty
value, and the Entry sinks -- getAndSet(Entry) / set(EntryReader) -- treat a
null Entry as a no-op, so a null/empty value flows through the Entry pathway
as "no tag" without any caller guarding. create(Object) now applies the
empty-CharSequence check by runtime type, so the null/empty => absent
convention holds regardless of the static type at the call site.

The strict (key,value) setters keep their contract -- their values are now
@nonnull -- so null tolerance is scoped to the Entry pathway. The annotations
make the split self-describing.

Fixes a latent NPE by construction: RemoteHostnameAdder sets
create(TRACER_HOST, hostname) guarding only null, not empty, so an empty
hostname previously NPE'd on set(null). Caller-side guard cleanup (incl. the
redundant #11958 guard) is left to a follow-up.

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

Mark tag keys @nonnull on the TagMap write/create surface

A tag has no valid null key, so put/set/getAndSet/create now take @nonnull
tag. This completes the null contract alongside the value/Entry side: keys
are strict (null = a bug), values/Entries on the Entry pathway are tolerant
(null = no tag). Scoped to the write/create surface; read/lookup keys
(getString, remove, getXxxOrDefault) are left for a possible follow-up.

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

Brace single-statement null-check ifs per style convention

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

Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants