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

LocalRootSpan.current() referring to wrong span #6876

Open
patschl opened this issue Nov 13, 2024 · 1 comment
Open

LocalRootSpan.current() referring to wrong span #6876

patschl opened this issue Nov 13, 2024 · 1 comment
Labels
Bug Something isn't working needs author feedback Waiting for additional feedback from the author

Comments

@patschl
Copy link

patschl commented Nov 13, 2024

Describe the bug
For longer running jobs I am creating new root spans that link back to the span that created them in order to better organise and trace what's going on.
In those newly created root spans (ultimately new traces) I am using LocalRootSpan.current().setAttribute(key, value). I expected this to set the attribute on the created root span, but instead the attribute will be on the original root span of the job that created the new span.

Steps to reproduce

fun processInNewRootSpan() {
   // create tracer 
    val currentSpan = Span.current()
    val newSpan = tracer.spanBuilder("ProcessInNewRoot").addLink(currentSpan.spanContext).setNoParent().startSpan()

    try {
        newSpan.makeCurrent().use {
            process()
        }
    } finally {
        newSpan.end()
    }
}

fun process() {
    //do stuff
    LocalRootSpan.current().setAttribute("myattribute", "value")
}

What did you expect to see?
I expect myattribute to be set on the created ProcessInNewRoot span.

What did you see instead?
Attribute is actually set on the original root span that invoked the processInNewRootSpan() method.

What version and what artifacts are you using?
Artifacts:
io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:2.9.0,
io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.43.0

Environment
Compiler: AWS corretto 21.0.5
OS: (e.g., "Ubuntu 20.04")

Additional context
Am I wrong about my expected behaviour? The javadoc reads A local root span is a span that either does not have a parent span (it is the root span of a trace).
The newly created root span does not have a parent span.

@patschl patschl added the Bug Something isn't working label Nov 13, 2024
@trask
Copy link
Member

trask commented Nov 14, 2024

hi @patschl, LocalRootSpan is only an opentelemetry-instrumentation-api concept, and so only works if your local root span is created using opentelemetry-instrumentation-api and won't work if your local root span is created using opentelemetry-api

@jack-berg jack-berg added the needs author feedback Waiting for additional feedback from the author label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working needs author feedback Waiting for additional feedback from the author
Projects
None yet
Development

No branches or pull requests

3 participants