Skip to content

Commit ae7df53

Browse files
authored
feat(appsec): skip processing spans for events that are not http requests (#627)
1 parent d72ebaa commit ae7df53

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from importlib import import_module
1010
from time import time_ns
1111

12-
from datadog_lambda.asm import asm_start_response, asm_start_request
12+
from datadog_lambda.asm import asm_set_context, asm_start_response, asm_start_request
1313
from datadog_lambda.dsm import set_dsm_context
1414
from datadog_lambda.extension import should_use_extension, flush_extension
1515
from datadog_lambda.cold_start import (
@@ -239,6 +239,10 @@ def _before(self, event, context):
239239
)
240240
if config.data_streams_enabled:
241241
set_dsm_context(event, event_source)
242+
243+
if config.appsec_enabled:
244+
asm_set_context(event_source)
245+
242246
self.span = create_function_execution_span(
243247
context=context,
244248
function_name=config.function_name,

0 commit comments

Comments
 (0)