Skip to content

Span Inferrer: Fix path for API Gateway V1 #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/trace/span-inferrer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const ddbEvent = require("../../event_samples/dynamodb.json");
const kinesisEvent = require("../../event_samples/kinesis.json");
const eventBridgeEvent = require("../../event_samples/eventbridge.json");
const webSocketEvent = require("../../event_samples/api-gateway-wss.json");
const apiGatewayV1 = require("../../event_samples/api-gateway-v1.json");
const apiGatewayV2 = require("../../event_samples/api-gateway-v2.json");
const s3Event = require("../../event_samples/s3.json");
const mockWrapper = {
startSpan: jest.fn(),
Expand Down Expand Up @@ -213,6 +215,56 @@ describe("SpanInferrer", () => {
},
});
});
it("creates an inferred span for API Gateway V1 events", () => {
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper);
inferrer.createInferredSpan(apiGatewayV1, {} as any, {} as SpanContext);

expect(mockWrapper.startSpan).toBeCalledWith("aws.apigateway", {
childOf: {},
startTime: undefined,
tags: {
_inferred_span: { synchronicity: undefined, tag_source: "self" },
apiid: "id",
endpoint: "/my/path",
"http.url": "id.execute-api.us-east-1.amazonaws.com/my/path",
domain_name: "id.execute-api.us-east-1.amazonaws.com",
operation_name: "aws.apigateway",
request_id: undefined,
"http.method": "GET",
"resource.name": "id.execute-api.us-east-1.amazonaws.com /my/path",
resource_names: "id.execute-api.us-east-1.amazonaws.com /my/path",
service: "id.execute-api.us-east-1.amazonaws.com",
"service.name": "id.execute-api.us-east-1.amazonaws.com",
"span.type": "http",
stage: "$default",
},
});
});
it("creates an inferred span for API Gateway V2 events", () => {
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper);
inferrer.createInferredSpan(apiGatewayV2, {} as any, {} as SpanContext);

expect(mockWrapper.startSpan).toBeCalledWith("aws.apigateway", {
childOf: {},
startTime: 1583817383220,
tags: {
_inferred_span: { synchronicity: undefined, tag_source: "self" },
apiid: "r3pmxmplak",
endpoint: "/default/nodejs-apig-function-1G3XMPLZXVXYI",
"http.url": "r3pmxmplak.execute-api.us-east-2.amazonaws.com/default/nodejs-apig-function-1G3XMPLZXVXYI",
domain_name: "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
operation_name: "aws.apigateway",
request_id: undefined,
"http.method": "GET",
"resource.name": "r3pmxmplak.execute-api.us-east-2.amazonaws.com /default/nodejs-apig-function-1G3XMPLZXVXYI",
resource_names: "r3pmxmplak.execute-api.us-east-2.amazonaws.com /default/nodejs-apig-function-1G3XMPLZXVXYI",
service: "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
"service.name": "r3pmxmplak.execute-api.us-east-2.amazonaws.com",
"span.type": "http",
stage: "default",
},
});
});
it("creates an inferred span for s3 events", () => {
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper);
inferrer.createInferredSpan(s3Event, {} as any, {} as SpanContext);
Expand Down
2 changes: 1 addition & 1 deletion src/trace/span-inferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class SpanInferrer {
): SpanWrapper {
const options: SpanOptions = {};
const domain = event.requestContext.domainName;
const path = event.rawPath || event.requestContext.routeKey;
const path = event.rawPath || event.requestContext.path || event.requestContext.routeKey;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astuyve I'm afraid that the right change here should be:

const path = event.rawPath || event.requestContext.resourcePath || event.requestContext.routeKey;

Copy link
Contributor

@astuyve astuyve Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let method;
if (event.requestContext.httpMethod) {
method = event.requestContext.httpMethod;
Expand Down