-
Notifications
You must be signed in to change notification settings - Fork 45
Explicit trace ID propagation for SFN #526
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7c127a3
add logic to extract traceID from _datadog header
avedmala 8658dea
rename test
avedmala 3eccb20
fix type
avedmala 97b189a
added root arn case
avedmala eaa09f3
trigger ci
avedmala 2baec69
Add `http.route` tags for API Gateway (#524)
nhulston 3c4014b
feat: [SVLS-5677] DynamoDB Stream event span pointers (#522)
apiarian-datadog 6f54a00
trigger ci
avedmala 4e0afdb
Merge remote-tracking branch 'origin/main' into avedmala/sfn-span-link
avedmala 25780a8
use default propagator.extract
avedmala 85a157f
lint
avedmala aad3cd8
lint
avedmala c3681de
updated to use trace/parent hash from _datadog
avedmala 7d1d475
lint
avedmala e9a7d46
skip is context complete check
avedmala a6464b4
remove unused import
avedmala 068c2fc
fix legacy lambda parsing with new header
avedmala 6105b21
Merge branch 'main' into avedmala/sfn-span-link
avedmala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
TraceContextSource, | ||
XrayDaemon, | ||
Headers, | ||
TraceHeader, | ||
) | ||
from datadog_lambda.xray import ( | ||
send_segment, | ||
|
@@ -380,10 +381,33 @@ def extract_context_from_step_functions(event, lambda_context): | |
execution_id = event.get("Execution").get("Id") | ||
state_name = event.get("State").get("Name") | ||
state_entered_time = event.get("State").get("EnteredTime") | ||
# returning 128 bits since 128bit traceId will be break up into | ||
# traditional traceId and _dd.p.tid tag | ||
# https://github.com/DataDog/dd-trace-py/blob/3e34d21cb9b5e1916e549047158cb119317b96ab/ddtrace/propagation/http.py#L232-L240 | ||
trace_id = _deterministic_sha256_hash(execution_id, LOWER_64_BITS) | ||
meta = {} | ||
|
||
if "_datadog" in event: | ||
trace_header = event.get("_datadog") | ||
if TraceHeader.TRACE_ID in trace_header: | ||
# use the trace ID from the top-most parent when it exists | ||
trace_id = int(trace_header.get(TraceHeader.TRACE_ID)) | ||
tags = trace_header.get(TraceHeader.TAGS, "") | ||
for tag in tags.split(","): | ||
tag_key, tag_val = tag.split("=") | ||
meta[tag_key] = tag_val | ||
elif "x-datadog-execution-arn" in trace_header: | ||
root_execution_id = trace_header.get("x-datadog-execution-arn") | ||
trace_id = _deterministic_sha256_hash(root_execution_id, LOWER_64_BITS) | ||
meta["_dd.p.tid"] = hex( | ||
_deterministic_sha256_hash(root_execution_id, HIGHER_64_BITS) | ||
)[2:] | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole branch should be the old behavior |
||
# returning 128 bits since 128bit traceId will be break up into | ||
# traditional traceId and _dd.p.tid tag | ||
# https://github.com/DataDog/dd-trace-py/blob/3e34d21cb9b5e1916e549047158cb119317b96ab/ddtrace/propagation/http.py#L232-L240 | ||
trace_id = _deterministic_sha256_hash(execution_id, LOWER_64_BITS) | ||
# take the higher 64 bits as _dd.p.tid tag and use hex to encode | ||
# [2:] to remove '0x' in the hex str | ||
meta["_dd.p.tid"] = hex( | ||
_deterministic_sha256_hash(execution_id, HIGHER_64_BITS) | ||
)[2:] | ||
|
||
parent_id = _deterministic_sha256_hash( | ||
f"{execution_id}#{state_name}#{state_entered_time}", HIGHER_64_BITS | ||
|
@@ -394,13 +418,7 @@ def extract_context_from_step_functions(event, lambda_context): | |
trace_id=trace_id, | ||
span_id=parent_id, | ||
sampling_priority=sampling_priority, | ||
# take the higher 64 bits as _dd.p.tid tag and use hex to encode | ||
# [2:] to remove '0x' in the hex str | ||
meta={ | ||
"_dd.p.tid": hex( | ||
_deterministic_sha256_hash(execution_id, HIGHER_64_BITS) | ||
)[2:] | ||
}, | ||
meta=meta, | ||
) | ||
except Exception as e: | ||
logger.debug("The Step Functions trace extractor returned with error %s", e) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.