Thundra APM
Search…
Deployment Integrations
Integration Options for Node.js SDK
Using Layers
Without Layers
Serverless Framework
SST
AWS SAM
AWS CDK

Using Layers

Integrating Thundra using AWS Lambda Layers is the recommended (and easier) way to get started with Thundra. Depending on whether or not you choose to use a custom runtime, you can integrate Thundra with no code changes at all or just by wrapping your handler function.

Step 1: Deploy Your Function to AWS Lambda

Bundle all your Node.js Lambda function files and any additional required packages, and then upload it to the AWS Lambda console using the “Upload a.zip file” option for the code entry type. Note that Thundra dependencies are not expected to be in the artifact to be uploaded, as they come with a layer that will be utilized at a later point.

Step 2: Configure Your Function

Add Thundra's Node.js layer to your Lambda function using the ARN below. Note that the ARN contains a region and a version parameter which you will need to set. Set the region value to your Lambda function's region and the version value to the layer version you want to use with your Lambda function.
1
arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-node-layer-minified:${version}
Copied!
Latest version of the Thundra's Node.js layer:
After the Thundra layer ARN has been added, you can continue using a custom runtime or continue without using a custom runtime. Regardless of what you choose, make sure to also set the THUNDRA_APIKEY environment variable to the API key you get from the Thundra console.

Step 3: Configure Handler

You should only use one (either auto or manual) of the options below, not both of them!

a. Auto wrap

Set the handler to thundra_handler.wrapper and then set the THUNDRA_AGENT_LAMBDA_HANDLER environment variable value to your original handler (e.g., index.handler).

b. Manual wrap

You can wrap your Lambda handler to integrate Thundra as shown below.
index.js
1
const thundra = require("@thundra/core")();
2
3
exports.handler = thundra((event, context,callback) => {
4
callback(null, "Hello Thundra!");
5
});
Copied!
In the example above, the required @thundra/core package is already available in Thundra's Node.js layer, which we already added. Thus, you don't need to install the package and bundle it with your Lambda function.

Step 4: Invoke Your Function

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

Without Layers

If you do not want to use AWS Lambda Layers, you can still easily integrate Thundra to your Node.js Lambda function. All you have to do is install the @thundra/core package via npm.

Step 1: Install the @thundra/core package

1
npm install @thundra/core --save
Copied!

Step 2: Wrap your Lambda Handler

After installing the @thundra/core module, you will need to wrap your Lambda handlers. Thundra will monitor your AWS Lambda function automatically, supporting callback along with various context functions.
handler.js
1
const thundra = require("@thundra/core")();
2
3
exports.handler = thundra((event, context,callback) => {
4
callback(null, "Hello Thundra!");
5
});
Copied!

Step 3: Deploy Your Function to AWS Lambda

Bundle your function and any additional required Node.js packages, and then upload it to the AWS Lambda console using the “Upload a.zip file” option for the code entry type.

Step 4: Configure your function

In the AWS Lambda console, set the THUNDRA_APIKEY environment variable to the API key value you got from the Thundra console.

Step 5: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

Serverless Framework

Step 1: Install Thundra’s Serverless Plugin to Automatically Wrap Your Functions

1
npm install serverless-plugin-thundra
Copied!

Step 2: Adding Thundra's Serverless Plugin in serverless.yml File

After installing Thundra’s serverless plugin, specify it as a plugin for your serverless environment by adding it under the plugins section of your serverless.yml file.
serverless.yml
1
plugins:
2
- serverless-plugin-thundra
Copied!
Step 3: Add THUNDRA_APIKEY to Environment Variables Under provider Section in serverless.yml
serverless.yml
1
provider:
2
environment:
3
THUNDRA_APIKEY: <YOUR-THUNDRA-API-KEY>
Copied!
Step 4: Deploy
1
serverless deploy
Copied!

Step 5: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

Step 1: Get the Thundra Layer ARN

Thundra Layer ARN
1
arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-node-layer-minified:${version}
Copied!
Latest version of the Thundra's Node.js layer:

Step 2: Construct Thundra Layer

With the Thundra layer ARN (using latest layer version is highly recommended), you can use the layer construct in your CDK code.
1
import { LayerVersion } from "@aws-cdk/aws-lambda";
2
const thundraLayer = LayerVersion.fromLayerVersionArn(this, "ThundraLayer", "<ARN>");
Copied!

Step 3: Configure Lambda Function

You can then set it for all the functions in your stack using the addDefaultFunctionLayers and addDefaultFunctionEnv. Note we only want to enable this when the function is deployed, not in Live Lambda Dev as the layer will prevent the debugger from connecting.
1
if (!scope.local) {
2
const thundraAWSAccountNo = 269863060030;
3
const thundraNodeLayerVersion = 96; // Latest version at time of writing
4
const thundraLayer = LayerVersion.fromLayerVersionArn(
5
this,
6
"ThundraLayer",
7
`arn:aws:lambda:${scope.region}:${thundraAWSAccountNo}:layer:thundra-lambda-node-layer:${thundraNodeLayerVersion}`,
8
);
9
this.addDefaultFunctionLayers([thundraLayer]);
10
11
this.addDefaultFunctionEnv({
12
THUNDRA_APIKEY: process.env.THUNDRA_API_KEY,
13
NODE_OPTIONS: "-r @thundra/core/dist/bootstrap/lambda",
14
});
15
}
Copied!

AWS SAM

Step 1: Add configuration changes on SAM template.yml

  • Add the THUNDRA_APIKEY environment variable using your Thundra API key.
1
Globals:
2
Function:
3
Environment:
4
Variables:
5
THUNDRA_APIKEY: <YOUR-THUNDRA-API-KEY>
Copied!
  • Add the Thundra layer to Layers in the Globals section. The ThundraAWSAccountNo and ThundraNodeLayerVersion parameters are defined in the Parameters section in the following configuration:
Latest version of the Thundra's Node.js layer:
1
Parameters:
2
ThundraAWSAccountNo:
3
Type: Number
4
Default: 269863060030
5
6
ThundraNodeLayerVersion:
7
Type: Number
8
Default: 96 # Or use any other version
9
10
Globals:
11
Function:
12
Layers:
13
- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-node-layer:${ThundraNodeLayerVersion}
14
15
Copied!
  • Change Handler to Thundra handler
1
Resources:
2
HelloWorldFunction:
3
Type: AWS::Serverless::Function
4
Properties:
5
Handler: thundra_handler.wrapper
Copied!
  • Pass your handler to Thundra over THUNDRA_AGENT_LAMBDA_HANDLER environment variable
1
Resources:
2
HelloWorldFunction:
3
Type: AWS::Serverless::Function
4
Properties:
5
Handler: thundra_handler.wrapper
6
Environment:
7
Variables:
8
THUNDRA_AGENT_LAMBDA_HANDLER: <YOUR-LAMBDA-HANDLER>
Copied!
An example configuration:
1
Parameters:
2
ThundraAWSAccountNo:
3
Type: Number
4
Default: 269863060030
5
ThundraNodeLayerVersion:
6
Type: Number
7
Default: 96 # Or use any other version
8
9
Globals:
10
Function:
11
Timeout: 5
12
Environment:
13
Variables:
14
THUNDRA_APIKEY: <YOUR-THUNDRA-API-KEY>
15
Layers:
16
- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-node-layer:${ThundraNodeLayerVersion}
17
18
Resources:
19
HelloWorldFunction:
20
Type: AWS::Serverless::Function
21
Properties:
22
Handler: thundra_handler.wrapper
23
Environment:
24
Variables:
25
THUNDRA_AGENT_LAMBDA_HANDLER: <YOUR-LAMBDA-HANDLER>
26
Copied!
Step 2: Test / Deploy
To build and run your function locally, use the following:
1
sam build && sam local invoke
Copied!
Then, package and deploy your function using sam.

Step 2: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

AWS CDK

Step 1: Apply Configuration Changes on Your Function Properties.

  • Add THUNDRA_APIKEY environment variable with your Thundra API key.
1
import {Function} from "@aws-cdk/aws-lambda";
2
3
export class YourConstructClass extends core.Construct {
4
5
const thundraApiKey = <YOUR-THUNDRA-API-KEY>;
6
7
constructor(scope: core.Construct, id: string) {
8
const yourFunction = new Function(this, "<YOUR-LAMBDA-HANDLER>", {
9
..., // other function properties
10
environment: {
11
..., // other environment variables
12
THUNDRA_APIKEY: thundraApiKey
13
}
14
});
15
}
16
}
Copied!
  • Define Thundra layer and add it to your function properties.
  • And change your handler to Thundra's handler as described below.
Latest version of the Thundra's Node.js layer:
1
import {Aws} from "@aws-cdk/core";
2
import {Function, LayerVersion} from "@aws-cdk/aws-lambda";
3
4
export class YourConstructClass extends core.Construct {
5
6
const thundraApiKey = <YOUR-THUNDRA-API-KEY>;
7
const thundraAWSAccountNo = 269863060030;
8
const thundraNodeLayerVersion = 96; // or any other version
9
const thundraLayer = LayerVersion.fromLayerVersionArn(
10
this,
11
"ThundraLayer",
12
`arn:aws:lambda:${Aws.REGION}:${thundraAWSAccountNo}:layer:thundra-lambda-node-layer:${thundraNodeLayerVersion}`
13
);
14
15
constructor(scope: core.Construct, id: string) {
16
const yourFunction = new Function(<scope>, <id>, {
17
..., // other function properties
18
// Set your main handler to Thundra's handler
19
handler: "thundra_handler.wrapper",
20
environment: {
21
..., // other environment variables
22
THUNDRA_APIKEY: thundraApiKey,
23
// Add your handler as an environment variable
24
// for Thundra to call as the original handler
25
THUNDRA_AGENT_LAMBDA_HANDLER: "<YOUR-LAMBDA-HANDLER>",
26
},
27
layers: [
28
thundraLayer,
29
... // other layers
30
]
31
});
32
}
33
}
Copied!
Aws.REGION is a pseudo parameter that is bootstrapped from your stack's environment configuration
An example configuration:
1
import {Aws} from "@aws-cdk/core";
2
import {Code, Function, Runtime, LayerVersion} from "@aws-cdk/aws-lambda";
3
4
export class YourConstructClass extends core.Construct {
5
6
const thundraApiKey = <YOUR-THUNDRA-API-KEY>;
7
const thundraAWSAccountNo = 269863060030;
8
const thundraNodeLayerVersion = 96; // or any other version
9
const thundraLayer = LayerVersion.fromLayerVersionArn(
10
this,
11
"ThundraLayer",
12
`arn:aws:lambda:${Aws.REGION}:${thundraAWSAccountNo}:layer:thundra-lambda-node-layer:${thundraNodeLayerVersion}`
13
);
14
15
constructor(scope: core.Construct, id: string) {
16
const handler = new Function(this, "MyFunction", {
17
runtime: Runtime.NODEJS_14_X,
18
code: Code.asset("/path/to/your/resource"),
19
handler: "thundra_handler.wrapper",
20
environment: {
21
THUNDRA_APIKEY: thundraApiKey,
22
THUNDRA_AGENT_LAMBDA_HANDLER: "<YOUR-LAMBDA-HANDLER>",
23
},
24
layers: [
25
thundraLayer
26
]
27
});
28
}
29
}
Copied!

Step 2: Build / Deploy

1
npm run build && cdk deploy
Copied!

Step 3: Invoke Your Function

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!
Last modified 20d ago
Copy link