-
Notifications
You must be signed in to change notification settings - Fork 45
[Tracing] Adds SQS and LambdaContext Trace extraction #105
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
[Tracing] Adds SQS and LambdaContext Trace extraction #105
Conversation
…-client-context * main: master-main (#103)
datadog_lambda/tracing.py
Outdated
parent_id = lowercase_headers.get(TraceHeader.PARENT_ID) | ||
sampling_priority = lowercase_headers.get(TraceHeader.SAMPLING_PRIORITY) | ||
if "headers" in event: | ||
trace_id, parent_id, sampling_priority = extract_context_from_http_event(event) |
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.
cc: @DylanLovesCoffee I recall you are touching this function as well, and I actually suggested code changes like what @Czechh does 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.
datadog_lambda/tracing.py
Outdated
return trace_id, parent_id, sampling_priority | ||
|
||
|
||
def extract_context_from_sqs_event(event): |
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.
If not hard, does it make sense to add an integration test?
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.
Modified the SQS object to inject trace data ✅
datadog_lambda/tracing.py
Outdated
if "headers" in event: | ||
trace_id, parent_id, sampling_priority = extract_context_from_http_event(event) | ||
elif "Records" in event: | ||
trace_id, parent_id, sampling_priority = extract_context_from_sqs_event(event) |
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.
If "Records" is in the event, but we fail to parse, we should probably try extracting from the lambda context next.
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.
Use the lambda context as a fallback for both headers
and SQS
events
datadog_lambda/tracing.py
Outdated
|
||
|
||
def extract_context_from_lambda_context(lambda_context): | ||
dd_data = lambda_context.client_context.get("custom", {}).get("_datadog", {}) |
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.
Interesting, didn't realize it was possible for some services to add metadata to the context.
END RequestId: XXXX | ||
REPORT RequestId: XXXX Duration: XXXX ms Billed Duration: XXXX ms Memory Size: 1024 MB Max Memory Used: XXXX MB | ||
XRAY TraceId: XXXX SegmentId: XXXX Sampled: true | ||
START RequestId: XXXX Version: $LATEST | ||
{"e": XXXX, "m": "aws.lambda.enhanced.invocations", "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-plugin-dev-async-metrics_python27_with_plugin", "resource:integration-plugin-dev-async-metrics_python27_with_plugin", "cold_start:false", "memorysize:1024", "runtime:python2.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1} | ||
{"e": XXXX, "m": "hello.dog", "t": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1} | ||
{"e": XXXX, "m": "tests.integration.count", "t": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 21} | ||
{"traces": [[{"resource": "integration-plugin-dev-async-metrics_python27_with_plugin", "name": "aws.lambda", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_sampling_priority_v1": 2, "system.pid": XXXX}, "parent_id": "XXXX", "meta": {"runtime-id": "XXXX", "request_id": "XXXX", "cold_start": "false", "datadog_lambda": "2.24.0", "function_arn": "arn:aws:lambda:us-east-1:601427279990:function:integration-plugin-dev-async-metrics_python27_with_plugin", "dd_trace": "0.44.0", "_dd.origin": "lambda", "_dd.parent_source": "xray", "resource_names": "integration-plugin-dev-async-metrics_python27_with_plugin", "function_version": "$LATEST"}, "error": 0, "duration": XXXX, "type": "serverless", "span_id": "XXXX"}]]} | ||
{"traces": [[{"resource": "integration-plugin-dev-async-metrics_python27_with_plugin", "name": "aws.lambda", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_sampling_priority_v1": 1, "system.pid": XXXX}, "parent_id": "XXXX", "meta": {"runtime-id": "XXXX", "request_id": "XXXX", "cold_start": "false", "datadog_lambda": "X.X.X", "function_arn": "arn:aws:lambda:us-east-1:601427279990:function:integration-plugin-dev-async-metrics_python27_with_plugin", "dd_trace": "X.X.X", "_dd.origin": "lambda", "resource_names": "integration-plugin-dev-async-metrics_python27_with_plugin", "function_version": "$LATEST"}, "error": 0, "duration": XXXX, "type": "serverless", "span_id": "XXXX"}]]} |
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.
"_dd.parent_source": "xray"
is gone because I added to the SQS input event some trace data :)
…-client-context * main: Update contributing doc (#106)
What does this PR do?
Following the
dd-trace-py
0.45.0 release this PR adds support for extracting the trace data fromSQS
and the LambdaContext
objectMotivation
Testing Guidelines
Additional Notes
Types of Changes
Check all that apply