Serverless Framework

Adding Thundra libraries with Serverless Framework

If you're using Serverless Frameworks as an infrastructure as a code platform to define and deploy your resources, you can easily add Thundra Layer to your project. Below an example that how you can do it with Python.

service: demo
custom:
region: eu-west-1
thundra_layer_version: 15 # or any other version
provider:
name: aws
runtime: python3.7
region: ${self:custom.region}
functions:
demo:
handler: thundra.handler.wrapper
layers:
- arn:aws:lambda:${self:custom.region}:269863060030:layer:thundra-lambda-python-layer:${self:custom.thundra_layer_version}
environment:
thundra_agent_lambda_handler: <your_handler>
thundra_apiKey: <api_key>

You can consult to the documentation for Node.js, Python, Java, Go, and .NET about the some exceptions according to runtime.

Instrumenting multiple functions with Thundra's Serverless plugin

We understand that defining Thundra for each function can be a daunting task. For this reason, we created a Serverless Framework plugin which automatically add Thundra Layer and instrument all the functions in the .yaml file.

Note that this plugin instruments only Java, Python, and Node.js functions.

Installation

This is done by first downloading Thundra’s serverless plugin using the npm command as below:

  • Download Thundra's Serverless Plugin

npm install serverless-plugin-thundra
  • After installing Thundra’s serverless plugin, please specify it as a plugin for your serverless environment by adding it under the plugins section of your .yml file.

plugins:
- serverless-plugin-thundra
  • Furthermore, add the thundra component under custom with apiKey under that, as seen below:

custom:
thundra:
apiKey: <YOUR THUNDRA API KEY>

Already existing Thundra API key

Please remember to add your generated Thundra API Key as is shown in the code snippet above. Also, please remember to add it as an environment variable in the serverless.yml file by referencing it under your provider tag as below:

environment:
thundra_apiKey: ${self:custom.thundra.apiKey}

You can configure Thundra's serverless plugin to disable specific functions or the whole plugin in general.

Disable Plugin:

You may disable Thundra's serverless plugin by using the disable variable under the thundra component which you added under custom when adding the plugin to your '.yml' file.

custom:
thundra:
apiKey: <YOUR THUNDRA API KEY>
disable: true

Disable for specific functions:

You may disable automatic wrapping of specific functions by using the disableAutoWrap variable when defining your functions under the functions component.

functions:
hello-world-test:
name: hello-world-test
handler: index.handler
disableAutoWrap: false

Upon running of your serverless deploy command you shall see that Thundra is working on wrapping your functions. On your Lambda console, you can see that the handler information has changed according to the wrapping conducted by Thundra.

Thundra's Serverless Framework plugin allows you to instrument several functions in one go, and also protect your code base from errors that can occur from manual wrapping. However, this does not mean that you do not have to configure other aspects of your monitoring requirements. Thundra has several monitoring capabilities such as instrumentation to visualize your entire serverless environment in forms of spans. Hence if you would like to enhance your monitoring experience, you would have to perform further configurations. Nevertheless, most of these configurations can be performed via environment variables, abating configuration injections within your code base which are prone to errors if not done correctly.