DataDog / datadog-lambda-go

The Datadog AWS Lambda package for Go
Apache License 2.0
59 stars 40 forks source link

Unable to set the parent span for new child spans #78

Closed speza closed 3 years ago

speza commented 3 years ago

I'm using the below code in an attempt to trace individual SQS messages and add them to the parent span the other service that sent them.

I have confirmed that metadata contains both x-datadog-parent-id and x-datadog-trace-id in the format that the tracer.TextMapCarrier requires.

The traces are coming through ok but the issue is that by the time the traces are sent through the Datadog Lambda Forwarder the parent is set to the span started for the root of the Lambda execution (in listener.go#startFunctionExecutionSpan) instead of the that has been extracted.

opts := []ddtrace.StartSpanOption{
    tracer.ResourceName("eventHandler"),
}
if parentTraceCtx, err := tracer.Extract(tracer.TextMapCarrier(metadata)); err == nil {
    opts = append(opts, tracer.ChildOf(parentTraceCtx))
}

tracer.StartSpanFromContext(ctx, "Process", opts...)

Is there a limitation that I am perhaps misunderstanding when trying to set the parent span to something other than the Lambda execution span?

Steps to Reproduce the Problem

See above code snippet.

Specifications

Stacktrace

N/A