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

Implement extension for AWS Lambda for automatic integration. #3041

Closed

Conversation

marshall-lee
Copy link
Contributor

@marshall-lee marshall-lee commented Nov 10, 2020

This PR aims to improve the experience for users who want to integrate Sentry to their AWS Lambda functions.

For now, users have to upload @sentry/serverless package and its every dependency into a node_modules directory of their lambda function. It's especially inconvenient for people who just write the code in the AWS Console and don't have any external dependencies but want to enable error tracking & tracing.

Thanks to AWS, there Lambda Layers exist. We can bundle all the Sentry packages and distribute it as pluggable layer available by its ARN string. Added a layer to the lambda, one can then load the integration automatically when the lambda starts using a special environment variable NODE_OPTIONS=-r @sentry/serverless/dist/auto. Then, SENTRY_DSN environment variable must be set too and SENTRY_TRACES_SAMPLE_RATE is also available to enable tracing.

TODO:

  • Write a publish script that pushes a zip bundle to every region of AWS (it creates a new version of a layer).
  • Run this script on every release (???). Don't know how to do it really. cc @kamilogorek

Another problem I don't know what to do with is layer versions. Layers don't have anything like tags, e.g @v5.27.3. Layer versions are just auto-incrementing numbers, e.g. arn:aws:lambda:eu-central-1:123456789:layer:SentrySDK:1, arn:aws:lambda:eu-central-1:123456789:layer:SentrySDK:2, ...
So we need to figure out a way how to inform users which version is the latest. Maybe the serverless README.md must be somehow updated every time a new layer version is uploaded? Or the README.md should just contain a hyperlink to some page with the latest version numbers? I really don't know.

@lobsterkatie
Copy link
Member

lobsterkatie commented Nov 10, 2020

@marshall-lee - Thanks for this. Kamil's out until next week, but in the meantime, two things:

SENTRY_TRACES_SAMPLE_RATE is also available to enable tracing

How would you handle the tracesSampler option documented here?

As for running a script on every release, that's controlled by this file.

@marshall-lee
Copy link
Contributor Author

@lobsterkatie

How would you handle the tracesSampler option documented here?

tracesSampler, beforeSend, beforeBreadcrumb and other options that require writing a js function, cannot be provided when using @sentry/serverless/dist/auto script. We can support more scalar environment variables of config but not the ones that require writing a code. This automated integration is intended for simple use cases where you don't need much Sentry customization. Only SENTRY_DSN variable is really required and you're gtg.

But even when not using @sentry/serverless/dist/auto, having a layer with a full Sentry SDK is still useful. Users still don't have to upload sdk for every function, they just link a layer to it and then require('@sentry/serverless') becomes available so they can manually call Sentry.init({ dsn: '...', tracesSampler: function() { ... } }); like they did before.

@lobsterkatie
Copy link
Member

tracesSampler, beforeSend, beforeBreadcrumb and other options that require writing a js function, cannot be provided when using @sentry/serverless/dist/auto script. We can support more scalar environment variables of config but not the ones that require writing a code. This automated integration is intended for simple use cases where you don't need much Sentry customization. Only SENTRY_DSN variable is really required and you're gtg.

But even when not using @sentry/serverless/dist/auto, having a layer with a full Sentry SDK is still useful. Users still don't have to upload sdk for every function, they just link a layer to it and then require('@sentry/serverless') becomes available so they can manually call Sentry.init({ dsn: '...', tracesSampler: function() { ... } }); like they did before.

Ah, got it. Thanks for the explanation. Never mind, then! :-)

@ajjindal
Copy link

@HazAT could you take a look at this while Kamil is out? We are trying to get this out by end of the week.

Thanks @lobsterkatie

Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

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

Is this file empty on purpose?
packages/serverless/index.js

WRT publishing this, we need to upload this publically to our own AWS account to a specific layer?

package.json Outdated Show resolved Hide resolved
@marshall-lee
Copy link
Contributor Author

@HazAT

WRT publishing this, we need to upload this publically to our own AWS account to a specific layer?

Yep. There's also a script for this called packages/serverless/scripts/publish-awslambda-layer.js. It uploads a layer data to a bunch of AWS regions and makes it public.

Note that it must be uploaded to every region user might want because layer region and lambda function region must match.

@marshall-lee
Copy link
Contributor Author

@kamilogorek you can re-check, i removed all questionnable stuff.

@scefali
Copy link
Member

scefali commented Jan 20, 2021

Closing because we merged a PR that implements this: #3165

@scefali scefali closed this Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants