[Tracing] Adds SQS and LambdaContext Trace extraction#105
Conversation
…-client-context * main: master-main (#103)
| 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.
cc: @DylanLovesCoffee I recall you are touching this function as well, and I actually suggested code changes like what @Czechh does here.
| return trace_id, parent_id, sampling_priority | ||
|
|
||
|
|
||
| def extract_context_from_sqs_event(event): |
There was a problem hiding this comment.
If not hard, does it make sense to add an integration test?
There was a problem hiding this comment.
Modified the SQS object to inject trace data ✅
| 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.
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.
Use the lambda context as a fallback for both headers and SQS events
|
|
||
|
|
||
| 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.
Interesting, didn't realize it was possible for some services to add metadata to the context.
| {"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.
"_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-py0.45.0 release this PR adds support for extracting the trace data fromSQSand the LambdaContextobjectMotivation
Testing Guidelines
Additional Notes
Types of Changes
Check all that apply