Skip to content

Commit 2b85536

Browse files
authored
Add http.route tags for API Gateway (#524)
Add route tags
1 parent 88f2099 commit 2b85536

12 files changed

+29
-0
lines changed

datadog_lambda/trigger.py

+6
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ def extract_http_tags(event):
299299
if headers and headers.get("Referer"):
300300
http_tags["http.referer"] = headers.get("Referer")
301301

302+
# Try to get `routeKey` from API GW v2; otherwise try to get `resource` from API GW v1
303+
route = event.get("routeKey") or event.get("resource")
304+
if route:
305+
# "GET /my/endpoint" = > "/my/endpoint"
306+
http_tags["http.route"] = route.split(" ")[-1]
307+
302308
return http_tags
303309

304310

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

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
106106
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
107107
"http.url_details.path": "/Prod/",
108108
"http.method": "GET",
109+
"http.route": "/",
109110
"http.status_code": "200",
110111
"_dd.base_service": "integration-tests-python"
111112
},
@@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
605606
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
606607
"http.url_details.path": "/httpapi/get",
607608
"http.method": "GET",
609+
"http.route": "/httpapi/get",
608610
"http.status_code": "200",
609611
"_dd.base_service": "integration-tests-python"
610612
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
106106
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
107107
"http.url_details.path": "/Prod/",
108108
"http.method": "GET",
109+
"http.route": "/",
109110
"http.status_code": "200",
110111
"_dd.base_service": "integration-tests-python"
111112
},
@@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
605606
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
606607
"http.url_details.path": "/httpapi/get",
607608
"http.method": "GET",
609+
"http.route": "/httpapi/get",
608610
"http.status_code": "200",
609611
"_dd.base_service": "integration-tests-python"
610612
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
106106
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
107107
"http.url_details.path": "/Prod/",
108108
"http.method": "GET",
109+
"http.route": "/",
109110
"http.status_code": "200",
110111
"_dd.base_service": "integration-tests-python"
111112
},
@@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
605606
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
606607
"http.url_details.path": "/httpapi/get",
607608
"http.method": "GET",
609+
"http.route": "/httpapi/get",
608610
"http.status_code": "200",
609611
"_dd.base_service": "integration-tests-python"
610612
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
106106
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
107107
"http.url_details.path": "/Prod/",
108108
"http.method": "GET",
109+
"http.route": "/",
109110
"http.status_code": "200",
110111
"_dd.base_service": "integration-tests-python"
111112
},
@@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
605606
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
606607
"http.url_details.path": "/httpapi/get",
607608
"http.method": "GET",
609+
"http.route": "/httpapi/get",
608610
"http.status_code": "200",
609611
"_dd.base_service": "integration-tests-python"
610612
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
106106
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
107107
"http.url_details.path": "/Prod/",
108108
"http.method": "GET",
109+
"http.route": "/",
109110
"http.status_code": "200",
110111
"_dd.base_service": "integration-tests-python"
111112
},
@@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
605606
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
606607
"http.url_details.path": "/httpapi/get",
607608
"http.method": "GET",
609+
"http.route": "/httpapi/get",
608610
"http.status_code": "200",
609611
"_dd.base_service": "integration-tests-python"
610612
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
8686
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
8787
"http.url_details.path": "/Prod/",
8888
"http.method": "GET",
89+
"http.route": "/",
8990
"http.status_code": "200",
9091
"_dd.base_service": "integration-tests-python"
9192
},
@@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
642643
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
643644
"http.url_details.path": "/httpapi/get",
644645
"http.method": "GET",
646+
"http.route": "/httpapi/get",
645647
"http.status_code": "200",
646648
"_dd.base_service": "integration-tests-python"
647649
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
8686
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
8787
"http.url_details.path": "/Prod/",
8888
"http.method": "GET",
89+
"http.route": "/",
8990
"http.status_code": "200",
9091
"_dd.base_service": "integration-tests-python"
9192
},
@@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
642643
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
643644
"http.url_details.path": "/httpapi/get",
644645
"http.method": "GET",
646+
"http.route": "/httpapi/get",
645647
"http.status_code": "200",
646648
"_dd.base_service": "integration-tests-python"
647649
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
8686
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
8787
"http.url_details.path": "/Prod/",
8888
"http.method": "GET",
89+
"http.route": "/",
8990
"http.status_code": "200",
9091
"_dd.base_service": "integration-tests-python"
9192
},
@@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
642643
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
643644
"http.url_details.path": "/httpapi/get",
644645
"http.method": "GET",
646+
"http.route": "/httpapi/get",
645647
"http.status_code": "200",
646648
"_dd.base_service": "integration-tests-python"
647649
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
8686
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
8787
"http.url_details.path": "/Prod/",
8888
"http.method": "GET",
89+
"http.route": "/",
8990
"http.status_code": "200",
9091
"_dd.base_service": "integration-tests-python"
9192
},
@@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
642643
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
643644
"http.url_details.path": "/httpapi/get",
644645
"http.method": "GET",
646+
"http.route": "/httpapi/get",
645647
"http.status_code": "200",
646648
"_dd.base_service": "integration-tests-python"
647649
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
8686
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
8787
"http.url_details.path": "/Prod/",
8888
"http.method": "GET",
89+
"http.route": "/",
8990
"http.status_code": "200",
9091
"_dd.base_service": "integration-tests-python"
9192
},
@@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
642643
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
643644
"http.url_details.path": "/httpapi/get",
644645
"http.method": "GET",
646+
"http.route": "/httpapi/get",
645647
"http.status_code": "200",
646648
"_dd.base_service": "integration-tests-python"
647649
},

tests/test_trigger.py

+3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def test_extract_trigger_tags_api_gateway(self):
258258
"http.url": "70ixmpl4fl.execute-api.us-east-2.amazonaws.com",
259259
"http.url_details.path": "/prod/path/to/resource",
260260
"http.method": "POST",
261+
"http.route": "/{proxy+}",
261262
},
262263
)
263264

@@ -276,6 +277,7 @@ def test_extract_trigger_tags_api_gateway_non_proxy(self):
276277
"http.url": "lgxbo6a518.execute-api.eu-west-1.amazonaws.com",
277278
"http.url_details.path": "/dev/http/get",
278279
"http.method": "GET",
280+
"http.route": "/http/get",
279281
},
280282
)
281283

@@ -342,6 +344,7 @@ def test_extract_trigger_tags_api_gateway_http_api(self):
342344
"http.url": "x02yirxc7a.execute-api.eu-west-1.amazonaws.com",
343345
"http.url_details.path": "/httpapi/get",
344346
"http.method": "GET",
347+
"http.route": "/httpapi/get",
345348
},
346349
)
347350

0 commit comments

Comments
 (0)