Skip to content

Add otel4s-instrumentation module#2387

Open
iRevive wants to merge 1 commit into
typelevel:mainfrom
iRevive:topic/otel4s/jdbc-telemetry
Open

Add otel4s-instrumentation module#2387
iRevive wants to merge 1 commit into
typelevel:mainfrom
iRevive:topic/otel4s/jdbc-telemetry

Conversation

@iRevive

@iRevive iRevive commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

This module specifically targets the OpenTelemetry instrumentation module. However, it works without IOLocal propagation, which can incur a notable performance penalty.

Usage example: iRevive/otel4s-showcase#6.

image

Comment on lines +27 to +32
val scope = ctx.underlying.makeCurrent()
try {
f(a)
} finally {
scope.close() // release the context
}

@iRevive iRevive Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the main trick: we explicitly activate context when running primitive operations.

So JdbcTelemetry instrumentation runs in the correct context, and the spans are correctly connected.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super simple.
Maybe this even makes it easier to connect errors to the correct origin.
Sometime / often in doobie the stacktraces contain no connection to the application code.

@iRevive iRevive force-pushed the topic/otel4s/jdbc-telemetry branch from f039d80 to 8b6d005 Compare February 27, 2026 20:27
@iRevive

iRevive commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

@mzuehlke while #2385 looks good, this functionality is surprisingly straightforward.

The classpath pollution is also minimal:
https://mvnrepository.com/artifact/io.opentelemetry.instrumentation/opentelemetry-jdbc/2.25.0-alpha/dependencies

@iRevive iRevive force-pushed the topic/otel4s/jdbc-telemetry branch from 8b6d005 to 5cdd9a1 Compare February 27, 2026 20:36
@iRevive

iRevive commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

I still don't like the fact that we need to include the alpha dependency in the classpath. Perhaps it would be enough to document this, and users can replicate the code in their codebases?

However, I find the new fragment syntax (i.e., queryWithSummary) quite useful, and it will not work with this instrumentation out of the box. But with a few tricks, it can be doable, I think.

@iRevive iRevive force-pushed the topic/otel4s/jdbc-telemetry branch from 5cdd9a1 to 8fae488 Compare February 27, 2026 20:39
@iRevive iRevive marked this pull request as ready for review June 14, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants