Skip to content
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

ENG-53423: add handling for empty responses #83

Merged
merged 3 commits into from
Nov 22, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/pr_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: npm run generate_pb

- name: Cache proto
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: proto
path: ./src/config/generated.*
Expand All @@ -29,7 +29,7 @@ jobs:
needs: generate_proto
strategy:
matrix:
node_version: [ "14", "16", "18", "20" ]
node_version: [ "18", "20", "22" ]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand All @@ -42,7 +42,7 @@ jobs:
- run: npm install
- run: npm install -g [email protected]

- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: proto
path: ./src/config/
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
generate_proto:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: '16'
- run: npm install
Expand All @@ -27,8 +27,8 @@ jobs:
runs-on: ubuntu-20.04
needs: generate_proto
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "16"
registry-url: 'https://registry.npmjs.org'
Expand All @@ -46,7 +46,7 @@ jobs:
- run: npm install
- run: npm install -g [email protected]

- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: proto
path: ./src/config/
Expand Down
30 changes: 24 additions & 6 deletions src/instrumentation/ExtendedAwsLambdaInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ export class ExtendedAwsLambdaInstrumentation extends AwsLambdaInstrumentation {

// @ts-ignore
if (config.requestHook) {
// @ts-ignore
config.requestHook(span, {event, context: lambdaContext});
try{
// @ts-ignore
config.requestHook(span, {event, context: lambdaContext});
}catch(e){
logger.debug("Error processing request hook")
logger.debug(e)
}

}

return otelContext.with(trace.setSpan(otelContext.active(), span), async () => {
Expand All @@ -35,8 +41,14 @@ export class ExtendedAwsLambdaInstrumentation extends AwsLambdaInstrumentation {

// @ts-ignore
if (config.responseHook) {
// @ts-ignore
config.responseHook(span, {err: null, res: result});
try{
// @ts-ignore
config.responseHook(span, {err: null, res: result});
}catch(e){
logger.debug("Error processing success state response hook")
logger.debug(e)
}

}

span.end();
Expand All @@ -52,8 +64,14 @@ export class ExtendedAwsLambdaInstrumentation extends AwsLambdaInstrumentation {
} catch (error) {
// @ts-ignore
if (config.responseHook) {
// @ts-ignore
config.responseHook(span, {err: error});
try{
// @ts-ignore
config.responseHook(span, {err: error});
}catch(e){
logger.debug("Error processing error state response hook")
logger.debug(e)
}

}

span.recordException(error);
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/LambdaInstrumentationWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function LambdaRequestHook(span, {event, context}){
}

export function LambdaResponseHook(span, {err, res}) : void {
if(err && !res){
if(err || !res){
return
}
let statusCode = res['statusCode']
Expand Down
14 changes: 14 additions & 0 deletions test/instrumentation/LambdaInstrumentationWrapperTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,18 @@ describe("manually instrument lambda function", () => {
}
expect(errorCount).to.equal(0)
})

it('can handle non-apigateway events without a response gracefully', async () => {
async function myHandler(event, context, callback){
}

let wrappedHandler = agentTestWrapper.instrumentLambda(myHandler)
let errorCount = 0
try {
await wrappedHandler({"some-different-event": "foo"}, {}, () => {})
} catch(error){
errorCount += 1
}
expect(errorCount).to.equal(0)
})
})
Loading