Skip to content

Stop connection pool liveness checks from creating spans (quick fix - span reduction) - #13677

Open
dougqh wants to merge 5 commits into
masterfrom
dougqh/jdbc-pool-validation-suppression
Open

dougqh wants to merge 5 commits into
masterfrom
dougqh/jdbc-pool-validation-suppression

Conversation

@dougqh

@dougqh dougqh commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Connection pool liveness checks (SELECT 1 FROM DUAL, Connection.isValid) no longer create spans. This covers HikariCP, DBCP2 (standalone and Tomcat-bundled), Tomcat JDBC and c3p0, on borrow, on return and from keepalive timers.

It is on by default. DD_TRACE_JDBC_POOL_VALIDATION_ENABLED=false restores the previous behavior.

It also fixes a SQL Server DBM full-mode bug that this change made reachable on every borrow: setContextInfo unboxed a null sampling decision under muted tracing, threw an NPE, and the catch used up the once-only DBM injection warning. That would have hidden any later real injection failure.

Motivation

Customers hitting ingestion overages show large volumes of pool validation queries. In one case they were ~800k requests among the top Oracle resources. Checks that run on a background thread become standalone root traces. Checks on borrow add a child span to every request that reuses an idle connection. Nobody gets value from these spans, and they are cheap to stop at the source rather than filtering them later.

Additional Notes

  • Validation runs under a black-hole span, so the check creates no span and injects no DBM trace context. In DBM service/full modes the validation SQL still gets the service-level comment, so DBM can still attribute the query to the service; only the span link is gone.
  • Tomcat JDBC runs the user's initSQL through validate(VALIDATE_INIT), so that action stays traced, along with the test-on-connect check that shares it.
  • Session-scoped DBM propagation (SQL Server context_info, Oracle action, Postgres application_name) persists on the connection. A muted query skips the write, so DBM may associate it with the previous request's context. That behavior already exists under @DoNotTrace; this change doesn't make it worse, but it's worth a DBM opinion.
  • Not covered yet: Oracle UCP, and application-level health checks (e.g. Spring Boot's DataSourceHealthIndicator).
  • Tests count validation calls through an H2 function, so they fail if the pool didn't actually validate. With the advice disabled, they fail on leaked validation spans.

Contributor Checklist

🤖 Generated with Claude Code

dougqh and others added 5 commits November 24, 2026 09:28
Pools validate connections with a test query such as SELECT 1 FROM DUAL,
on borrow, on return and from keepalive timers. Each check produced a
JDBC span: a child span inside application traces when validating on
borrow, and a standalone root trace when validating in the background.

Run HikariCP, DBCP2 (standalone and Tomcat-bundled), Tomcat JDBC and
c3p0 validation under a black-hole span, so the checks create no spans
and inject no DBM trace context. Tomcat's init SQL runs through the same
validate method and stays traced.

The integration is on by default and can be turned off with
DD_TRACE_JDBC_POOL_VALIDATION_ENABLED=false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The validation query calls a counting H2 function, so each case also
proves the pool really validated during the traced borrow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setContextInfo unboxed forceSamplingDecision() without a null check.
Under a black-hole span, such as a muted pool validation or
@DoNotTrace, the decision is null, so it threw an NPE. The catch logged
a misleading DBM warning and used up the once-only injection warning,
hiding any later real injection failure.

Return before the round trip when there is no sampling decision, as the
Oracle action and SQL comment paths already do. Traced queries are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the local runUnderTrace with TraceUtils.runUnderTrace, and say
why the warm-up sleep is needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: feature Enhancements and improvements inst: jdbc JDBC instrumentation labels Nov 25, 2026
@datadog-official

datadog-official Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 61.13% (-0.09%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 25, 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.87 s 14.76 s [-0.1%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 13.75 s 13.72 s [-0.4%; +0.8%] (no difference)
startup:petclinic:appsec:Agent 17.88 s 17.77 s [-0.5%; +1.7%] (no difference)
startup:petclinic:iast:Agent 17.78 s 17.78 s [-0.9%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 17.46 s 17.56 s [-1.8%; +0.6%] (no difference)
startup:petclinic:sca:Agent 17.19 s 17.83 s [-7.8%; +0.6%] (no difference)
startup:petclinic:tracing:Agent 16.88 s 16.98 s [-1.8%; +0.7%] (no difference)

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

@dougqh

dougqh commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 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-12-02T04:09:09.996816Z c006385 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

Copy link
Copy Markdown

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

Reviewed commit: c006385ff2

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

@dougqh
dougqh marked this pull request as ready for review December 2, 2026 04:07
@dougqh
dougqh requested review from a team as code owners December 2, 2026 04:07
@dougqh
dougqh requested review from sarahchen6 and ygree and removed request for a team December 2, 2026 04:07
@dd-octo-sts dd-octo-sts Bot added the tag: ai generated Largely based on code generated by an AI or LLM label Dec 2, 2026

@datadog-official datadog-official 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

Validation suppression restores the previous scope on exceptional exits and leaves Tomcat initialization SQL traced. The specialist’s completed static review identified no actionable defects.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit c006385

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

inst: jdbc JDBC instrumentation tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant