Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ktor 3: CallLogging and StatusPages don't have Trace IDs #13237

Closed
rolaca11 opened this issue Feb 6, 2025 · 2 comments · Fixed by #13239
Closed

Ktor 3: CallLogging and StatusPages don't have Trace IDs #13237

rolaca11 opened this issue Feb 6, 2025 · 2 comments · Fixed by #13239
Labels
bug Something isn't working contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome

Comments

@rolaca11
Copy link
Contributor

rolaca11 commented Feb 6, 2025

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).

@rolaca11 rolaca11 added bug Something isn't working needs triage New issue that requires triage labels Feb 6, 2025
@laurit
Copy link
Contributor

laurit commented Feb 6, 2025

We'd welcome a contribution for this.

@laurit laurit added contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome and removed needs triage New issue that requires triage labels Feb 6, 2025
rolaca11 added a commit to rolaca11/opentelemetry-java-instrumentation that referenced this issue Feb 6, 2025
rolaca11 added a commit to rolaca11/opentelemetry-java-instrumentation that referenced this issue Feb 6, 2025
@rolaca11
Copy link
Contributor Author

rolaca11 commented Feb 6, 2025

Thank you, I made a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants