Skip to content

Commit f31d9bf

Browse files
committed
Span Inferrer: Fix path for API Gateway V1
1 parent 5bd4206 commit f31d9bf

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/trace/span-inferrer.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const ddbEvent = require("../../event_samples/dynamodb.json");
77
const kinesisEvent = require("../../event_samples/kinesis.json");
88
const eventBridgeEvent = require("../../event_samples/eventbridge.json");
99
const webSocketEvent = require("../../event_samples/api-gateway-wss.json");
10+
const apiGatewayV1 = require("../../event_samples/api-gateway-v1.json");
11+
const apiGatewayV2 = require("../../event_samples/api-gateway-v2.json");
1012
const s3Event = require("../../event_samples/s3.json");
1113
const mockWrapper = {
1214
startSpan: jest.fn(),
@@ -213,6 +215,56 @@ describe("SpanInferrer", () => {
213215
},
214216
});
215217
});
218+
it("creates an inferred span for API Gateway V1 events", () => {
219+
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper);
220+
inferrer.createInferredSpan(apiGatewayV1, {} as any, {} as SpanContext);
221+
222+
expect(mockWrapper.startSpan).toBeCalledWith("aws.apigateway", {
223+
childOf: {},
224+
startTime: undefined,
225+
tags: {
226+
_inferred_span: { synchronicity: undefined, tag_source: "self" },
227+
apiid: "id",
228+
endpoint: "/my/path",
229+
"http.url": "id.execute-api.us-east-1.amazonaws.com/my/path",
230+
"domain_name": "id.execute-api.us-east-1.amazonaws.com",
231+
operation_name: "aws.apigateway",
232+
request_id: undefined,
233+
"http.method": "GET",
234+
"resource.name": "id.execute-api.us-east-1.amazonaws.com /my/path",
235+
resource_names: "id.execute-api.us-east-1.amazonaws.com /my/path",
236+
service: "id.execute-api.us-east-1.amazonaws.com",
237+
"service.name": "id.execute-api.us-east-1.amazonaws.com",
238+
"span.type": "http",
239+
"stage": "$default"
240+
},
241+
});
242+
});
243+
it("creates an inferred span for API Gateway V2 events", () => {
244+
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper);
245+
inferrer.createInferredSpan(apiGatewayV2, {} as any, {} as SpanContext);
246+
247+
expect(mockWrapper.startSpan).toBeCalledWith("aws.apigateway", {
248+
childOf: {},
249+
startTime: 1583817383220,
250+
tags: {
251+
_inferred_span: { synchronicity: undefined, tag_source: "self" },
252+
apiid: "r3pmxmplak",
253+
endpoint: "/default/nodejs-apig-function-1G3XMPLZXVXYI",
254+
"http.url": "r3pmxmplak.execute-api.us-east-2.amazonaws.com/default/nodejs-apig-function-1G3XMPLZXVXYI",
255+
"domain_name": "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
256+
operation_name: "aws.apigateway",
257+
request_id: undefined,
258+
"http.method": "GET",
259+
"resource.name": "r3pmxmplak.execute-api.us-east-2.amazonaws.com /default/nodejs-apig-function-1G3XMPLZXVXYI",
260+
resource_names: "r3pmxmplak.execute-api.us-east-2.amazonaws.com /default/nodejs-apig-function-1G3XMPLZXVXYI",
261+
service: "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
262+
"service.name": "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
263+
"span.type": "http",
264+
"stage": "default"
265+
},
266+
});
267+
});
216268
it("creates an inferred span for s3 events", () => {
217269
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper);
218270
inferrer.createInferredSpan(s3Event, {} as any, {} as SpanContext);

src/trace/span-inferrer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class SpanInferrer {
5555
): SpanWrapper {
5656
const options: SpanOptions = {};
5757
const domain = event.requestContext.domainName;
58-
const path = event.rawPath || event.requestContext.routeKey;
58+
const path = event.rawPath || event.requestContext.path || event.requestContext.routeKey;
5959
let method;
6060
if (event.requestContext.httpMethod) {
6161
method = event.requestContext.httpMethod;

0 commit comments

Comments
 (0)