Skip to content

Commit 2baec69

Browse files
nhulstonavedmala
authored andcommitted
Add http.route tags for API Gateway (#524)
Add route tags
1 parent eaa09f3 commit 2baec69

12 files changed

+29
-0
lines changed

datadog_lambda/trigger.py

Lines changed: 6 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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
},

0 commit comments

Comments
 (0)