Skip to content

Commit baadddd

Browse files
committed
feat(appsec): enable api security
1 parent c7739eb commit baadddd

15 files changed

+60
-13
lines changed

datadog_lambda/asm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ def asm_start_response(
195195
),
196196
)
197197

198+
if isinstance(response, dict) and "statusCode" in response:
199+
body = response.get("body")
200+
else:
201+
body = response
202+
203+
core.dispatch(
204+
# The matching listener is registered in ddtrace.appsec._handlers
205+
"aws_lambda.parse_body",
206+
(body,),
207+
)
208+
198209

199210
def get_asm_blocked_response(
200211
event_source: _EventSource,

datadog_lambda/wrapper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ def _after(self, event, context):
318318
if status_code:
319319
self.inferred_span.set_tag("http.status_code", status_code)
320320

321+
if self.trigger_tags and (route := self.trigger_tags.get("http.route")):
322+
self.inferred_span.set_tag("http.route", route)
323+
321324
if config.service:
322325
self.inferred_span.set_tag("peer.service", config.service)
323326

tests/integration/snapshots/logs/async-metrics_python310.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
6666
"_inferred_span.synchronicity": "sync",
6767
"_inferred_span.tag_source": "self",
6868
"http.status_code": "200",
69+
"http.route": "/",
6970
"peer.service": "integration-tests-python",
7071
"_dd.peer.service.source": "peer.service",
7172
"_dd.base_service": "integration-tests-python",
@@ -613,6 +614,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
613614
"_inferred_span.synchronicity": "sync",
614615
"_inferred_span.tag_source": "self",
615616
"http.status_code": "200",
617+
"http.route": "/httpapi/get",
616618
"peer.service": "integration-tests-python",
617619
"_dd.peer.service.source": "peer.service",
618620
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/async-metrics_python311.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
6666
"_inferred_span.synchronicity": "sync",
6767
"_inferred_span.tag_source": "self",
6868
"http.status_code": "200",
69+
"http.route": "/",
6970
"peer.service": "integration-tests-python",
7071
"_dd.peer.service.source": "peer.service",
7172
"_dd.base_service": "integration-tests-python",
@@ -613,6 +614,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
613614
"_inferred_span.synchronicity": "sync",
614615
"_inferred_span.tag_source": "self",
615616
"http.status_code": "200",
617+
"http.route": "/httpapi/get",
616618
"peer.service": "integration-tests-python",
617619
"_dd.peer.service.source": "peer.service",
618620
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/async-metrics_python312.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
6666
"_inferred_span.synchronicity": "sync",
6767
"_inferred_span.tag_source": "self",
6868
"http.status_code": "200",
69+
"http.route": "/",
6970
"peer.service": "integration-tests-python",
7071
"_dd.peer.service.source": "peer.service",
7172
"_dd.base_service": "integration-tests-python",
@@ -613,6 +614,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
613614
"_inferred_span.synchronicity": "sync",
614615
"_inferred_span.tag_source": "self",
615616
"http.status_code": "200",
617+
"http.route": "/httpapi/get",
616618
"peer.service": "integration-tests-python",
617619
"_dd.peer.service.source": "peer.service",
618620
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/async-metrics_python313.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
6666
"_inferred_span.synchronicity": "sync",
6767
"_inferred_span.tag_source": "self",
6868
"http.status_code": "200",
69+
"http.route": "/",
6970
"peer.service": "integration-tests-python",
7071
"_dd.peer.service.source": "peer.service",
7172
"_dd.base_service": "integration-tests-python",
@@ -613,6 +614,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
613614
"_inferred_span.synchronicity": "sync",
614615
"_inferred_span.tag_source": "self",
615616
"http.status_code": "200",
617+
"http.route": "/httpapi/get",
616618
"peer.service": "integration-tests-python",
617619
"_dd.peer.service.source": "peer.service",
618620
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/async-metrics_python38.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
6666
"_inferred_span.synchronicity": "sync",
6767
"_inferred_span.tag_source": "self",
6868
"http.status_code": "200",
69+
"http.route": "/",
6970
"peer.service": "integration-tests-python",
7071
"_dd.peer.service.source": "peer.service",
7172
"_dd.base_service": "integration-tests-python",
@@ -613,6 +614,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
613614
"_inferred_span.synchronicity": "sync",
614615
"_inferred_span.tag_source": "self",
615616
"http.status_code": "200",
617+
"http.route": "/httpapi/get",
616618
"peer.service": "integration-tests-python",
617619
"_dd.peer.service.source": "peer.service",
618620
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/async-metrics_python39.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
6666
"_inferred_span.synchronicity": "sync",
6767
"_inferred_span.tag_source": "self",
6868
"http.status_code": "200",
69+
"http.route": "/",
6970
"peer.service": "integration-tests-python",
7071
"_dd.peer.service.source": "peer.service",
7172
"_dd.base_service": "integration-tests-python",
@@ -613,6 +614,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
613614
"_inferred_span.synchronicity": "sync",
614615
"_inferred_span.tag_source": "self",
615616
"http.status_code": "200",
617+
"http.route": "/httpapi/get",
616618
"peer.service": "integration-tests-python",
617619
"_dd.peer.service.source": "peer.service",
618620
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/sync-metrics_python310.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
4646
"_inferred_span.synchronicity": "sync",
4747
"_inferred_span.tag_source": "self",
4848
"http.status_code": "200",
49+
"http.route": "/",
4950
"peer.service": "integration-tests-python",
5051
"_dd.peer.service.source": "peer.service",
5152
"_dd.base_service": "integration-tests-python",
@@ -653,6 +654,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
653654
"_inferred_span.synchronicity": "sync",
654655
"_inferred_span.tag_source": "self",
655656
"http.status_code": "200",
657+
"http.route": "/httpapi/get",
656658
"peer.service": "integration-tests-python",
657659
"_dd.peer.service.source": "peer.service",
658660
"_dd.base_service": "integration-tests-python",

tests/integration/snapshots/logs/sync-metrics_python311.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
4646
"_inferred_span.synchronicity": "sync",
4747
"_inferred_span.tag_source": "self",
4848
"http.status_code": "200",
49+
"http.route": "/",
4950
"peer.service": "integration-tests-python",
5051
"_dd.peer.service.source": "peer.service",
5152
"_dd.base_service": "integration-tests-python",
@@ -653,6 +654,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
653654
"_inferred_span.synchronicity": "sync",
654655
"_inferred_span.tag_source": "self",
655656
"http.status_code": "200",
657+
"http.route": "/httpapi/get",
656658
"peer.service": "integration-tests-python",
657659
"_dd.peer.service.source": "peer.service",
658660
"_dd.base_service": "integration-tests-python",

0 commit comments

Comments
 (0)