open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.89k stars 825 forks source link

[Kotlin] Custom contexts and spans are not being associated with OTEL objects automatically generated with the agent jar #6887

Closed chomey closed 1 year ago

chomey commented 1 year ago

Describe the bug The automatically generated trace data for database interactions is not being associated with custom context and spans defined in the calling functions.

Screen Shot 2022-10-14 at 16 04 39

Ideally, the root span of the top trace in the screenshot, comprising of 3 spans, should be parented by the last span of the bottom span.

Top span:

Screen Shot 2022-10-14 at 16 09 03

The top span is generated automatically from -javaagent.

I'm running the database function like this:

        val span = GlobalOpenTelemetry.getTracer("my-tracer")
            .spanBuilder("my-span")
            .setParent(coroutineContext.getOpenTelemetryContext())
            .startSpan()
        withContext(span.asContextElement()) {
            try {
                doMyDatabaseCalls() // Agent is auto instrumenting my DB calls here
            } catch (e: Throwable) {
                span.recordException(e)
                span.setStatus(StatusCode.ERROR)
                throw e
            } finally {
                span.end()
            }
        }

What did you expect to see? The full trace to be a single trace, all nested under a single root span.

What did you see instead? See screenshot

What version and what artifacts are you using? Maven Versions:

Agent Version: https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/tag/v1.19.0

Environment Compiler:

openjdk version "17.0.3" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu17.34+19-CA (build 17.0.3+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.34+19-CA (build 17.0.3+7-LTS, mixed mode, sharing)

OS:

Apple Silicon 12.2.1
chomey commented 1 year ago

Oh... should I be creating this issue on the https://github.com/open-telemetry/opentelemetry-java-instrumentation repository instead?

jkwatson commented 1 year ago

Oh... should I be creating this issue on the https://github.com/open-telemetry/opentelemetry-java-instrumentation repository instead?

yes. I will transfer it over there.

laurit commented 1 year ago

@chomey could you check whether this issue is still present with the latest version of the agent

github-actions[bot] commented 1 year ago

This has been automatically marked as stale because it has been marked as needing author feedback and has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.