-
Notifications
You must be signed in to change notification settings - Fork 36
Fix incorrect parent id for the aws.lambda span #166
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
Conversation
8ef2935
to
ca0d0ad
Compare
Codecov Report
@@ Coverage Diff @@
## main #166 +/- ##
==========================================
- Coverage 86.73% 86.53% -0.21%
==========================================
Files 31 31
Lines 1184 1203 +19
Branches 235 236 +1
==========================================
+ Hits 1027 1041 +14
- Misses 102 106 +4
- Partials 55 56 +1
Continue to review full report at Codecov.
|
@@ -1,4 +1,3 @@ | |||
XXXX-XX-XX XX:XX:XX.XXX XXXX-XXXX-XXXX-XXXX-XXXX INFO Snapshot test http requests successfully made to URLs: https://ip-ranges.datadoghq.com,https://ip-ranges.datadoghq.eu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing with the logs below, I don't think this line should be there. Probably missed from previous integration test updates.
XXXX-XX-XX XX:XX:XX.XXX XXXX-XXXX-XXXX-XXXX-XXXX INFO [dd.trace_id=XXXX dd.span_id=XXXX] Processed SNS request | ||
{"traces":[[{"trace_id":"XXXX","span_id":"XXXX","parent_id":"XXXX","name":"aws.lambda","resource":"integration-plugin-dev-async-metrics_node12_with_plugin","error":0,"meta":{"_dd.origin":"lambda","service":"integration-plugin-dev-async-metrics_node12_with_plugin","cold_start":"false","function_arn":"XXXX_node12_with_plugin","function_version":"$LATEST","request_id":"XXXX","resource_names":"integration-plugin-dev-async-metrics_node12_with_plugin","datadog_lambda":"XXXX","dd_trace":"XXXX","_dd.parent_source":"xray","function_trigger.event_source":"sns","function_trigger.event_source_arn":"arn:aws:sns:us-east-2:123456789012:sns-lambda"},"metrics":{"_sample_rate":1,"_sampling_priority_v1":2},"start":XXXX,"duration":XXXX,"service":"aws.lambda","type":"serverless"}]]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the new version of tracer logs the traces a little bit later than the previous version, not sure, but probably doesn't hurt.
|
||
// Get the trace headers from the root trace context. | ||
get rootTraceHeaders(): Partial<TraceHeaders> { | ||
const rootTraceContext = this.rootTraceContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we set the root trace context to being the incoming Datadog trace headers. However, when hybrid tracing is enabled, we want to use the PARENT ID from X-Ray but the TRACE ID from Datadog. Is that accounted for here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the relevant logic in Go: https://github.com/DataDog/datadog-lambda-go/blob/main/internal/trace/context.go#L45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the root trace context is derived from X-Ray when there is not incoming Datadog trace headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Nick is right about the desired behaviour. Otherwise the parent on the root span swaps between the incoming datadog span, (when it's available), and the root x-ray segment. This was an existing issue, so we don't have to fix it with this PR, but I think we would change the logic here: https://github.com/DataDog/datadog-lambda-js/blob/main/src/trace/context.ts#L88
, to set the parentId to the x-ray when merge x-ray traces is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Nick's comment is a potential issue we should fix, but I don't think we have to do it in this PR.
What does this PR do?
The
currentTraceHeaders
method callscurrentTraceContext
, which always return the current trace context. This method is good for getting the trace headers for the injection to downstream calls, because it always sets the parent id to the currently active Datadog span or X-Ray segment. However, it shouldn't be used to determine the parent of theaws.lambda
span, because it doesn't matter if the user creates a custom span or segment. Theaws.lambda
span should always be parented to the root trace context, i.e., the parent span should either be from the incoming trace context or the X-Ray root segment.Perhaps this wasn't an issue before, because
getXraySegment
doesn't return anything unless X-Ray active tracing is enabled, but it now always return a segment? But it doesn't matter anymore,getXraySegment
shouldn't be called when determining the parent of theaws.lambda
span anyway.To fix the issue,
rootTraceHeaders
was added toTraceContextService
and it always return the trace headers from the root trace context. When determining theaws.lambda
span's parent inlistener.js
, callrootTraceHeaders
instead ofcurrentTraceHeaders
.Other changes included:
dd-trace
to0.31.0
version to allow the Datadog trace context propagate through AWS SDKlambda.invoke()
.Motivation
When the incoming Lambda event object or context object contains a Datadog trace context, the automatically generated
aws.lambda
span should be parented to it. However, it currently parents the span to the X-Ray segment instead, even when X-Ray active tracing is not enabled. This results theaws.lambda
span being an orphan (parent id points to a non-existent span).Testing Guidelines
Additional Notes
Types of Changes
Check all that apply