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

Add new AWS Lambda plugin #1307

Merged
merged 5 commits into from
Mar 2, 2021
Merged

Conversation

imjoehaines
Copy link
Contributor

@imjoehaines imjoehaines commented Feb 25, 2021

Goal

This PR adds a plugin to allow Bugsnag to work in an AWS Lambda function. There is more work to do before release, such as session support, but the plugin is functional in this state

This plugin works by using the new @bugsnag/in-flight package so that it can wait for all requests to finish before allowing the Lambda to terminate. There is a default 2 second timeout, but this can be configured by the user to whatever makes sense for their app

Basic usage

const Bugsnag = require('@bugsnag/js')
const BugsnagPluginAwsLambda = require('@bugsnag/plugin-aws-lambda')

Bugsnag.start({
  apiKey: 'api key here',
  plugins: [BugsnagPluginAwsLambda]
})

const bugsnagHandler = Bugsnag.getPlugin('awsLambda').createHandler()

const handler = async (event, context) => // code goes here

module.exports.lambdaHandler = bugsnagHandler(handler)

createHandler takes an options object, with the only current option being flushTimeoutMs. This is the length of time (in milliseconds) that we will wait for requests to finish. For example:

createHandler({ flushTimeoutMs: 5000 }) // 5 seconds

Testing

Tested with unit tests and the MR tests have been updated to assert events are reported when using the new plugin

@github-actions
Copy link

github-actions bot commented Feb 25, 2021

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 40.76 kB 12.57 kB
After 40.76 kB 12.57 kB
± No change No change

code coverage diff

Ok File Lines Branches Functions Statements
/home/runner/work/bugsnag-js/bugsnag-js/packages/in-flight/src/in-flight.js 100%
(+0%)
66.67%
(+16.67%)
100%
(+7.69%)
100%
(+0%)
/home/runner/work/bugsnag-js/bugsnag-js/packages/plugin-aws-lambda/src/index.js 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)

Total:

Lines Branches Functions Statements
81.45%(+0.19%) 70.18%(+0.37%) 84.03%(+0.33%) 80.35%(+0.19%)

Generated by 🚫 dangerJS against 49fad3d

@imjoehaines imjoehaines merged commit ff219fb into integration/aws-lambda Mar 2, 2021
@imjoehaines imjoehaines deleted the plugin-aws-lambda branch March 2, 2021 14:05
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.

2 participants