Skip to content

How to create two sibling child span with the same parent span? #3704

Answered by dmathieu
miknyko asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

No. Context in go is immutable, it cannot be updated.
When you call tracer.Start, two arguments are returned. The first one is the new context, the second one is the new span.
If your third span is created against the same context as your second one, they will both have the same parent.

For example:

ctx, spanA := tracer.Start(context.Background(), "span A")
newCtx, spanB := tracer.Start(ctx, "span B")
yetAnotherCtx, spanC := tracer.Start(ctx, "span B")

In there, the first created span has no parent, since we create a brand new context for it.
The second one has A as a parent, since we use the context from that span.
The third one also has A as a parent, for the same reason.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@miknyko
Comment options

Answer selected by MrAlias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3703 on February 10, 2023 12:53.