Skip to content

Commit 8b5ed4e

Browse files
Refactoring change to use extract_context_from_http_event_or_context
1 parent d513e9e commit 8b5ed4e

21 files changed

+2884
-111
lines changed

datadog_lambda/tracing.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -537,25 +537,6 @@ def extract_context_from_step_functions(event, lambda_context):
537537
return extract_context_from_lambda_context(lambda_context)
538538

539539

540-
def extract_context_from_request_header(event, lambda_context):
541-
"""
542-
Attempt to extract Datadog trace context from an event payload where Datadog information
543-
is under the event["request"]["header"] section. Intended to replace some of the
544-
need for customers to provide custom extractor functions in their code for workflows such as
545-
RUM -> AppSync -> Lambda.
546-
"""
547-
try:
548-
nested_json = event.get("request").get("headers")
549-
context = propagator.extract(nested_json)
550-
551-
if not _is_context_complete(context):
552-
context = extract_context_from_lambda_context(lambda_context)
553-
except Exception:
554-
context = extract_context_from_lambda_context(lambda_context)
555-
556-
return context
557-
558-
559540
def extract_context_custom_extractor(extractor, event, lambda_context):
560541
"""
561542
Extract Datadog trace context using a custom trace extractor function
@@ -646,6 +627,14 @@ def extract_dd_trace_context(
646627

647628
if extractor is not None:
648629
context = extract_context_custom_extractor(extractor, event, lambda_context)
630+
elif isinstance(event, (set, dict)) and "request" in event:
631+
if "headers" in event.get("request"):
632+
context = extract_context_from_http_event_or_context(
633+
event.get("request"),
634+
lambda_context,
635+
event_source,
636+
decode_authorizer_context=False,
637+
)
649638
elif isinstance(event, (set, dict)) and "headers" in event:
650639
context = extract_context_from_http_event_or_context(
651640
event, lambda_context, event_source, decode_authorizer_context
@@ -661,7 +650,7 @@ def extract_dd_trace_context(
661650
elif event_source.equals(EventTypes.STEPFUNCTIONS):
662651
context = extract_context_from_step_functions(event, lambda_context)
663652
else:
664-
context = extract_context_from_request_header(event, lambda_context)
653+
context = extract_context_from_lambda_context(lambda_context)
665654

666655
if _is_context_complete(context):
667656
logger.debug("Extracted Datadog trace context from event or context")

publish_test_layer.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
REGION=us-east-1 PYTHON_VERSION=$PYTHON_VERSION ARCH=$ARCH ./scripts/build_layers.sh
2+
3+
LAYER_NAME="Python${PYTHON_VERSION/3./3}-RITHIKA"
4+
LAYER_ZIP=".layers/datadog_lambda_py-${ARCH}-${PYTHON_VERSION}.zip"
5+
REGION="us-east-1"
6+
7+
echo "zipping package files"
8+
PYTHON_VERSION=$PYTHON_VERSION ARCH=$ARCH ./scripts/build_layers.sh
9+
10+
echo "publishing layer"
11+
12+
layer_arn=$(
13+
aws-vault exec sso-serverless-sandbox-account-admin -- \
14+
aws lambda publish-layer-version --layer-name $LAYER_NAME \
15+
--description "Datadog Tracer Lambda Layer for Python" \
16+
--zip-file "fileb://$LAYER_ZIP" \
17+
--region "$REGION" \
18+
--output json \
19+
| jq -r '.LayerVersionArn')
20+
21+
echo "new python layer published $layer_arn"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"identity": "None",
3+
"info": {
4+
"fieldName": "getItems",
5+
"parentTypeName": "Query",
6+
"selectionSetGraphQL": "{\n id\n}",
7+
"selectionSetList":["id"]
8+
},
9+
"prev": "None",
10+
"request": {
11+
"domainName": "None",
12+
"headers": {
13+
"accept": "*/*",
14+
"accept-encoding": "gzip, deflate, br, zstd",
15+
"accept-language": "en-US,en;q=0.9",
16+
"cloudfront-forwarded-proto": "https",
17+
"cloudfront-is-desktop-viewer": "True",
18+
"cloudfront-is-mobile-viewer": "False",
19+
"cloudfront-is-smarttv-viewer":"False",
20+
"cloudfront-is-tablet-viewer":" False",
21+
"cloudfront-viewer-asn": "6461",
22+
"cloudfront-viewer-country": "US",
23+
"content-length": "47",
24+
"content-type": "application/graphql",
25+
"host": "4aowrg2uhvbw5mn7osu6searqi.appsync-api.us-east-1.amazonaws.com",
26+
"origin": "http://localhost:5173",
27+
"priority": "u=1, i",
28+
"referer": "http://localhost:5173/",
29+
"sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Google Chrome\";v=\"140\"",
30+
"sec-ch-ua-mobile": "?0",
31+
"sec-ch-ua-platform": "macOS",
32+
"sec-fetch-dest": "empty",
33+
"sec-fetch-mode": "cors",
34+
"sec-fetch-site": "cross-site",
35+
"traceparent": "00-0000000000000000d9f454c80b9a529a-73ac6ca3427073a3-01",
36+
"tracestate": "dd=s:1;o:rum",
37+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36","via":"2.0 62f9f3967e93a923f21c8acb20cf10b6.cloudfront.net (CloudFront)",
38+
"x-amz-cf-id": "Femhicb_Vbva-J8qWjdI4hKMmqusCeQSp207UGyY3u8VOUrdE8BBvg==",
39+
"x-amzn-appsync-is-vpce-request": "False",
40+
"x-amzn-remote-ip": "64.124.12.19",
41+
"x-amzn-requestid": "1ee1669a-eda3-4d4f-911c-35f74ebef31d",
42+
"x-amzn-trace-id": "Root=1-68cdb7e9-438bf88259d7ce3535723bdd",
43+
"x-forwarded-for": "64.124.12.19,15.158.225.229",
44+
"x-forwarded-port": "443",
45+
"x-forwarded-proto": "https"
46+
}
47+
},
48+
"source": "None"
49+
}

0 commit comments

Comments
 (0)