Skip to content

Commit

Permalink
Add http.route tags for API Gateway (#524)
Browse files Browse the repository at this point in the history
Add route tags
  • Loading branch information
nhulston authored Oct 29, 2024
1 parent 88f2099 commit 2b85536
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions datadog_lambda/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ def extract_http_tags(event):
if headers and headers.get("Referer"):
http_tags["http.referer"] = headers.get("Referer")

# Try to get `routeKey` from API GW v2; otherwise try to get `resource` from API GW v1
route = event.get("routeKey") or event.get("resource")
if route:
# "GET /my/endpoint" = > "/my/endpoint"
http_tags["http.route"] = route.split(" ")[-1]

return http_tags


Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/async-metrics_python310.log
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/async-metrics_python311.log
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/async-metrics_python312.log
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/async-metrics_python38.log
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/async-metrics_python39.log
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -605,6 +606,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/sync-metrics_python310.log
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/sync-metrics_python311.log
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/sync-metrics_python312.log
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/sync-metrics_python38.log
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/snapshots/logs/sync-metrics_python39.log
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/Prod/",
"http.method": "GET",
"http.route": "/",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down Expand Up @@ -642,6 +643,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "XXXX.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
"http.status_code": "200",
"_dd.base_service": "integration-tests-python"
},
Expand Down
3 changes: 3 additions & 0 deletions tests/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def test_extract_trigger_tags_api_gateway(self):
"http.url": "70ixmpl4fl.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/prod/path/to/resource",
"http.method": "POST",
"http.route": "/{proxy+}",
},
)

Expand All @@ -276,6 +277,7 @@ def test_extract_trigger_tags_api_gateway_non_proxy(self):
"http.url": "lgxbo6a518.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/dev/http/get",
"http.method": "GET",
"http.route": "/http/get",
},
)

Expand Down Expand Up @@ -342,6 +344,7 @@ def test_extract_trigger_tags_api_gateway_http_api(self):
"http.url": "x02yirxc7a.execute-api.eu-west-1.amazonaws.com",
"http.url_details.path": "/httpapi/get",
"http.method": "GET",
"http.route": "/httpapi/get",
},
)

Expand Down

0 comments on commit 2b85536

Please sign in to comment.