Skip to content

Commit 9a516b2

Browse files
committed
apply changes from code review
1 parent ec4ddc7 commit 9a516b2

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed
108 KB
Loading

docs/platforms/javascript/guides/aws-lambda/install/layer.mdx

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Learn how to add the Sentry Node Lambda Layer to use Sentry in you
44
sidebar_order: 1
55
---
66

7-
The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/adding-layers.html) instead of adding `@sentry/aws-serverless` with `npm` or `yarn` manually.
7+
The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/adding-layers.html) instead of installing `@sentry/aws-serverless` with a package manager manually.
88
If you follow this guide, you don't have to worry about deploying Sentry dependencies alongside your function code.
99

1010
## Prerequisites
@@ -60,7 +60,7 @@ Select which Sentry features you'd like to install in addition to Error Monitori
6060
Set the following environment variables in your Lambda function configuration:
6161

6262
```bash {tabTitle:CommonJS}
63-
NODE_OPTIONS="-r @sentry/aws-serverless/awslambda-auto"
63+
NODE_OPTIONS="--require @sentry/aws-serverless/awslambda-auto"
6464
SENTRY_DSN="___PUBLIC_DSN___"
6565
# ___PRODUCT_OPTION_START___ performance
6666
SENTRY_TRACES_SAMPLE_RATE="1.0"
@@ -79,7 +79,9 @@ To set environment variables, navigate to your Lambda function, select **Configu
7979

8080
![](./img/env_vars.png)
8181

82-
**For ESM functions only:** You'll also need to manually wrap your handler as shown below:
82+
<Alert level="info" title="For ESM Lambda Functions">
83+
84+
You'll also need to manually wrap your handler as shown below:
8385

8486
```javascript {filename:index.mjs}
8587
import * as Sentry from "@sentry/aws-serverless";
@@ -89,29 +91,25 @@ export const handler = Sentry.wrapHandler(async (event, context) => {
8991
});
9092
```
9193

94+
</Alert>
95+
9296
### Option B: Manual Setup
9397

9498
Instead of using environment variables, you can manually initialize the SDK and wrap your handler in code. This approach works for both CommonJS and ESM functions and allows for further customization of the SDK setup.
9599

96100
Note that you don't have to actually install an NPM package for this to work, as the package is already included in the Lambda Layer.
97101

98-
#### For CommonJS Functions
102+
#### For CommonJS Lambda Functions
99103

100104
```javascript {filename:index.js}
101105
const Sentry = require("@sentry/aws-serverless");
102-
// ___PRODUCT_OPTION_START___ profiling
103-
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
104-
// ___PRODUCT_OPTION_END___ profiling
105106

106107
Sentry.init({
107108
dsn: "___PUBLIC_DSN___",
108109

109110
// Adds request headers and IP for users, for more info visit:
110111
// https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/options/#sendDefaultPii
111112
sendDefaultPii: true,
112-
// ___PRODUCT_OPTION_START___ profiling
113-
integrations: [nodeProfilingIntegration()],
114-
// ___PRODUCT_OPTION_END___ profiling
115113
// ___PRODUCT_OPTION_START___ performance
116114

117115
// Add Tracing by setting tracesSampleRate and adding integration
@@ -121,20 +119,18 @@ Sentry.init({
121119
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
122120
tracesSampleRate: 1.0,
123121
// ___PRODUCT_OPTION_END___ performance
124-
// ___PRODUCT_OPTION_START___ profiling
125-
// Set sampling rate for profiling - this is relative to tracesSampleRate
126-
profilesSampleRate: 1.0,
127-
// ___PRODUCT_OPTION_END___ profiling
128122
});
129123

124+
// Your package imports
125+
130126
exports.handler = Sentry.wrapHandler(async (event, context) => {
131127
// Your handler code
132128
});
133129
```
134130

135-
It's important to add both, the `Sentry.init` call outside the handler function and the `Sentry.wrapHandler` wrapper around your function to automatically catch errors and performance data.
131+
It's important to add both, the `Sentry.init` call outside the handler function and the `Sentry.wrapHandler` wrapper around your function to automatically catch errors and performance data. Make sure that the `Sentry.init` call and the import statement are at the very top of your file before any other imports.
136132

137-
#### For ESM Functions
133+
#### For ESM Lambda Functions
138134

139135
First, wrap your handler:
140136

@@ -152,20 +148,13 @@ Create a new file, for example `instrument.mjs` to initialize the SDK:
152148

153149
```javascript {filename:instrument.mjs}
154150
import * as Sentry from "@sentry/aws-serverless";
155-
// ___PRODUCT_OPTION_START___ profiling
156-
import { nodeProfilingIntegration } from "@sentry/profiling-node";
157-
158-
// ___PRODUCT_OPTION_END___ profiling
159151

160152
Sentry.init({
161153
dsn: "___PUBLIC_DSN___",
162154

163155
// Adds request headers and IP for users, for more info visit:
164156
// https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/options/#sendDefaultPii
165157
sendDefaultPii: true,
166-
// ___PRODUCT_OPTION_START___ profiling
167-
integrations: [nodeProfilingIntegration()],
168-
// ___PRODUCT_OPTION_END___ profiling
169158
// ___PRODUCT_OPTION_START___ performance
170159

171160
// Add Tracing by setting tracesSampleRate and adding integration
@@ -175,10 +164,6 @@ Sentry.init({
175164
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
176165
tracesSampleRate: 1.0,
177166
// ___PRODUCT_OPTION_END___ performance
178-
// ___PRODUCT_OPTION_START___ profiling
179-
// Set sampling rate for profiling - this is relative to tracesSampleRate
180-
profilesSampleRate: 1.0,
181-
// ___PRODUCT_OPTION_END___ profiling
182167
});
183168
```
184169

docs/platforms/javascript/guides/aws-lambda/install/npm.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In this guide you will learn how to set up the `@sentry/aws-serverless` SDK for
88
We recommend starting the SDK automatically via environment variables so that you only have to make minimal code changes to your lambda function.
99
If you need more control over the SDK setup, you can also [initialize the SDK in code](#option-b-manual-setup).
1010

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](../layer) instead.
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, use the [Lambda Layer](../layer) instead.
1212

1313
## 1. Prerequisites
1414

@@ -85,7 +85,7 @@ Choose your setup method based on your Lambda function type:
8585
Set the following environment variables in your Lambda function configuration:
8686

8787
```bash {tabTitle:CommonJS}
88-
NODE_OPTIONS="-r @sentry/aws-serverless/awslambda-auto"
88+
NODE_OPTIONS="--require @sentry/aws-serverless/awslambda-auto"
8989
SENTRY_DSN="___PUBLIC_DSN___"
9090
# ___PRODUCT_OPTION_START___ performance
9191
SENTRY_TRACES_SAMPLE_RATE="1.0"

0 commit comments

Comments
 (0)