Expected Behavior
Execute DataDog Synthetic Test and see trace linked to the executed request.
Actual Behavior
Traces are not linked.
Steps to Reproduce the Problem
In our case the headers are not passed via headers, but multiValueHeaders:
"multiValueHeaders": {
"x-datadog-origin": [
"synthetics"
],
"x-datadog-parent-id": [
"0"
],
"x-datadog-sampling-priority": [
"1"
],
"x-datadog-trace-id": [
"1775877486757059156"
],
}
|
func getHeadersFromEventHeaders(ctx context.Context, ev json.RawMessage) map[string]string { |
It is possible to set a custom TraceContextExtractor in the config, but would be nice to have this supported out of the box.
// lambda.Start(ddlambda.WrapFunction(proxiedHandler, &ddlambda.Config{
// DDTraceEnabled: true,
// DebugLogging: false,
// TraceContextExtractor: getHeadersFromEventHeaders,
// }))
type eventWithHeaders struct {
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
}
func getHeadersFromEventHeaders(ctx context.Context, ev json.RawMessage) map[string]string {
eh := eventWithHeaders{}
headers := map[string]string{}
err := json.Unmarshal(ev, &eh)
if err != nil {
return headers
}
lowercaseHeaders := map[string]string{}
for k, v := range eh.MultiValueHeaders {
if len(v) > 0 {
lowercaseHeaders[strings.ToLower(k)] = v[0]
}
}
return lowercaseHeaders
}
Additionally we had to patch getTraceContext to include x-datadog-origin:
|
func getTraceContext(ctx context.Context, headers map[string]string) (TraceContext, bool) { |
tc[samplingPriorityHeader] = samplingPriority
tc[traceIDHeader] = traceID
tc[parentIDHeader] = parentID
if origin, ok := headers["x-datadog-origin"]; ok {
tc["x-datadog-origin"] = origin
}
return tc, true
Otherwise it is missing for the check in extractTextMap (no origin, thus ErrSpanContextNotFound):
https://github.com/DataDog/dd-trace-go/blob/fb51babc4beed2e0037c41df97848313e7e43af3/ddtrace/tracer/textmap.go#L557
Specifications
- Datadog Go Lambda package version: 1.20.0
- Go version: 1.24.0
Expected Behavior
Execute DataDog Synthetic Test and see trace linked to the executed request.
Actual Behavior
Traces are not linked.
Steps to Reproduce the Problem
In our case the headers are not passed via
headers, butmultiValueHeaders:datadog-lambda-go/internal/trace/context.go
Line 173 in 82f6bee
It is possible to set a custom
TraceContextExtractorin the config, but would be nice to have this supported out of the box.Additionally we had to patch
getTraceContextto includex-datadog-origin:datadog-lambda-go/internal/trace/context.go
Line 130 in 82f6bee
Otherwise it is missing for the check in
extractTextMap(no origin, thusErrSpanContextNotFound):https://github.com/DataDog/dd-trace-go/blob/fb51babc4beed2e0037c41df97848313e7e43af3/ddtrace/tracer/textmap.go#L557
Specifications