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

[SUP-1281] AWS Lambda example app #1517

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from

Conversation

luke-belton
Copy link
Member

@luke-belton luke-belton commented Aug 19, 2021

Goal

Bugsnag has a plugin for AWS Lambda but until now there was no example app to demonstrate Bugsnag + AWS Lambda functionality.

Design

Adds Lambda functions to demonstrate the following:

  • Handled exceptions (with Bugsnag.notify)
  • Unhandled exceptions
  • Lambda timeouts
  • Promise rejections

Demonstrates Bugsnag's support for both async and callback Lambda handlers.

Changeset

Example app has been added within the /examples/aws-lambda/simple-app directory

Testing

Tested all functions with sam local run-api and sam local invoke "<RESOURCE_NAME>" -e <path/to/event.json>. The functions have also been deployed to AWS and tested there too.

Note that the timeout functions don't work locally due to a bug with AWS SAM CLI bug, but they work on the deployed test app.

@luke-belton luke-belton changed the title adds aws lambda examples [SUP-1281] AWS Lambda example app Aug 19, 2021
@github-actions
Copy link

github-actions bot commented Aug 19, 2021

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 43.13 kB 13.19 kB
After 43.13 kB 13.19 kB
± No change No change

code coverage diff

Coverage values did not change👌.

Total:

Lines Branches Functions Statements
0%(+0%) 0%(+0%) 0%(+0%) 0%(+0%)

Generated by 🚫 dangerJS against dd3c0f1

@johnkiely1
Copy link
Member

Functionality works as expected for both local and deployed set ups.

I would suggest adding a bit more to the readme:
Perhaps listing out each function endpoint with a little description of what it does.

The retuned {"message":"Internal server error"} for the majority of the endpoints was a little unexpected. I think this is a consequence of the way the lambda function fails. It would be nice if this could be something a little less vague or at least reference it in the readme that this would be expected.

There is a open question/potential bug with platforms regarding caching behaviour for surrounding code retrieval as the /async/handled-error and /callback/handled error can return incorrect code. But we could avoid this by either renaming one of the files or moving the notify away from line 12 on one of them. It's probably worth doing this anyway to avoid confusion.

Errors do display the missing-sourcemaps banner on the dashboard. I wonder if it possible to get these to be produced with the build? if possible add some additional instructions in the readme on how to upload.

@luke-belton
Copy link
Member Author

luke-belton commented Mar 11, 2022

I would suggest adding a bit more to the readme

I've updated the readme to give a better description of the functions

The retuned {"message":"Internal server error"} for the majority of the endpoints was a little unexpected

I don't think there's much we can do about this as it's the way the function fails.

Errors do display the missing-sourcemaps banner on the dashboard

I can't find a way to generate sourcemaps with sam build. I think we'd need to look use something like webpack to build the functions if we wanted to generate sourcemaps

Copy link
Member

@johnkiely1 johnkiely1 left a comment

Choose a reason for hiding this comment

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

There are some failing tests which need to be looked at.

I've not been able to retest any errors arriving to the dashboard as I encounter multiple errors using a brand new copy of the repo and running the sam local command

Firstly :
Invoking callback-handled-exception.lambdaHandler (nodejs14.x)
NodeDependenciesLayer is a local Layer in the template
Image was not found.

FileNotFoundError: [Errno 2] No such file or directory: '/Users/johnkiely/Documents/test_projects/testAwsExample/bugsnag-js/examples/aws-lambda/simple-app/callback-dependencies-layer'

I think this is solved by the following:

template.yaml -> change to ContentUri: dependencies-layer/

However then I get:
Invalid lambda response received: Invalid API Gateway Response Keys: {'errorType', 'trace', 'errorMessage'} in {'errorType': 'Runtime.ImportModuleError', 'errorMessage': "Error: Cannot find module '@bugsnag/js'\nRequire stack:\n- /var/task/async-handled-exception.js\n- /var/runtime/UserFunction.js\n- /var/runtime/Runtime.js\n- /var/runtime/index.js", 'trace': ["Runtime.ImportModuleError: Error: Cannot find module '@bugsnag/js'", 'Require stack:', '- /var/task/async-handled-exception.js', '- /var/runtime/UserFunction.js', '- /var/runtime/Runtime.js', '- /var/runtime/index.js', ' at _loadUserApp (/var/runtime/UserFunction.js:221:13)', ' at Object.module.exports.load (/var/runtime/UserFunction.js:279:17)', ' at Object. (/var/runtime/index.js:43:34)', ' at Module._compile (internal/modules/cjs/loader.js:1085:14)', ' at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)', ' at Module.load (internal/modules/cjs/loader.js:950:32)', ' at Function.Module._load (internal/modules/cjs/loader.js:790:12)', ' at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)', ' at internal/main/run_main_module.js:17:47']}

Looks like something is broken with the dependency resolution.

Also I think we may want to consider not including the package-lock.json file. I was using npm 6 which gave warnings because lockfileVersion:2 is not supported. https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json#lockfileversion. Also npm 8 doesn't support lockfileVersion:1. So users may need to generate their own based on npm version as 6-8 are all currently widely used.

Typo's/suggestions in readme. see in line comments

@himanshufize
Copy link

I try to implement bugsnag for handled error but it not able to log error when I try to call notify inside catch block. I try block it doing it.

@@ -0,0 +1,25 @@
const Bugsnag = require('@bugsnag/js')
const BugsnagPluginAwsLambda = require('@bugsnag/plugin-aws-lambda')

Copy link

@himanshufize himanshufize Jun 20, 2022

Choose a reason for hiding this comment

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

@luke-belton Just one request. Can you add an example in which we call multiple functions and in those function error could occur but they should not break the flow of execution?

This in regard use case when failure in some place is OK but still be need log regarding those failures - One API request

@luke-belton
Copy link
Member Author

@johnkiely1 - I haven't been able to repro the error Invalid lambda response received: Invalid API Gateway Response Keys:. Do you know what version of node you were running to test this?

Other than that I've pushed some changes that cover the rest of your comments I hope!

@luke-belton luke-belton requested review from KevinRSDNguyen and removed request for xljones September 12, 2022 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants