question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to created nested spans without passing parents around

See original GitHub issue
  • This only affects the JavaScript OpenTelemetry library
  • [_] This may affect other libraries, but I would like to get opinions here first

I’ve just started using this library in my project so it’s very possible I’m missing something obvious. Apologies if so!

I’ve gotten tracing with Zipkin working - really easily thanks to the guides 😃 I’ve also gotten Express tracing working, and the creation of custom spans. I can also do nested spans, but only if I pass the parent down the call hierarchy.

Is there some way to achieve nested spans without needing to pass the parent around? This is especially important if I want to have the child created several steps below the parent.

For example:

function a() {
    const span = opentelemetry.trace.getTracer('default').startSpan('a');
    b();
    span.end();
}

function b() {
    c();
}

function c() {
    d();
}

function d() {
    const span = ....; // What happens here?
    span.end();
}

I’d really like to have the span created in d() be a child of the span created in a(), but without needing to pass that parent span down from a->b->c->d.

Is this possible at all?

And to make things even more complicated, I’d like to be able to do it for async functions as well. Is that possible at all?

I’m somewhat assuming that it is possible, because I’m assuming that the contrib libraries for things like HTTP and pg are doing similar, so that they participate in active spans instead of starting new ones. I’ve not made use of those yet to prove that though, and I’ve not been able to follow the code of the HTTP one to see how it could possibly do that.

Cheers

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cartermpcommented, Sep 10, 2022

Should this issue still be open? This is now documented and by using trace.startActiveSpan you don’t need to do the dance of passing context and/or spans around: https://opentelemetry.io/docs/instrumentation/js/instrumentation/#create-nested-spans

0reactions
cletustboonecommented, Jul 7, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Telemetry - Create span without passing parent ...
I am currently trying to implement custom tracing using telemetry. I am trying to trace the load time of the page load and...
Read more >
Instrumentation | OpenTelemetry
The previous examples showed how to create an active span. In some cases, you'll want to create inactive spans that are siblings of...
Read more >
Span in tracing - Rust
Constructs a new Span as child of the given parent span, with the given metadata and set of field values. After the span...
Read more >
Add span tags and filter and group your application ...
Depending on the programming language you are you using, you'll need to set the tags to add to your spans differently. Note: take...
Read more >
The Content Span element - HTML - MDN Web Docs
The HTML element is a generic inline container for phrasing content, which does not inherently represent anything.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found