Skip to content

Lack of convenient API to start span with a parent context in v2 #3598

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

Open
Gilthoniel opened this issue Jun 6, 2025 · 3 comments
Open

Lack of convenient API to start span with a parent context in v2 #3598

Gilthoniel opened this issue Jun 6, 2025 · 3 comments
Labels
enhancement quick change/addition that does not need full team approval

Comments

@Gilthoniel
Copy link

Tracer Version(s)

v2.0.0

Go Version(s)

go v1.24.3

Bug Report

We used to use the ChildOf option to inject a parent context extracted from a message or an HTTP request but the option is not deprecated in favor of StartChild but we cannot instantiate the parent span from the parent context and we end up doing this:

if parentSpan, _ := tracer.Extract(MessageCarrier{msg}); parentSpan != nil {
	opts = append(opts, tracer.WithStartSpanConfig(&tracer.StartSpanConfig{
		Parent: parentSpan,
	}))
}

But that seems overkill. I can't find a different way so I'm assuming that's not the right approach but then I have no idea what the right one is.

Or a Parent option when starting the span would be possible ?

Reproduction Code

opts := []tracer.StartSpanOption{
	tracer.Tag("messaging.topic", topic),
	tracer.Tag(ext.SpanKind, ext.SpanKindConsumer),
	tracer.SpanType(ext.SpanTypeMessageConsumer),
}

if parentSpan, _ := tracer.Extract(MessageCarrier{msg}); parentSpan != nil {
	opts = append(opts, tracer.WithStartSpanConfig(&tracer.StartSpanConfig{
		Parent: parentSpan,
	}))
}

span, ctx := tracer.StartSpanFromContext(ctx, "queue.consume", opts...)
defer func() {
	span.Finish(tracer.WithError(err))
}()

Error Logs

No response

Go Env Output

No response

@Gilthoniel Gilthoniel added the bug unintended behavior that has to be fixed label Jun 6, 2025
@github-actions github-actions bot added the needs-triage New issues that have not yet been triaged label Jun 6, 2025
@darccio darccio removed the needs-triage New issues that have not yet been triaged label Jun 6, 2025
@darccio
Copy link
Member

darccio commented Jun 6, 2025

@Gilthoniel Thanks for reaching out! ChildOf was deprecated but it's still available. The way you modified your code is correct, but we agree it can bee a bit cumbersome. We'll discuss your case internally to see how can be improve this specific case.

@skunkworker
Copy link

Piggybacking on this issue. The docs here https://github.com/DataDog/dd-trace-go/blob/main/ddtrace/tracer/doc.go. Outline continuing remote traces (without creating a new parent trace). But do not give a v2 replacement.

// Then, on the server side, to continue the trace one would do:
//
//	sctx, err := tracer.Extract(tracer.HTTPHeadersCarrier(req.Header))
//	// ...
//	span := tracer.StartSpan("child.span", tracer.ChildOf(sctx))

Is the method above the only way to "continue" a trace from a given spancontext parent?

@darccio darccio added enhancement quick change/addition that does not need full team approval and removed bug unintended behavior that has to be fixed labels Jun 10, 2025
@darccio darccio changed the title [BUG]: cannot start span with a parent context anymore in v2 Lack of convenient API to start span with a parent context in v2 Jun 10, 2025
@darccio
Copy link
Member

darccio commented Jun 11, 2025

@skunkworker You are right. Keep in mind that ChildOf is still available although marked as deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement quick change/addition that does not need full team approval
Projects
None yet
Development

No branches or pull requests

3 participants