Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2f051a6
add trigger event span tags
DylanLovesCoffee Dec 8, 2020
d6fbf3e
add tests and sample events
DylanLovesCoffee Dec 8, 2020
ce92c3f
Merge branch 'master' into dylan/trigger-tags
DylanLovesCoffee Dec 8, 2020
64fb4ec
update snapshots
DylanLovesCoffee Dec 8, 2020
080f007
lint
DylanLovesCoffee Dec 8, 2020
1d611c0
implement feedback
DylanLovesCoffee Dec 10, 2020
d83ee4e
refactor adding tags
DylanLovesCoffee Dec 11, 2020
b840c3d
black
DylanLovesCoffee Dec 11, 2020
d731561
include alb for http tags
DylanLovesCoffee Dec 14, 2020
15c4610
add s3 test
DylanLovesCoffee Dec 17, 2020
ec51ccd
nits and add CN and Gov arn regions
DylanLovesCoffee Dec 22, 2020
f275936
always add trigger tags to xray subseg
DylanLovesCoffee Dec 22, 2020
9cfaedc
implement feedback
DylanLovesCoffee Dec 24, 2020
1965908
handle Lambda response status code
DylanLovesCoffee Dec 28, 2020
e680aff
renaming for specificity
DylanLovesCoffee Dec 28, 2020
c0bc254
carry response status_code to xray
DylanLovesCoffee Jan 4, 2021
eaa952d
cleanup
DylanLovesCoffee Jan 4, 2021
195a6aa
fix merge conflicts
DylanLovesCoffee Jan 7, 2021
369bdfc
add xray dummy subsegment for trigger tags at end of invocation
DylanLovesCoffee Jan 8, 2021
79140cf
rename trigger tag and update snapshots
DylanLovesCoffee Jan 20, 2021
a02c289
lint EOF extra line
DylanLovesCoffee Jan 20, 2021
a9bbf0c
update with feedback
DylanLovesCoffee Jan 21, 2021
5375952
Merge branch 'main' into dylan/trigger-tags
DylanLovesCoffee Jan 21, 2021
0e71a7e
update snapshots
DylanLovesCoffee Jan 21, 2021
20b4945
fix
DylanLovesCoffee Jan 21, 2021
3190475
fix my fix
DylanLovesCoffee Jan 21, 2021
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
Prev Previous commit
Next Next commit
always add trigger tags to xray subseg
  • Loading branch information
DylanLovesCoffee committed Dec 22, 2020
commit f2759361c6ba71243c9dcdfebf6838e4c72eb4b9
24 changes: 16 additions & 8 deletions datadog_lambda/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _context_obj_to_headers(obj):
}


def create_dd_metadata_subsegment(dd_context, trigger_tags):
def create_dd_metadata_subsegment(dd_context):
"""
Save the context to an X-Ray subsegment's metadata field, so the X-Ray
trace can be converted to a Datadog trace in the Datadog backend with
Expand All @@ -100,13 +100,21 @@ def create_dd_metadata_subsegment(dd_context, trigger_tags):
subsegment.put_metadata(
XraySubsegment.TRACE_KEY, dd_context, XraySubsegment.NAMESPACE
)
# Add trigger tags under the dd subsegment's root_span_metadata field
if trigger_tags:
subsegment.put_metadata(
XraySubsegment.ROOT_SPAN_METADATA_KEY,
trigger_tags,
XraySubsegment.NAMESPACE,
)
xray_recorder.end_subsegment()


def create_dd_root_span_metadata_subsegment(lambda_function_tags):
"""
Store tags to an X-Ray subsegment's metadata field to be added to the Lambda
function execution span
"""
xray_recorder.begin_subsegment(XraySubsegment.NAME)
subsegment = xray_recorder.current_subsegment()
subsegment.put_metadata(
XraySubsegment.ROOT_SPAN_METADATA_KEY,
lambda_function_tags,
XraySubsegment.NAMESPACE,
)
xray_recorder.end_subsegment()


Expand Down
7 changes: 5 additions & 2 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from datadog_lambda.tracing import (
extract_dd_trace_context,
create_dd_metadata_subsegment,
create_dd_root_span_metadata_subsegment,
inject_correlation_ids,
dd_tracing_enabled,
set_correlation_ids,
Expand Down Expand Up @@ -123,12 +124,14 @@ def _before(self, event, context):

set_cold_start()
submit_invocations_metric(context)
# Extract trigger tags
# Extract trigger tags and add them to a subsegment if found
trigger_tags = extract_trigger_tags(event, context)
if trigger_tags:
create_dd_root_span_metadata_subsegment(trigger_tags)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, just a reminder, i recall you would have to duplicate the root span tags to the aws.lambda.function span as well, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct 👍

# Extract Datadog trace context and source from incoming requests
dd_context, trace_context_source = extract_dd_trace_context(event)
if trace_context_source == TraceContextSource.EVENT:
create_dd_metadata_subsegment(dd_context, trigger_tags)
create_dd_metadata_subsegment(dd_context)

self.span = None
if dd_tracing_enabled:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
START RequestId: XXXX Version: $LATEST
{"e": XXXX, "m": "aws.lambda.enhanced.invocations", "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-dev-async-metrics_python27", "resource:integration-dev-async-metrics_python27", "cold_start:true", "memorysize:1024", "runtime:python2.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
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:true", "memorysize:1024", "runtime:python2.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
START RequestId: XXXX Version: $LATEST
{"m": "aws.lambda.enhanced.invocations", "v": 1, "e": XXXX, "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-dev-async-metrics_python36", "resource:integration-dev-async-metrics_python36", "cold_start:true", "memorysize:1024", "runtime:python3.6", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python36_2.XX.0"]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
START RequestId: XXXX Version: $LATEST
{"m": "aws.lambda.enhanced.invocations", "v": 1, "e": XXXX, "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-plugin-dev-async-metrics_python36_with_plugin", "resource:integration-plugin-dev-async-metrics_python36_with_plugin", "cold_start:true", "memorysize:1024", "runtime:python3.6", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python36_2.XX.0"]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
START RequestId: XXXX Version: $LATEST
{"m": "aws.lambda.enhanced.invocations", "v": 1, "e": XXXX, "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-dev-async-metrics_python37", "resource:integration-dev-async-metrics_python37", "cold_start:true", "memorysize:1024", "runtime:python3.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python37_2.XX.0"]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
START RequestId: XXXX Version: $LATEST
{"m": "aws.lambda.enhanced.invocations", "v": 1, "e": XXXX, "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-plugin-dev-async-metrics_python37_with_plugin", "resource:integration-plugin-dev-async-metrics_python37_with_plugin", "cold_start:true", "memorysize:1024", "runtime:python3.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python37_2.XX.0"]}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/snapshots/logs/http-error_python27.log
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!
RequestsDependencyWarning)
START RequestId: XXXX Version: $LATEST
{"e": XXXX, "m": "aws.lambda.enhanced.invocations", "t": ["region:us-east-1", "account_id:XXXX", "functionname:integration-dev-http-error_python27", "resource:integration-dev-http-error_python27", "cold_start:true", "memorysize:1024", "runtime:python2.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1}
HTTP GET https://httpstat.us/400/ Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "User-Agent:python-requests/2.25.0", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {}
HTTP GET https://httpstat.us/400/ Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "User-Agent:python-requests/2.25.1", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {}
HTTP POST https://api.datadoghq.com/api/v1/distribution_points?api_key=XXXX Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "Content-Length:460", "Content-Type:application/json", "User-Agent:datadogpy/0.39.0 (python 2.7.18; os linux; arch x86_64)", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {"series": [{"tags": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "metric": "hello.dog", "interval": 10, "host": null, "points": [[XXXX, [1.0]]], "device": null, "type": "distribution"}, {"tags": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "metric": "tests.integration.count", "interval": 10, "host": null, "points": [[XXXX, [21.0]]], "device": null, "type": "distribution"}]}
{"traces": [[{"resource": "integration-dev-http-error_python27", "name": "aws.lambda", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_sampling_priority_v1": 1, "system.pid": XXXX, "_dd.agent_psr": 1.0}, "parent_id": "XXXX", "meta": {"trigger.event_source": "api-gateway", "trigger.event_source_arn": "arn:aws:apigateway:us-east-1::/restapis/wt6mne2s9k/stages/test", "http.method": "GET", "runtime-id": "XXXX", "request_id": "XXXX", "cold_start": "true", "datadog_lambda": "2.26.0", "function_arn": "arn:aws:lambda:us-east-1:601427279990:function:integration-dev-http-error_python27", "dd_trace": "0.44.0", "_dd.origin": "lambda", "resource_names": "integration-dev-http-error_python27", "http.status_code": "200", "function_version": "$LATEST"}, "error": 0, "duration": XXXX, "type": "serverless", "span_id": "XXXX"}, {"resource": "requests.request", "name": "requests.request", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_dd.measured": 1}, "parent_id": "XXXX", "meta": {"http.status_code": "400", "http.url": "https://httpstat.us/400/", "_dd.origin": "lambda", "http.method": "GET"}, "error": 0, "duration": XXXX, "type": "http", "span_id": "XXXX"}, {"resource": "requests.request", "name": "requests.request", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_dd.measured": 1}, "parent_id": "XXXX", "meta": {"http.status_code": "202", "http.url": "https://api.datadoghq.com/api/v1/distribution_points", "_dd.origin": "lambda", "http.method": "POST"}, "error": 0, "duration": XXXX, "type": "http", "span_id": "XXXX"}]]}
END RequestId: XXXX
REPORT RequestId: XXXX Duration: XXXX ms Billed Duration: XXXX ms Memory Size: 1024 MB Max Memory Used: XXXX MB Init Duration: XXXX ms
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-dev-http-error_python27", "resource:integration-dev-http-error_python27", "cold_start:false", "memorysize:1024", "runtime:python2.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1}
HTTP GET https://httpstat.us/400/ Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "User-Agent:python-requests/2.25.0", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {}
HTTP GET https://httpstat.us/400/ Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "User-Agent:python-requests/2.25.1", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {}
HTTP POST https://api.datadoghq.com/api/v1/distribution_points?api_key=XXXX Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "Content-Length:460", "Content-Type:application/json", "User-Agent:datadogpy/0.39.0 (python 2.7.18; os linux; arch x86_64)", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {"series": [{"tags": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "metric": "hello.dog", "interval": 10, "host": null, "points": [[XXXX, [1.0]]], "device": null, "type": "distribution"}, {"tags": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "metric": "tests.integration.count", "interval": 10, "host": null, "points": [[XXXX, [21.0]]], "device": null, "type": "distribution"}]}
{"traces": [[{"resource": "integration-dev-http-error_python27", "name": "aws.lambda", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_sampling_priority_v1": 1, "system.pid": XXXX, "_dd.agent_psr": 1.0}, "parent_id": "XXXX", "meta": {"trigger.event_source": "sns", "trigger.event_source_arn": "arn:aws:sns:us-east-2:123456789012:sns-lambda", "runtime-id": "XXXX", "request_id": "XXXX", "cold_start": "false", "datadog_lambda": "2.26.0", "function_arn": "arn:aws:lambda:us-east-1:601427279990:function:integration-dev-http-error_python27", "dd_trace": "0.44.0", "_dd.origin": "lambda", "resource_names": "integration-dev-http-error_python27", "function_version": "$LATEST"}, "error": 0, "duration": XXXX, "type": "serverless", "span_id": "XXXX"}, {"resource": "requests.request", "name": "requests.request", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_dd.measured": 1}, "parent_id": "XXXX", "meta": {"http.status_code": "400", "http.url": "https://httpstat.us/400/", "_dd.origin": "lambda", "http.method": "GET"}, "error": 0, "duration": XXXX, "type": "http", "span_id": "XXXX"}, {"resource": "requests.request", "name": "requests.request", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_dd.measured": 1}, "parent_id": "XXXX", "meta": {"http.status_code": "202", "http.url": "https://api.datadoghq.com/api/v1/distribution_points", "_dd.origin": "lambda", "http.method": "POST"}, "error": 0, "duration": XXXX, "type": "http", "span_id": "XXXX"}]]}
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-dev-http-error_python27", "resource:integration-dev-http-error_python27", "cold_start:false", "memorysize:1024", "runtime:python2.7", "datadog_lambda:vXX", "dd_lambda_layer:datadog-python27_2.XX.0"], "v": 1}
HTTP GET https://httpstat.us/400/ Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "User-Agent:python-requests/2.25.0", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {}
HTTP GET https://httpstat.us/400/ Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "User-Agent:python-requests/2.25.1", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {}
HTTP POST https://api.datadoghq.com/api/v1/distribution_points?api_key=XXXX Headers: ["Accept-Encoding:gzip, deflate", "Accept:*/*", "Connection:keep-alive", "Content-Length:460", "Content-Type:application/json", "User-Agent:datadogpy/0.39.0 (python 2.7.18; os linux; arch x86_64)", "x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:1", "x-datadog-trace-id:XXXX"] Data: {"series": [{"tags": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "metric": "hello.dog", "interval": 10, "host": null, "points": [[XXXX, [1.0]]], "device": null, "type": "distribution"}, {"tags": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.XX.0"], "metric": "tests.integration.count", "interval": 10, "host": null, "points": [[XXXX, [21.0]]], "device": null, "type": "distribution"}]}
{"traces": [[{"resource": "integration-dev-http-error_python27", "name": "aws.lambda", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_sampling_priority_v1": 1, "system.pid": XXXX, "_dd.agent_psr": 1.0}, "parent_id": "XXXX", "meta": {"trigger.event_source": "sqs", "trigger.event_source_arn": "arn:aws:sqs:us-east-2:123456789012:my-queue", "runtime-id": "XXXX", "request_id": "XXXX", "cold_start": "false", "datadog_lambda": "2.26.0", "function_arn": "arn:aws:lambda:us-east-1:601427279990:function:integration-dev-http-error_python27", "dd_trace": "0.44.0", "_dd.origin": "lambda", "resource_names": "integration-dev-http-error_python27", "function_version": "$LATEST"}, "error": 0, "duration": XXXX, "type": "serverless", "span_id": "XXXX"}, {"resource": "requests.request", "name": "requests.request", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_dd.measured": 1}, "parent_id": "XXXX", "meta": {"http.status_code": "400", "http.url": "https://httpstat.us/400/", "_dd.origin": "lambda", "http.method": "GET"}, "error": 0, "duration": XXXX, "type": "http", "span_id": "XXXX"}, {"resource": "requests.request", "name": "requests.request", "service": "aws.lambda", "start": XXXX, "trace_id": "XXXX", "metrics": {"_dd.measured": 1}, "parent_id": "XXXX", "meta": {"http.status_code": "202", "http.url": "https://api.datadoghq.com/api/v1/distribution_points", "_dd.origin": "lambda", "http.method": "POST"}, "error": 0, "duration": XXXX, "type": "http", "span_id": "XXXX"}]]}
END RequestId: XXXX
Expand Down
Loading