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

Create a new linked Span from the current Context #2068

Closed
bogdandrutu opened this issue Jul 5, 2021 · 2 comments · Fixed by #2115
Closed

Create a new linked Span from the current Context #2068

bogdandrutu opened this issue Jul 5, 2021 · 2 comments · Fixed by #2115
Labels
enhancement New feature or request
Milestone

Comments

@bogdandrutu
Copy link
Member

Problem Statement

In a long-living operation (context), I want to start a new Trace that is linked to the long-living operation. An example can be a bidirectional grpc stream where every received message represents a new operation, or a long living consumer operation in a pub-sub solution where every received message is a new operation.

Right now, I had to do something like this (in a grpc case):

	// Since the receiverCtx is long lived do not use it to start the span, just link to it.
	_, span = rec.tracer.Start(context.Background(), spanName, trace.WithLinks(trace.Link{
		SpanContext: trace.SpanContextFromContext(receiverCtx),
	}))

	ctx = trace.ContextWithSpan(receiverCtx, span)

Proposed Solution

	// Since the receiverCtx is long lived do not use it to start the span, just link to it.
	ctx, span = rec.tracer.Start(receiverCtx, spanName, trace.WithParentAsLink(true))

OR:

	// Since the receiverCtx is long lived do not use it to start the span, just link to it.
	ctx, span = rec.tracer.Start(receiverCtx, spanName, trace.WithNoParent(true), trace.WithLinks(trace.Link{
		SpanContext: trace.SpanContextFromContext(receiverCtx),
	})
@bogdandrutu bogdandrutu added the enhancement New feature or request label Jul 5, 2021
@Aneurysm9
Copy link
Member

Does the existing trace.WithNewRoot() option enable the second proposed solution? I think trace.WithParentAsLink(true) is nicer/simpler, but perhaps combining WIthNewRoot and a simpler Link initializer might be more flexible.

@bogdandrutu
Copy link
Member Author

bogdandrutu commented Jul 8, 2021

Thanks for pointing me to a bug :D

#2071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants