Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC OpenTelemetryStatement#getConnection() Doesn't Return Wrapped Connection #10550

Closed
rgrochowicz opened this issue Feb 14, 2024 · 0 comments · Fixed by #10554
Closed

JDBC OpenTelemetryStatement#getConnection() Doesn't Return Wrapped Connection #10550

rgrochowicz opened this issue Feb 14, 2024 · 0 comments · Fixed by #10554
Labels
bug Something isn't working needs triage New issue that requires triage

Comments

@rgrochowicz
Copy link

rgrochowicz commented Feb 14, 2024

Describe the bug

We're using OpenTelemetry's JDBC data source instrumentation library to wrap and instrument our JDBC connections. However, when getting the connection used for a PreparedStatement, the library returns the underlying connection rather than the wrapped, Otel-provided connection.

In a very narrow case, with:

  • An Otel-instrumented connection pool like Hikari
  • Spring's TransactionTemplate + JdbcTemplate
  • Using JdbcTemplate#queryForStream

Spring will call OpenTelemetryStatement#getConnection(), receive the non-wrapped connection, and through reference checks that return false, mistakenly close the connection.

Instead, OpenTelemetryStatement#getConnection() should return the wrapped connection that created the Statement rather than deferring to its delegate.

Steps to reproduce

(executing within this Otel test)

JdbcTelemetry telemetry = JdbcTelemetry.create(testing.getOpenTelemetry());
DataSource dataSource = telemetry.wrap(new TestDataSource());
    
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
assertEquals(connection, statement.getConnection());

The assertion fails when I'd expect it to succeed.

Expected behavior

OpenTelemetryStatement#getConnection() returns the wrapped connection (OpenTelemetryConnection) that's the same wrapped connection used to create the statement.

Actual behavior

OpenTelemetryStatement#getConnection() returns the underlying connection rather than the wrapped connection.

Javaagent or library instrumentation version

v1.31.1

Environment

JDK: Corretto 17
OS: macOS / Amazon Linux 2023

Additional context

No response

@rgrochowicz rgrochowicz added bug Something isn't working needs triage New issue that requires triage labels Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New issue that requires triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant