SqlLogger with custom request ID

14 views
Skip to first unread message

Alex Buchanan

unread,
Jan 13, 2022, 8:16:17 PM1/13/22
to jDBI
Hello,

Is it possible to pass a request ID (or other request metadata) through to a SqlLogger implementation?

It seems that the SqlLogger would be instantiated globally (once at app startup), and I don't see a clear path for updating the StatementContext with a request ID.

By "request ID" I mean some string that can be easily linked to the HTTP request which resulted in the JDBI queries being executed (such as a distributed trace ID).

Thanks!

Alex Buchanan

unread,
Jan 13, 2022, 10:33:22 PM1/13/22
to jDBI
Or, perhaps SqlLogger isn't what I need, perhaps there's a different approach for doing per-query instrumentation with request context?

Steven Schlansker

unread,
Jan 14, 2022, 3:41:16 PM1/14/22
to jd...@googlegroups.com
There's nothing specific for handling request ID, but you're free to define it as an attribute which can be read through the StatementContext.
Since Jdbi does not use background threads or async requests, a ThreadLocal will also work in a pinch, but it's not as maintainable as making it explicit.
> --
> You received this message because you are subscribed to the Google Groups "jDBI" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jdbi/acad1738-7492-46d8-b79b-04042188c35fn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages