open-telemetry / opentelemetry-sqlcommenter

SQLCommenter components for various languages
Apache License 2.0
28 stars 13 forks source link

[Java] Would injecting trace context to a prepared statement work properly? #32

Open jiwen624 opened 2 years ago

jiwen624 commented 2 years ago

Hello there,

I'm looking into the code of io.opentelemetry.sqlcommenter.schibernate.SCHibernate where the current trace context is injected as a comment into a SQL statement which will be prepared later. However, as a PreparedStatement object it is normally prepared once but executed many times with different parameter values and this may be a problem.

Let's imagine a scenario where a web application is serving client requests and the injected statement is prepared and stored somewhere in a thread and reused by multiple client requests. When the subsequent client requests are handled, the same trace context is reused again and again because the same prepared statement is executed. I guess this would lead to an incorrect correlation?

Thanks.

sjs994 commented 2 years ago

Thanks @jiwen624 for creating a bug for this. When i last tested with hibernate, it seemed the execution of prepared statements were not instrumented. I can reverify it again.

But anyway, this is a bug. Will assign it to myself for now.