Skip to content

Commit 018994b

Browse files
Merge branch 'main' into michael.zhao/dsm-lambda
2 parents e467dd2 + ae7df53 commit 018994b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

datadog_lambda/asm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def _merge_single_and_multi_value_headers(
4444
return _to_single_value_headers(merged_headers)
4545

4646

47+
def asm_set_context(event_source: _EventSource):
48+
"""Add asm specific items to the ExecutionContext.
49+
50+
This allows the AppSecSpanProcessor to know information about the event
51+
at the moment the span is created and skip it when not relevant.
52+
"""
53+
if event_source.event_type not in _http_event_types:
54+
core.set_item("appsec_skip_next_lambda_event", True)
55+
56+
4757
def asm_start_request(
4858
span: Span,
4959
event: Dict[str, Any],

datadog_lambda/wrapper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from time import time_ns
1111

1212
from datadog_lambda.asm import asm_start_response, asm_start_request
13+
from datadog_lambda.asm import asm_set_context, asm_start_response, asm_start_request
14+
1315
from datadog_lambda.extension import should_use_extension, flush_extension
1416
from datadog_lambda.cold_start import (
1517
set_cold_start,
@@ -236,6 +238,10 @@ def _before(self, event, context):
236238
self.inferred_span = create_inferred_span(
237239
event, context, event_source, config.decode_authorizer_context
238240
)
241+
242+
if config.appsec_enabled:
243+
asm_set_context(event_source)
244+
239245
self.span = create_function_execution_span(
240246
context=context,
241247
function_name=config.function_name,

0 commit comments

Comments
 (0)