opentelemetry-js: Nested Child spans are not getting parented correctly

Please answer these questions before submitting a bug report.

What version of OpenTelemetry are you using? 0.15.0

What version of Node are you using? v14.15.5

Please provide the code you used to setup the OpenTelemetry SDK : https://github.com/mnadeem/nodejs-opentelemetry-tempo

What did you do? Created Child Spans

const doSomeWorkInNewNestedSpan = (parentSpan) => {
    const childSpan = tracer.startSpan('doSomeWorkInNewNestedSpan', {
        parentSpan, attributes: { 'code.function' : 'doSomeWorkInNewNestedSpan' }
    });
    childSpan.setAttribute('code.filepath', "test2");
    //Do some work
    doSomeHeavyWork();
    childSpan.end();
}

If possible, provide a recipe for reproducing the error.: Follow the guidelines in https://github.com/mnadeem/nodejs-opentelemetry-tempo

What did you expect to see? Nested Child spans should be parented correctly

Something like this nested and stair cased (from https://github.com/mnadeem/boot-opentelemetry-tempo)

image

What did you see instead? Nested child spans are not parented correctly

image

Additional context

Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

FWIW I’m a Node.js programmer of 10 years, spent an hour reading this thread and many others + docs, and still cant figure out how to do something as simple (or should be simple) as making a child span link properly to parent.

Using parent option in tracer.startSpan has been removed via #1612 because it was removed from the spec.

It’s needed to use context for this. Either passing it manual like here or using context.with() as shown here.

There might come helpers to ease this (see #1923).

We are discussing/working on a convenience API for this that will make this api.withSpan(span, doSomeWorkInNewNested2Span) which should make this less confusing for new users.

I am also working on a new documentation which should simplify these common use cases.