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

To enable trace when transaction commit or rollback in jdbc

Open tkmsaaaam opened this issue 1 year ago • 3 comments

Contribute for #10381

To enable trace when transaction commit or rollback in jdbc.

like below image

tkmsaaaam avatar Jun 01 '24 12:06 tkmsaaaam

There are a few things to consider with this instrumentation. Firstly it only updates the jdbc library instrumentation, ideally we'd like to have the same features in the library instrumentation and the javaagent instrumentation. Secondly the implementation assumes that calling Connection.commit() executes sql COMMIT statement, which I suspect isn't always true. It is an internal detail of the driver that depends on the database, it might as well execute COMMIT TRANSACTION instead. https://stackoverflow.com/questions/5248649/jdbc-commit-what-happens-behind-the-scenes suggests that for sql server it is executing IF @@TRANCOUNT > 0 COMMIT TRAN (note that the linked stack overflow question is quite old). If we don't know what statement is really executed perhaps we shouldn't fill db.statement at all? @trask do you any suggestions for this? Does the spec provide guidelines for something like this?

laurit avatar Jun 03 '24 16:06 laurit

hi @tkmsaaaam! can you put this behavior behind an experimental feature flag for now, and open an issue in https://github.com/open-telemetry/semantic-conventions about how to model commit and rollback in database semantic conventions?

trask avatar Jun 06 '24 16:06 trask

hi @tkmsaaaam! can you put this behavior behind an experimental feature flag for now, and open an issue in https://github.com/open-telemetry/semantic-conventions about how to model commit and rollback in database semantic conventions?

Thank you for your review. I opened the issue. https://github.com/open-telemetry/semantic-conventions/issues/1134

tkmsaaaam avatar Jun 09 '24 10:06 tkmsaaaam