Description
Describe the bug
I have a Ktor 3 based project I want to use tracing with, but the CallLogging
and StatusPages
logs don't have tracing data included in them.
Steps to reproduce
Run a basic Ktor application with the module configuration like this:
fun Application.module() {
// ...
install(CallLogging) {
level = Level.INFO
}
tracing() // details don't matter
install(StatusPages) {
exception<Throwable> {
// ...
}
}
// ...
}
Expected behavior
In case of a successful call (200 status), the log statements from CallLogging
plugin should include tracing data.
In case of an error, log statements from the status page configuration should include tracing data as well.
Actual behavior
Neither of the above cases have tracing data in their log statements
Javaagent or library instrumentation version
io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:2.12.0-alpha
Environment
JDK: Temurin 21
OS: Ubuntu 24.04
Additional context
I did a whole bunch of debugging and what I've noticed is that the io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil#configureTelemetry
function sets up tracing before the monitoring phase, which is way too late in the pipeline.
Both the above mentioned CallLogging
and StatusPages
plugins use hooks that run BEFORE the Monitoring
and therefore the OpenTelemetry
phases. In case of StatusPages
, the hook used is CallFailed
which intercepts the BeforeSetup
phase.
I think, that tracing should start as early in the pipeline as possible, therefore I suggest inserting the OpenTelemetry
phase before the BeforeSetup
phase, or at least before the Setup
phase (I realize BeforeSetup isn't guaranteed to exist).