From 0fb3144a27e137dd9040d8e65e0a79540d472605 Mon Sep 17 00:00:00 2001 From: Nicholas Hulston Date: Fri, 25 Oct 2024 12:55:38 -0400 Subject: [PATCH 1/5] add http.route tags --- src/trace/trigger.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/trace/trigger.ts b/src/trace/trigger.ts index ab670059..072be3f1 100644 --- a/src/trace/trigger.ts +++ b/src/trace/trigger.ts @@ -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; } @@ -286,6 +289,9 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv if (event.headers?.Referer) { httpTags["http.referer"] = event.headers.Referer; } + if (event.routeKey) { + httpTags["http.route"] = event.routeKey; + } return httpTags; } From 4b8a1fbf9e533527386ccb20008d14ef16496a60 Mon Sep 17 00:00:00 2001 From: Nicholas Hulston Date: Fri, 25 Oct 2024 13:00:44 -0400 Subject: [PATCH 2/5] update trigger.spec.ts tests --- src/trace/trigger.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/trace/trigger.spec.ts b/src/trace/trigger.spec.ts index 471e363f..681e22a6 100644 --- a/src/trace/trigger.spec.ts +++ b/src/trace/trigger.spec.ts @@ -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", }, @@ -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": "ANY /nodejs-apig-function-1G3XMPLZXVXYI", }, file: "api-gateway-v2.json", }, From 54e33f7c7d84e2ae1c73a1e27526a480a74ff8f3 Mon Sep 17 00:00:00 2001 From: Nicholas Hulston Date: Fri, 25 Oct 2024 14:44:59 -0400 Subject: [PATCH 3/5] update snapshots --- integration_tests/snapshots/logs/process-input-traced_node16.log | 1 + integration_tests/snapshots/logs/process-input-traced_node18.log | 1 + integration_tests/snapshots/logs/process-input-traced_node20.log | 1 + integration_tests/snapshots/logs/status-code-500s_node16.log | 1 + integration_tests/snapshots/logs/status-code-500s_node18.log | 1 + integration_tests/snapshots/logs/status-code-500s_node20.log | 1 + 6 files changed, 6 insertions(+) diff --git a/integration_tests/snapshots/logs/process-input-traced_node16.log b/integration_tests/snapshots/logs/process-input-traced_node16.log index 5734dc9b..6c2c2151 100644 --- a/integration_tests/snapshots/logs/process-input-traced_node16.log +++ b/integration_tests/snapshots/logs/process-input-traced_node16.log @@ -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", diff --git a/integration_tests/snapshots/logs/process-input-traced_node18.log b/integration_tests/snapshots/logs/process-input-traced_node18.log index bdee824c..f38d929c 100644 --- a/integration_tests/snapshots/logs/process-input-traced_node18.log +++ b/integration_tests/snapshots/logs/process-input-traced_node18.log @@ -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", diff --git a/integration_tests/snapshots/logs/process-input-traced_node20.log b/integration_tests/snapshots/logs/process-input-traced_node20.log index e04b7a03..dfc45ae7 100644 --- a/integration_tests/snapshots/logs/process-input-traced_node20.log +++ b/integration_tests/snapshots/logs/process-input-traced_node20.log @@ -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", diff --git a/integration_tests/snapshots/logs/status-code-500s_node16.log b/integration_tests/snapshots/logs/status-code-500s_node16.log index 9662d57e..79f4a0c8 100644 --- a/integration_tests/snapshots/logs/status-code-500s_node16.log +++ b/integration_tests/snapshots/logs/status-code-500s_node16.log @@ -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", diff --git a/integration_tests/snapshots/logs/status-code-500s_node18.log b/integration_tests/snapshots/logs/status-code-500s_node18.log index f8a31bee..7248a341 100644 --- a/integration_tests/snapshots/logs/status-code-500s_node18.log +++ b/integration_tests/snapshots/logs/status-code-500s_node18.log @@ -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", diff --git a/integration_tests/snapshots/logs/status-code-500s_node20.log b/integration_tests/snapshots/logs/status-code-500s_node20.log index 8a0c50b3..938aec86 100644 --- a/integration_tests/snapshots/logs/status-code-500s_node20.log +++ b/integration_tests/snapshots/logs/status-code-500s_node20.log @@ -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", From 33194a0f9addd15bcbfa7b9105dc601eb4b3956f Mon Sep 17 00:00:00 2001 From: Nicholas Hulston Date: Tue, 29 Oct 2024 10:23:10 -0400 Subject: [PATCH 4/5] Remove leading GET/ANY/etc. before `http.route` in API GW v2 --- src/trace/trigger.spec.ts | 2 +- src/trace/trigger.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/trace/trigger.spec.ts b/src/trace/trigger.spec.ts index 681e22a6..29b64892 100644 --- a/src/trace/trigger.spec.ts +++ b/src/trace/trigger.spec.ts @@ -28,7 +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": "ANY /nodejs-apig-function-1G3XMPLZXVXYI", + "http.route": "/nodejs-apig-function-1G3XMPLZXVXYI", }, file: "api-gateway-v2.json", }, diff --git a/src/trace/trigger.ts b/src/trace/trigger.ts index 072be3f1..8bf65520 100644 --- a/src/trace/trigger.ts +++ b/src/trace/trigger.ts @@ -290,7 +290,8 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv httpTags["http.referer"] = event.headers.Referer; } if (event.routeKey) { - httpTags["http.route"] = event.routeKey; + // "GET /my/endpoint" => "/my/endpoint" + httpTags["http.route"] = event.routeKey.split(" ")[-1]; } return httpTags; } From 38217bc3857d522f002f88860f97b1147b75520e Mon Sep 17 00:00:00 2001 From: Nicholas Hulston Date: Tue, 29 Oct 2024 10:30:02 -0400 Subject: [PATCH 5/5] fix --- src/trace/trigger.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trace/trigger.ts b/src/trace/trigger.ts index 8bf65520..e23e0fb6 100644 --- a/src/trace/trigger.ts +++ b/src/trace/trigger.ts @@ -291,7 +291,8 @@ function extractHTTPTags(event: APIGatewayEvent | APIGatewayProxyEventV2 | ALBEv } if (event.routeKey) { // "GET /my/endpoint" => "/my/endpoint" - httpTags["http.route"] = event.routeKey.split(" ")[-1]; + const array = event.routeKey.split(" "); + httpTags["http.route"] = array[array.length - 1]; } return httpTags; }