-
Notifications
You must be signed in to change notification settings - Fork 36
Inferred spans for Lambda function URLs #247
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9716c7f
Savepoint. Add trigger and event type logic. Start working out how to…
2c94f5e
feat: Create and finish inferred span. Handle parenting. Ensure compl…
astuyve eb87587
feat: Fix tests and guard clauses
astuyve 3d22dd5
tests: Trigger specs added and working
astuyve 4ae2e2f
feat: Fix http method on createInferredSpanForLambdaUrl. Add test for…
astuyve 96a750a
feat: Rename inferred-spans to span-inferrer, as it exports a class &…
astuyve 04cc766
feat: Use the magical resource.name and span.type to correctly set th…
astuyve a93ab98
Merge branch 'main' into chris.agocs/lambda_url_spans_and_triggers
astuyve aa2f561
Switch to truthy case statement
astuyve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"version": "2.0", | ||
"routeKey": "$default", | ||
"rawPath": "/", | ||
"rawQueryString": "", | ||
"headers": { | ||
"sec-fetch-mode": "navigate", | ||
"sec-fetch-site": "none", | ||
"accept-language": "en-US,en;q=0.9", | ||
"x-forwarded-proto": "https", | ||
"x-forwarded-port": "443", | ||
"x-forwarded-for": "71.195.30.42", | ||
"sec-fetch-user": "?1", | ||
"pragma": "no-cache", | ||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||
"sec-ch-ua": "\"Google Chrome\";v=\"95\", \"Chromium\";v=\"95\", \";Not A Brand\";v=\"99\"", | ||
"sec-ch-ua-mobile": "?0", | ||
"x-amzn-trace-id": "Root=1-61953929-1ec00c3011062a48477b169e", | ||
"sec-ch-ua-platform": "\"macOS\"", | ||
"host": "a8hyhsshac.lambda-url.eu-south-1.amazonaws.com", | ||
"upgrade-insecure-requests": "1", | ||
"cache-control": "no-cache", | ||
"accept-encoding": "gzip, deflate, br", | ||
"sec-fetch-dest": "document", | ||
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" | ||
}, | ||
"requestContext": { | ||
"accountId": "601427279990", | ||
"apiId": "a8hyhsshac", | ||
"domainName": "a8hyhsshac.lambda-url.eu-south-1.amazonaws.com", | ||
"domainPrefix": "a8hyhsshac", | ||
"http": { | ||
"method": "GET", | ||
"path": "/", | ||
"protocol": "HTTP/1.1", | ||
"sourceIp": "71.195.30.42", | ||
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" | ||
}, | ||
"requestId": "ec4d58f8-2b8b-4ceb-a1d5-2be7bff58505", | ||
"routeKey": "$default", | ||
"stage": "$default", | ||
"time": "17/Nov/2021:17:17:29 +0000", | ||
"timeEpoch": 1637169449721 | ||
}, | ||
"isBase64Encoded": false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SpanInferrer } from "./span-inferrer"; | ||
import { TracerWrapper } from "./tracer-wrapper"; | ||
const lambdaURLEvent = require("../../event_samples/lambda-function-urls.json"); | ||
|
||
const mockWrapper = { | ||
startSpan: jest.fn(), | ||
}; | ||
|
||
describe("SpanInferrer", () => { | ||
it("creates an inferred span for lambda function URLs", () => { | ||
const inferrer = new SpanInferrer(mockWrapper as unknown as TracerWrapper); | ||
inferrer.createInferredSpan(lambdaURLEvent, { | ||
awsRequestId: "abcd-1234", | ||
} as any); | ||
|
||
expect(mockWrapper.startSpan).toBeCalledWith("aws.lambda.url", { | ||
service: "aws.lambda", | ||
startTime: 1637169449721, | ||
tags: { | ||
endpoint: "/", | ||
"http.method": "GET", | ||
"http.url": "a8hyhsshac.lambda-url.eu-south-1.amazonaws.com/", | ||
operation_name: "aws.lambda.url", | ||
request_id: "abcd-1234", | ||
"resource.name": "a8hyhsshac.lambda-url.eu-south-1.amazonaws.com/", | ||
resource_names: "a8hyhsshac.lambda-url.eu-south-1.amazonaws.com/", | ||
"span.type": "http", | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Context } from "aws-lambda"; | ||
import { SpanOptions, TracerWrapper } from "./tracer-wrapper"; | ||
import { eventSources, parseEventSource } from "./trigger"; | ||
|
||
export class SpanInferrer { | ||
traceWrapper: TracerWrapper; | ||
constructor(traceWrapper: TracerWrapper) { | ||
this.traceWrapper = traceWrapper; | ||
} | ||
|
||
public createInferredSpan(event: any, context: Context | undefined): any { | ||
const eventSource = parseEventSource(event); | ||
if (eventSource === eventSources.lambdaUrl) { | ||
return this.createInferredSpanForLambdaUrl(event, context); | ||
} | ||
} | ||
|
||
createInferredSpanForLambdaUrl(event: any, context: Context | undefined): any { | ||
const options: SpanOptions = {}; | ||
const domain = event.requestContext.domainName; | ||
const path = event.rawPath; | ||
options.tags = { | ||
operation_name: "aws.lambda.url", | ||
"http.url": domain + path, | ||
endpoint: path, | ||
"http.method": event.requestContext.http.method, | ||
resource_names: domain + path, | ||
request_id: context?.awsRequestId, | ||
"span.type": "http", | ||
"resource.name": domain + path, | ||
}; | ||
options.service = "aws.lambda"; | ||
options.startTime = event.requestContext.timeEpoch; | ||
|
||
return this.traceWrapper.startSpan("aws.lambda.url", options); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯