You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/aws-lambda/install/cjs-npm.mdx
+71-9Lines changed: 71 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,10 @@ sidebar_order: 2
5
5
---
6
6
7
7
In this guide you will learn how to set up the `@sentry/aws-serverless` SDK for AWS Lambda functions running in CommonJS (CJS) mode.
8
-
This installation method allows you to fully customize your Sentry SDK setup while also being able to tree-shake, transpile and bundle the SDK Code. However, you need to modify your code and deploy the Sentry dependencies alongside your function code. If you're looking for the most simple way to set up Sentry, you might want to use the [Lambda Layer](../cjs-layer) instead.
8
+
We recommend starting the SDK automatically via environment variables so that you only have to make minimal code changes to your lambda function.
9
+
If you need more control over the SDK setup, you can also [initialize the SDK in in code](#alternative-initialize-the-sdk-in-code).
10
+
11
+
However, you need to modify your code and deploy the Sentry dependencies alongside your function code. If you're looking for the most simple way to set up Sentry, you might want to use the [Lambda Layer](../cjs-layer) instead.
Initialize and configure the SDK in your Lambda function Code. Call `Sentry.init`_outside_ of the handler function to avoid re-initializing the SDK on every invocation. Also, add the `Sentry.wrapHandler` wrapper around your function to automatically catch errors and performance data:
66
+
Add the `Sentry.wrapHandler` wrapper around your function handler to automatically catch errors and performance data:
To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**:
89
+
90
+

91
+
92
+
That's it - make sure to re-deploy your function and you're all set!
93
+
94
+
## Alternative: Initialize the SDK in Code
95
+
96
+
To further customize the SDK setup, you can also manually initialize the SDK in your lambda function. You need to initialize the SDK in a separate file and load it before your function starts.
97
+
The benefit of this installation method is that you can fully customize your Sentry SDK setup in a `Sentry.init` call.
98
+
99
+
### 1. Install
100
+
101
+
Follow steps 1 and 2 above to [install the SDK NPM package](#2-install) in your project.
102
+
103
+
### 2. Initialize the SDK
104
+
105
+
Create a new file, for example `instrument.js` to initialize the SDK:
To load the SDK before your function starts, you need to preload the `instrument.js` by setting the `NODE_OPTIONS` environment variable:
155
+
156
+
```bash
157
+
NODE_OPTIONS="--require ./instrument.js"
158
+
```
159
+
160
+
To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**:
161
+
162
+

163
+
102
164
That's it - make sure to re-deploy your function and you're all set!
103
165
104
166
## Using the v7 SDK
105
167
106
-
The instructions above are written for SDK version 8 (the most recent version).
168
+
The instructions above are written for the latest SDK version.
107
169
In SDK versions prior to version 8, the `@sentry/aws-serverless` package was called `@sentry/serverless`. If you are using an older version, you can follow this guide but replace the package with `@sentry/serverless`.
// Set sampling rate for profiling - this is relative to tracesSampleRate
140
140
profilesSampleRate:1.0,
@@ -170,4 +170,4 @@ That's it - make sure to re-deploy your function and you're all set!
170
170
171
171
## Using the v7 SDK
172
172
173
-
The v7 `@sentry/serverless` SDK does not work correctly with ESM-based Lambda functions. Please upgrade to the v8 SDK and follow the instructions above.
173
+
The v7 `@sentry/serverless` SDK does not work correctly with ESM-based Lambda functions. Please upgrade to the latest SDK and follow the instructions above.
0 commit comments