Skip to content

Commit 8087c87

Browse files
authored
Add http.route tags for API Gateway (#584)
1 parent c7a87e9 commit 8087c87

8 files changed

+16
-0
lines changed

integration_tests/snapshots/logs/process-input-traced_node16.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ START
4848
"_inferred_span.tag_source": "self",
4949
"_inferred_span.synchronicity": "sync",
5050
"http.method": "GET",
51+
"http.route":"/{proxy+}",
5152
"stage": "test",
5253
"http.status_code": "200",
5354
"_dd.base_service": "integration-tests-js-XXXX-process-input-traced_node16",

integration_tests/snapshots/logs/process-input-traced_node18.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ START
4848
"_inferred_span.tag_source": "self",
4949
"_inferred_span.synchronicity": "sync",
5050
"http.method": "GET",
51+
"http.route":"/{proxy+}",
5152
"stage": "test",
5253
"http.status_code": "200",
5354
"_dd.base_service": "integration-tests-js-XXXX-process-input-traced_node18",

integration_tests/snapshots/logs/process-input-traced_node20.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ START
4848
"_inferred_span.tag_source": "self",
4949
"_inferred_span.synchronicity": "sync",
5050
"http.method": "GET",
51+
"http.route":"/{proxy+}",
5152
"stage": "test",
5253
"http.status_code": "200",
5354
"_dd.base_service": "integration-tests-js-XXXX-process-input-traced_node20",

integration_tests/snapshots/logs/status-code-500s_node16.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ START
5454
"_inferred_span.tag_source": "self",
5555
"_inferred_span.synchronicity": "sync",
5656
"http.method": "GET",
57+
"http.route":"/{proxy+}",
5758
"stage": "test",
5859
"http.status_code": "500",
5960
"_dd.base_service": "integration-tests-js-XXXX-status-code-500s_node16",

integration_tests/snapshots/logs/status-code-500s_node18.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ START
5454
"_inferred_span.tag_source": "self",
5555
"_inferred_span.synchronicity": "sync",
5656
"http.method": "GET",
57+
"http.route":"/{proxy+}",
5758
"stage": "test",
5859
"http.status_code": "500",
5960
"_dd.base_service": "integration-tests-js-XXXX-status-code-500s_node18",

integration_tests/snapshots/logs/status-code-500s_node20.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ START
5454
"_inferred_span.tag_source": "self",
5555
"_inferred_span.synchronicity": "sync",
5656
"http.method": "GET",
57+
"http.route":"/{proxy+}",
5758
"stage": "test",
5859
"http.status_code": "500",
5960
"_dd.base_service": "integration-tests-js-XXXX-status-code-500s_node20",

src/trace/trigger.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe("parseEventSource", () => {
1717
"http.url": "id.execute-api.us-east-1.amazonaws.com",
1818
"http.url_details.path": "/my/path",
1919
"http.method": "GET",
20+
"http.route": "/my/path",
2021
},
2122
file: "api-gateway-v1.json",
2223
},
@@ -27,6 +28,7 @@ describe("parseEventSource", () => {
2728
"http.url": "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
2829
"http.url_details.path": "/default/nodejs-apig-function-1G3XMPLZXVXYI",
2930
"http.method": "GET",
31+
"http.route": "/nodejs-apig-function-1G3XMPLZXVXYI",
3032
},
3133
file: "api-gateway-v2.json",
3234
},

src/trace/trigger.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv
275275
if (event.headers?.Referer) {
276276
httpTags["http.referer"] = event.headers.Referer;
277277
}
278+
if (event.resource) {
279+
httpTags["http.route"] = event.resource;
280+
}
278281
return httpTags;
279282
}
280283

@@ -286,6 +289,11 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv
286289
if (event.headers?.Referer) {
287290
httpTags["http.referer"] = event.headers.Referer;
288291
}
292+
if (event.routeKey) {
293+
// "GET /my/endpoint" => "/my/endpoint"
294+
const array = event.routeKey.split(" ");
295+
httpTags["http.route"] = array[array.length - 1];
296+
}
289297
return httpTags;
290298
}
291299

0 commit comments

Comments
 (0)