Skip to content

Commit

Permalink
Add http.route tags for API Gateway (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston authored Oct 29, 2024
1 parent c7a87e9 commit 8087c87
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ START
"_inferred_span.tag_source": "self",
"_inferred_span.synchronicity": "sync",
"http.method": "GET",
"http.route":"/{proxy+}",
"stage": "test",
"http.status_code": "200",
"_dd.base_service": "integration-tests-js-XXXX-process-input-traced_node16",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ START
"_inferred_span.tag_source": "self",
"_inferred_span.synchronicity": "sync",
"http.method": "GET",
"http.route":"/{proxy+}",
"stage": "test",
"http.status_code": "200",
"_dd.base_service": "integration-tests-js-XXXX-process-input-traced_node18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ START
"_inferred_span.tag_source": "self",
"_inferred_span.synchronicity": "sync",
"http.method": "GET",
"http.route":"/{proxy+}",
"stage": "test",
"http.status_code": "200",
"_dd.base_service": "integration-tests-js-XXXX-process-input-traced_node20",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ START
"_inferred_span.tag_source": "self",
"_inferred_span.synchronicity": "sync",
"http.method": "GET",
"http.route":"/{proxy+}",
"stage": "test",
"http.status_code": "500",
"_dd.base_service": "integration-tests-js-XXXX-status-code-500s_node16",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ START
"_inferred_span.tag_source": "self",
"_inferred_span.synchronicity": "sync",
"http.method": "GET",
"http.route":"/{proxy+}",
"stage": "test",
"http.status_code": "500",
"_dd.base_service": "integration-tests-js-XXXX-status-code-500s_node18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ START
"_inferred_span.tag_source": "self",
"_inferred_span.synchronicity": "sync",
"http.method": "GET",
"http.route":"/{proxy+}",
"stage": "test",
"http.status_code": "500",
"_dd.base_service": "integration-tests-js-XXXX-status-code-500s_node20",
Expand Down
2 changes: 2 additions & 0 deletions src/trace/trigger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("parseEventSource", () => {
"http.url": "id.execute-api.us-east-1.amazonaws.com",
"http.url_details.path": "/my/path",
"http.method": "GET",
"http.route": "/my/path",
},
file: "api-gateway-v1.json",
},
Expand All @@ -27,6 +28,7 @@ describe("parseEventSource", () => {
"http.url": "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
"http.url_details.path": "/default/nodejs-apig-function-1G3XMPLZXVXYI",
"http.method": "GET",
"http.route": "/nodejs-apig-function-1G3XMPLZXVXYI",
},
file: "api-gateway-v2.json",
},
Expand Down
8 changes: 8 additions & 0 deletions src/trace/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv
if (event.headers?.Referer) {
httpTags["http.referer"] = event.headers.Referer;
}
if (event.resource) {
httpTags["http.route"] = event.resource;
}
return httpTags;
}

Expand All @@ -286,6 +289,11 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv
if (event.headers?.Referer) {
httpTags["http.referer"] = event.headers.Referer;
}
if (event.routeKey) {
// "GET /my/endpoint" => "/my/endpoint"
const array = event.routeKey.split(" ");
httpTags["http.route"] = array[array.length - 1];
}
return httpTags;
}

Expand Down

0 comments on commit 8087c87

Please sign in to comment.