Skip to content

Commit abcfe53

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

15 files changed

+46
-2
lines changed

datadog_lambda/asm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,19 @@ def asm_start_response(
185185
"content-type": "application/json",
186186
}
187187

188+
if isinstance(response, dict) and "statusCode" in response:
189+
body = response.get("body")
190+
else:
191+
body = response
192+
188193
core.dispatch(
189194
# The matching listener is registered in ddtrace.appsec._handlers
190195
"aws_lambda.start_response",
191196
(
192197
span,
193198
status_code,
194199
response_headers,
200+
body,
195201
),
196202
)
197203

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)