opentelemetry-java-instrumentation icon indicating copy to clipboard operation
opentelemetry-java-instrumentation copied to clipboard

fix: optimize dataSourceName to resolve metrics high cardinality

Open YaoYingLong opened this issue 4 months ago • 2 comments

Summary

Fix high-cardinality c3p0 connection pool metric attributes when dataSourceName is not explicitly configured.

Previously, c3p0 metrics used PooledDataSource#getDataSourceName() directly as the connection pool name. In c3p0, if users do not call setDataSourceName(...), the underlying dataSourceName property remains unset, but getDataSourceName() falls back to getIdentityToken(). That identity token is generated per data source instance and includes VM/object-identity based values, so using it as pool.name / db.client.connection.pool.name can create high-cardinality metric attributes.

This change keeps explicitly configured dataSourceName values unchanged, but replaces c3p0 identity-token fallback values with generated low-cardinality names like c3p0-1.

Details

c3p0 documents dataSourceName as defaulting to either the named config name or an opaque identity token when no explicit name is set: https://www.mchange.com/projects/c3p0/#dataSourceName

The fallback behavior is implemented in AbstractPoolBackedDataSource#getDataSourceName(), which returns getIdentityToken() when the stored dataSourceName is null: https://github.com/swaldman/c3p0/blob/9084ab6577bb195672b8831d8fdbb9be22f76ebe/src/com/mchange/v2/c3p0/impl/AbstractPoolBackedDataSource.java#L1506-L1521

The identity token is generated by C3P0ImplUtils.allocateIdentityToken(...) using VM/object-identity based values: https://github.com/swaldman/c3p0/blob/9084ab6577bb195672b8831d8fdbb9be22f76ebe/src/com/mchange/v2/c3p0/impl/C3P0ImplUtils.java#L1407-L1452

Changes

  • Preserve user-provided c3p0 dataSourceName values for connection pool metrics.
  • Detect the c3p0 identity-token fallback and replace it with a generated default pool name.
  • Keep generated names stable for the registered data source lifetime.
  • Remove generated name state when metrics are unregistered.
  • Add test coverage for both explicit dataSourceName and unset dataSourceName cases.

YaoYingLong avatar Jul 09 '26 10:07 YaoYingLong

Pull request dashboard status

Merged · refreshed 2026-08-04 02:28 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Hi @YaoYingLong — just a friendly reminder that this pull request is waiting on you.

There are still items that need your attention. See the dashboard status comment for the full list. You don't need to push a code change to hand it back — replying to move each discussion forward is enough, whether that's answering a question, explaining why no change is needed, or asking a follow-up. The dashboard then automatically routes it back to reviewers.

If you believe this pull request is incorrectly routed as waiting on the author, comment /dashboard route:reviewers to route it from waiting on the author to waiting on reviewers.

Thank you for your contribution @YaoYingLong! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

otelbot[bot] avatar Aug 02 '26 23:08 otelbot[bot]