Skip to content

Conversation

jaydeluca
Copy link
Member

Closes #8303

@jaydeluca jaydeluca requested a review from a team as a code owner October 3, 2025 21:32
- name: jdbc
description: |
The JDBC instrumentation provides database client spans and metrics. Each call produces a span named after the SQL verb, enriched with standard DB client attributes (system, database, operation, sanitized statement, peer address) and error details if an exception occurs.
The instrumentation unwraps pooled connections to cache database metadata. If your connection pool doesn't support unwrapping (java.sql.Wrapper), metadata extraction will occur on every operation, causing higher CPU usage.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will require more careful wording. CPU usage isn' the real issue. The problem is that calling getMetaData may result in querying database (what this method does depends on the database driver, also the driver may cache the results). I'd suggests you to rephrase with emphasis on that instrumentation requires that connections can be unwrapped and that inability to unwrap may cause degraded performance or have increased overhead with some jdbc drivers. Below you also mention that unwrapping is needed for attributing work to correct connection. There was recently an issue with shardingsphere where we showed the wrong database for some queries.

Comment on lines 30 to 31
**Failover note:** Cached metadata uses the unwrapped connection object as the key. If your pool
reuses the same connection object after failover, telemetry may show stale host attributes.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not clear on the specifics reported in #8303 (comment)

but wondering if it's this:

https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/sql.md

[1] db.namespace: ...

A connection's currently associated database may change during its lifetime, e.g. from executing USE <database>.

If instrumentation is unable to capture the connection's currently associated database on each query without triggering an additional query to be executed (e.g. SELECT DATABASE()), then it is RECOMMENDED to fallback and use the database provided when the connection was established.

Instrumentation SHOULD document if db.namespace reflects the database provided when the connection was established.

Comment on lines 12 to 20
The JDBC instrumentation requires unwrapping pooled connections (via `java.sql.Wrapper`) to
correctly attribute database operations to the underlying connection and to cache metadata. Most
connection pools support this by default.

**Performance issue?** If unwrapping fails, the instrumentation may have degraded performance or
increased overhead with some JDBC drivers. Metadata extraction may result in database queries on
every operation (depending on driver implementation and caching behavior) instead of being cached,
and operations may be attributed to the wrong database connection. To fix, ensure your connection
pool supports unwrapping:
Copy link
Member

Choose a reason for hiding this comment

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

The instrumentation unwraps pooled connections (via java.sql.Wrapper) to cache database metadata
against the underlying physical connection. Most connection pools support this by default.

In the case that a connection pool doesn't support this, caching is limited
to the wrapper instance, which typically changes each time a connection is retrieved from the pool.
This can result in repeated metadata extraction, potentially causing performance degradation.

Comment on lines 27 to 28
**Custom wrappers:** Implement `java.sql.Wrapper` correctly to delegate `isWrapperFor()` and
`unwrap()` to the underlying connection.
Copy link
Member

Choose a reason for hiding this comment

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

not sure if this is needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running JDBC instrumentation causing delays in socket read from DB

3 participants