Remove JMX registration requirement for Apache DBCP 2.0 metrics#19160
Remove JMX registration requirement for Apache DBCP 2.0 metrics#19160YaoYingLong wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the hard dependency on JMX/MBeanRegistration for Apache DBCP 2.0 connection‑pool metrics auto‑instrumentation. Previously, metrics were only registered when a BasicDataSource was registered to an MBeanServer (via preRegister), which meant instrumentation silently did nothing outside JMX‑enabled setups (e.g. Spring Boot). The instrumentation now hooks the BasicDataSource#createDataSource() lifecycle so metrics are collected regardless of JMX, with a generated dbcp2-N fallback name when no name is otherwise available.
Changes:
- Switch the javaagent advice from
preRegister/postDeregistertocreateDataSource(registration) andclose/postDeregister(cleanup), resolving the data source name fromgetJmxName()→ registered JMXObjectName→ generated default. - Add a same‑package helper
OpenTelemetryBasicDataSourceUtil(registered viaisHelperClass) to accessBasicDataSource#getRegisteredJmxName(), and exposeDataSourceMetrics.getDefaultName()for thedbcp2-Nfallback. - Refactor the shared abstract test to support JMX‑less registration, add javaagent tests for default/registered/preferred naming, and update README/metadata docs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.../v2_0/BasicDataSourceInstrumentation.java |
Re‑targets advice to createDataSource/close/postDeregister and adds the new name‑resolution order. |
.../org/apache/commons/dbcp2/OpenTelemetryBasicDataSourceUtil.java |
New same‑package accessor for getRegisteredJmxName(). |
.../v2_0/ApacheDbcpInstrumentationModule.java |
Registers the new helper class via isHelperClass. |
.../v2_0/DataSourceMetrics.java |
Made public and adds getDefaultName() counter for fallback names. |
.../v2_0/ApacheDbcpInstrumentationTest.java (javaagent) |
Adds tests for default/registered/preferred JMX naming. |
.../AbstractApacheDbcpInstrumentationTest.java (testing) |
Refactors shared setup/assertions for JMX‑less flow. |
javaagent/README.md, metadata.yaml |
Documents that JMX registration is no longer required. |
Pull request dashboard statusStatus last refreshed: 2026-07-22 01:49:46 UTC.
This automated status or its linked feedback items may be incorrect. If something looks wrong, report it with the result you expected. |
|
can you update PR description to include motivation for why this PR? e.g.
|
|
@trask The PR description has been updated, with additional explanations added to clarify the rationale behind this PR submission. |
|
is this a breaking change? if so, let's put it behind the v3preview flag and try to get it into v2.30.0 |
@trask From my perspective, this is not a breaking change. It merely modifies the metric attribute name, switching the original high-cardinality value to a low-cardinality one. If you determine this counts as a breaking change, do we need to refactor the code for backward compatibility using a method like |
I think no: Existing users on the normal successful JMX path retain the name derived from their registered ObjectName. Non-JMX users previously received no Apache DBCP metrics, so the JDBC-derived or fallback name belongs to newly added telemetry and has no existing name to preserve. |
…al registered MBean name
…cs after JMX deregistration
Make Apache DBCP 2.0 connection pool metrics independent of JMX registration by registering metrics after
startPoolMaintenance()initializes the pool. Metric callbacks remain active through MBean deregistration and are removed whenBasicDataSource.close()completes, including exceptional exits.Resolve pool names from the registered JMX
ObjectName, then the JDBC URL and connection properties, withapache-dbcp2as the fallback. This does not change any public API or configuration property.