Skip to content

Commit b29c880

Browse files
authored
ref(aws-serverless): Improve README with better examples (#17787)
Fixes: #17774
1 parent 930c1f0 commit b29c880

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

packages/aws-serverless/README.md

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,53 @@
1515
This package is a wrapper around `@sentry/node`, with added functionality related to AWS Lambda. All
1616
methods available in `@sentry/node` can be imported from `@sentry/aws-serverless`.
1717

18-
To use this SDK, call `Sentry.init(options)` at the very beginning of your JavaScript file.
18+
### Automatic Setup
19+
20+
To use this SDK with an automatic setup, set the following environment variables in your Lambda function configuration:
21+
22+
```bash
23+
NODE_OPTIONS="--import @sentry/aws-serverless/awslambda-auto"
24+
SENTRY_DSN="__DSN__"
25+
# Add Tracing by setting tracesSampleRate and adding integration
26+
# Set tracesSampleRate to 1.0 to capture 100% of transactions
27+
# We recommend adjusting this value in production
28+
# Learn more at
29+
# https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
30+
SENTRY_TRACES_SAMPLE_RATE="1.0"
31+
```
32+
33+
### Manual Setup
34+
35+
Alternatively, to further customize the SDK setup, you can also manually initialize the SDK in your lambda function. The benefit of this installation method is that you can fully customize your Sentry SDK setup in a Sentry.init call.
1936

20-
```javascript
37+
Create a new file, for example `instrument.js` to initialize the SDK:
38+
39+
```js
2140
import * as Sentry from '@sentry/aws-serverless';
2241

2342
Sentry.init({
2443
dsn: '__DSN__',
25-
// ...
44+
// Adds request headers and IP for users, for more info visit:
45+
// https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/options/#sendDefaultPii
46+
sendDefaultPii: true,
47+
// Add Tracing by setting tracesSampleRate and adding integration
48+
// Set tracesSampleRate to 1.0 to capture 100% of transactions
49+
// We recommend adjusting this value in production
50+
// Learn more at
51+
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
52+
tracesSampleRate: 1.0,
2653
});
54+
```
55+
56+
And then load the SDK before your function starts by importing the instrument.js file via a NODE_OPTIONS environment variable:
57+
58+
```bash
59+
NODE_OPTIONS="--import ./instrument.js"
60+
```
61+
62+
## Verify
2763

64+
```js
2865
// async (recommended)
2966
export const handler = async (event, context) => {
3067
throw new Error('oh, hello there!');
@@ -36,19 +73,7 @@ export const handler = (event, context, callback) => {
3673
};
3774
```
3875

39-
If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the
40-
`tracesSampleRate` option.
41-
42-
```javascript
43-
import * as Sentry from '@sentry/aws-serverless';
44-
45-
Sentry.init({
46-
dsn: '__DSN__',
47-
tracesSampleRate: 1.0,
48-
});
49-
```
50-
51-
#### Integrate Sentry using the Sentry Lambda layer
76+
## Integrate Sentry using the Sentry Lambda layer
5277

5378
Another much simpler way to integrate Sentry to your AWS Lambda function is to add the official layer.
5479

0 commit comments

Comments
 (0)