From 06f183a85ee18e989668c5272fc1cec02b416d76 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 17 Feb 2025 10:24:08 +0100 Subject: [PATCH 1/2] feat(aws-lambda): Use versioned docs for v7 and v8 lambda layers --- .../guides/aws-lambda/install/cjs-layer.mdx | 26 ----- .../aws-lambda/install/cjs-layer__v7.x.mdx | 90 ++++++++++++++++ .../aws-lambda/install/cjs-layer__v8.x.mdx | 101 ++++++++++++++++++ 3 files changed, 191 insertions(+), 26 deletions(-) create mode 100644 docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx create mode 100644 docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx diff --git a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer.mdx b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer.mdx index 1aed72cc7b0ff..d55ca1223078e 100644 --- a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer.mdx +++ b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer.mdx @@ -88,29 +88,3 @@ exports.handler = Sentry.wrapHandler(async (event, context) => { 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. That's it - you're all set! - -## Lambda layer for v7 SDK - -The instructions above are written for SDK version 8 (the most recent version). -You can also install a v7 version of the Sentry Lambda layer in case you can't upgrade to v8. -The procedure is identical to the instructions above except for two differences: - -### v7 layer ARN - -The v7 Lambda layer has a different ARN: - -``` -arn:aws:Lambda:us-west-1:943013980633:layer:SentryNodeServerlessSDKv7:3 -``` - -Modify and copy the ARN value for your region into the input, e.g. for region `:us-west-1` and the current v7 Lambda layer version `:3`: - -### v7 package name - -The `@sentry/aws-serverless` package was called `@sentry/serverless` prior to version 8. Therefore, for the v7 layer, adjust your `NODE_OPTIONS` environment variable: - -```bash -NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto" -``` - -The other environment variables remain the same as above. diff --git a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx new file mode 100644 index 0000000000000..303dd7276934d --- /dev/null +++ b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx @@ -0,0 +1,90 @@ +--- +title: Lambda Layer - CJS +description: "Learn how to add the Sentry Node Lambda Layer to use Sentry in your Lambda functions running in CommonJS (CJS)" +sidebar_order: 1 +--- + +The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/Lambda/latest/dg/configuration-layers.html) instead of adding `@sentry/serverless` with `npm` or `yarn` manually. +If you follow this guide, you don't have to worry about deploying Sentry dependencies alongside your function code. +To actually start the SDK, you can decide between setting up the SDK using environment variables or in your Lambda function code. We recommend using environment variables as it's the easiest way to get started. [Initializing the SDK in code](#alternative-initialize-the-sdk-in-code) instead of setting environment variables gives you more control over the SDK setup if you need it. + + + +This installation method **does not** work with Lambda functions running in EcmaScript Modules (ESM) mode, using `import` syntax. + + + +## 1. Prerequisites + +Before you begin, make sure you have the following: + +- You have a Lambda function that is running in CommonJS (CJS) mode, using `require` syntax. +- You know the AWS region that your function is deployed to. + +## 2. Add the Sentry Lambda Layer + +Add the Sentry Layer by navigating to your Lambda function. Select **Layers**, then **Add a Layer**. + +![](./img/lambda_view.png) + +**Specify an ARN** tab as illustrated: + +![](./img/add_layer.png) + +Modify and copy the ARN value for your region into the input, e.g. for region `us-west-1` and the current v7 Lambda layer version `10`: + +``` +arn:aws:Lambda:us-west-1:943013980633:layer:SentryNodeServerlessSDKv7:10 +``` + +
+ +## 3. Initialize the SDK with Environment Variables + +The easiest way to set up the SDK is to start and configure it using environment variables. This way, you don't have to modify your Lambda function code. + +In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). + +Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below. + + + +Set the following environment variables in your Lambda function configuration: + +```bash {"onboardingOptions": {"performance": "3"}} +NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto" +SENTRY_DSN="___PUBLIC_DSN___" +SENTRY_TRACES_SAMPLE_RATE="1.0" +``` + +To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**. + +## Alternative: Initialize the SDK in Code + +Instead of [Step 3, setting environment variables](#3-initialize-the-sdk-with-environment-variables), you can also manually initialize the SDK in your Lambda function code. +This way, you can customize the SDK setup further. +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. + +Make sure you completed [step 1](#1-prerequisites) and [step 2](#2-add-the-sentry-lambda-layer) before proceeding. + +```javascript {filename:index.js} {"onboardingOptions": {"performance": "5-8"}} +const Sentry = require("@sentry/serverless"); + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + // Add Tracing by setting tracesSampleRate and adding integration + // Set tracesSampleRate to 1.0 to capture 100% of transactions + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, +}); + +exports.handler = Sentry.wrapHandler(async (event, context) => { + // Your handler code +}); +``` + +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. + +That's it - you're all set! diff --git a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx new file mode 100644 index 0000000000000..a1b86ac4d57be --- /dev/null +++ b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx @@ -0,0 +1,101 @@ +--- +title: Lambda Layer - CJS +description: "Learn how to add the Sentry Node Lambda Layer to use Sentry in your Lambda functions running in CommonJS (CJS)" +sidebar_order: 1 +--- + +The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/Lambda/latest/dg/configuration-layers.html) instead of adding `@sentry/aws-serverless` with `npm` or `yarn` [manually](../cjs-npm). +If you follow this guide, you don't have to worry about deploying Sentry dependencies alongside your function code. +To actually start the SDK, you can decide between setting up the SDK using environment variables or in your Lambda function code. We recommend using environment variables as it's the easiest way to get started. [Initializing the SDK in code](#alternative-initialize-the-sdk-in-code) instead of setting environment variables gives you more control over the SDK setup if you need it. + + + +This installation method **does not** work with Lambda functions running in EcmaScript Modules (ESM) mode, using `import` syntax. If you're running your function in ESM, follow the [ESM guide](../esm-npm). + + + +## 1. Prerequisites + +Before you begin, make sure you have the following: + +- You have a Lambda function that is running in CommonJS (CJS) mode, using `require` syntax. +- You know the AWS region that your function is deployed to. + +## 2. Add the Sentry Lambda Layer + +Add the Sentry Layer by navigating to your Lambda function. Select **Layers**, then **Add a Layer**. + +![](./img/lambda_view.png) + +**Specify an ARN** tab as illustrated: + +![](./img/add_layer.png) + +Modify and copy the ARN value for your region into the input, e.g. for region `us-west-1` and the current v8 Lambda layer version `7`: + +``` +arn:aws:Lambda:us-west-1:943013980633:layer:SentryNodeServerlessSDKv8:7 +``` + + + + Previously, the v8 Lambda layer was published under the `SentryNodeServerlessSDK` name. + This target will not receive updates anymore. + + If you need to continue using v8 please use the `SentryNodeServerlessSDKv8` layer as described above. + + + +
+ +## 3. Initialize the SDK with Environment Variables + +The easiest way to set up the SDK is to start and configure it using environment variables. This way, you don't have to modify your Lambda function code. + +In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). + +Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below. + + + +Set the following environment variables in your Lambda function configuration: + +```bash {"onboardingOptions": {"performance": "3"}} +NODE_OPTIONS="-r @sentry/aws-serverless/awslambda-auto" +SENTRY_DSN="___PUBLIC_DSN___" +SENTRY_TRACES_SAMPLE_RATE="1.0" +``` + +To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**: + +![](./img/cjs_env_vars.png) + +## Alternative: Initialize the SDK in Code + +Instead of [Step 3, setting environment variables](#3-initialize-the-sdk-with-environment-variables), you can also manually initialize the SDK in your Lambda function code. +This way, you can customize the SDK setup further. +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. + +Make sure you completed [step 1](#1-prerequisites) and [step 2](#2-add-the-sentry-lambda-layer) before proceeding. + +```javascript {filename:index.js} {"onboardingOptions": {"performance": "5-8"}} +const Sentry = require("@sentry/aws-serverless"); + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + // Add Tracing by setting tracesSampleRate and adding integration + // Set tracesSampleRate to 1.0 to capture 100% of transactions + // We recommend adjusting this value in production + // Learn more at + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate + tracesSampleRate: 1.0, +}); + +exports.handler = Sentry.wrapHandler(async (event, context) => { + // Your handler code +}); +``` + +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. + +That's it - you're all set! From 3edb1543fb6a3e5d5d1c0dfbd02e381b76e2722c Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Mon, 17 Feb 2025 10:40:53 +0100 Subject: [PATCH 2/2] Don't index v7 and v8 versions --- .../javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx | 1 + .../javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx index 303dd7276934d..158ebbbc979bc 100644 --- a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx +++ b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v7.x.mdx @@ -2,6 +2,7 @@ title: Lambda Layer - CJS description: "Learn how to add the Sentry Node Lambda Layer to use Sentry in your Lambda functions running in CommonJS (CJS)" sidebar_order: 1 +noindex: true --- The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/Lambda/latest/dg/configuration-layers.html) instead of adding `@sentry/serverless` with `npm` or `yarn` manually. diff --git a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx index a1b86ac4d57be..b7ead6200aadc 100644 --- a/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx +++ b/docs/platforms/javascript/guides/aws-lambda/install/cjs-layer__v8.x.mdx @@ -2,6 +2,7 @@ title: Lambda Layer - CJS description: "Learn how to add the Sentry Node Lambda Layer to use Sentry in your Lambda functions running in CommonJS (CJS)" sidebar_order: 1 +noindex: true --- The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/Lambda/latest/dg/configuration-layers.html) instead of adding `@sentry/aws-serverless` with `npm` or `yarn` [manually](../cjs-npm).