Open peterdk opened 2 weeks ago
Hello @peterdk, can you confirm io.sentry.jdbc.SentryJdbcEventListener
is actually being invoked in your setup? If so, does it find a valid transaction/span to create a child under?
@adinauer I can check, but how would I do that? I don't know if you can set breakpoints on library code? I'll try.
@Override
public void onBeforeAnyExecute(final @NotNull StatementInformation statementInformation) {
final ISpan parent = hub.getSpan();
if (parent != null && !parent.isNoOp()) {
final ISpan span = parent.startChild("db.query", statementInformation.getSql());
CURRENT_SPAN.set(span);
span.getSpanContext().setOrigin(TRACE_ORIGIN);
}
}
parent
seems to be null, the breakpoint on span
never triggers after the parent
breakpoint.
I do use Kotlin and ktor, so it's inside a coroutine. Already tried wrapping the main trace fun content with
withContext(SentryContext()) {`
and also the DB call parent functions all as suspend, but no changes.
Also only wrapping non suspend functions part (including the DB calls) with a Transaction
doesn't do anything.
Am I doing something wrong the the trace wrapping logic? span is empty, right after transaction start
val transaction = Sentry.startTransaction(name, operation)
try {
val hub = Sentry.getCurrentHub() //exists
val span = hub.span //null
doSomething()
I would expect that span would not be null?
Can you please take a look at https://docs.sentry.io/platforms/java/tracing/instrumentation/custom-instrumentation/#create-transaction-bound-to-the-current-scope and see if that helps?
Sorry, I guess this isn't too intuitive.
@adinauer I was just looking into that indeed. The span is not empty now! And indeed the JDBC breakpoint triggers and I do get query data now in Sentry! Great.
Maybe improve the docs a bit?
We'll discuss whether it makes sense to have separate methods in the future that make this more clear. We're currently changing lots of things in the SDK for v8 and this is one of the things on the list.
Integration
sentry-jdbc
Java Version
18
Version
7.10.0
Steps to Reproduce
I use Ktor for a API and am looking into a tool that can help monitor performance. I saw that Sentry supports JDBC queries, and that is something I am looking for.
I added to my build.gradle.kts:
My DB setup logic:
Sentry init:
I then instrumented one of the endpoints by wrapping the logic:
Expected Result
I expect that
Queries
section of Sentry is now being filled, but I only see data inTraces
. In the logging I don't see anything related to JDBC. In the docs I don't see anything else that I would need to setup.I am on the developer plan, but from what I see the queries section should be available until half July or so. Or am I already required to have a business plan?
Actual Result
I only see data in Traces, not in Queries and also not in Requests.
I do see the transactions logged in spy.log, so p6spy is working.
Sentry logging after a call happens: