Thundra

Thundra: Serverless Observability for AWS Lambda

The black box nature of AWS Lambda and other serverless environments means that identifying and fixing performance issues is difficult and time-consuming. Built for straightforward debugging, monitoring, and observability, Thundra provides deep insight into your entire serverless environment. Thundra collects and correlates all your metrics, logs, and traces, allowing you to quickly identify problematic invocations and also analyzes external services associated with that function. With Thundra’s zero overhead and automated instrumentation capabilities, your developers are free to write code without worrying about bulking up their Lambdas or wasting time on chasing black box problems.

Get Started    Discussions

Installation and Configuration

Installation

With AWS Lambda Layers

With AWS Lambda Layers you do not have to install Thundra modules before uploading your function to AWS Lambda.

You just need to wrap your lambda function handler with Thundra as shown below:

from thundra.thundra_agent import Thundra
thundra = Thundra(api_key=<your api key is here>)
@thundra
def handler(event, context):
   print("Hello Thundra!")

To initialize your Thundra variable in your function, you can pass in your Thundra generated API key.

After deploying your function you need to add Thundra's Python Layer as shown here.

Without AWS Lambda Layers

Installation is extremely simple with the pip3 command in the directory of your project.

pip3 install thundra -t .

After installing Thundra’s Python module, you simply have to import it within your Python Lambda function as shown below:


from thundra.thundra_agent import Thundra
thundra = Thundra(api_key=<your api key is here>)
@thundra
def handler(event, context):
   print("Hello Thundra!")

To initialize your Thundra variable in your function, you can pass in your Thundra generated API key.

Automatic Wrapping

If you do not want to change your code you may also automatically wrap your Python function handlers by using Thundra's automatic wrapping capabilities for Python. This is a non-invasive method to wrap your functions and can be done when deploying your lambda functions using serverless. You can read about automatic wrapping in more detail here.

Configurations

Configuring your Lambda functions allows you to control what information you would like to monitor and how you would like to monitor it. This includes monitoring modes such as synchronous or asynchronous monitoring. Thundra for Python functions can be configured in three ways, providing flexibility in how you prefer to monitor your applications. These include:

A detailed list of configuration variable can be found here

After you have successfully configured your lambda function as per the steps above, you can expect to see invocation details of your Lambda function on the Thundra Web Console. This includes displaying your invocation Trace as a single Span. To see more detailed span information, you can instrument your function further, either by manual or through automated instrumentation.

Serverless Framework

Serverless framework deployment is facilitated by using Thundra’s environment variables and setting them in your serverless.yml file. Deploying your serverless application will set these variables and allow Thundra to monitor your functions. A list of environment variables that you may configure in your serverless.yml file can be found here.

Configuration via AWS SAM template file

Using Thundra's layers for Python, you can easily setup Thundra in your template.yml file used by AWS SAM. Using this method, no code change is required!

All you have to do is to add thundra_apiKey variable with your api key and thundra_agent_lambda_handler variable with handler path of your function, change Handler of function to thundra.handler.wrapper and add Thundra's Python layer to Layers as seen in the below example:

Parameters:
  ThundraAWSAccountNo:
    Type: Number
    Default: 269863060030

  ThundraPythonLayerVersion:
    Type: Number
    Default: 7 # Or use any other version

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: thundra.handler.wrapper
      Layers:
        - !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-python-layer:${ThundraPythonLayerVersion}

      Environment:
          Variables:
              thundra_apiKey: <your_api_key> 
              thundra_agent_lambda_handler: hello_world.app.lambda_handler

Latest layer version can be seen here.

If you have multiple functions in your template.yml file that you want to integrate with Thundra, you can use the Global section to add the Thundra's Python layer to multiple functions at once. Below is an example configuration:

Parameters:
  ThundraAWSAccountNo:
    Type: Number
    Default: 269863060030

  ThundraPythonLayerVersion:
    Type: Number
    Default: 7 # Or use any other version

Globals:
  Function:
    Runtime: python3.7
    Timeout: 3

    Handler: thundra.handler.wrapper
    Layers:
    	- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-python-layer:${ThundraPythonLayerVersion}

    Environment:
      Variables:
          thundra_apiKey: <your_api_key>

Resources:
  HelloWorldFunction1:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
          Variables:
              thundra_agent_lambda_handler: hello_world_1.app.lambda_handler

  HelloWorldFunction2:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
          Variables:
              thundra_agent_lambda_handler: hello_world_2.app.lambda_handler

Chalice

Chalice deployment is facilitated by using Thundra’s environment variables and setting them in your .chalice/config.json file. Deploying your chalice application will set these variables and allow Thundra to monitor your functions. A list of environment variables that you may configure in your config.json file can be found here.

You can add environment variables for global or for a specific stage as shown below in your .chalice/config.json:

{
  "version": "2.0",
  "app_name": "test",

  "environment_variables": {
    "thundra_apiKey": <your api key here>
  },
  "stages": {
    "dev": {
      "environment_variables": {
        "thundra_apiKey": <your api key here>
      },
      "api_gateway_stage": "api"
    }
  }
}

Programatic Configuration

You can configure Thundra monitoring in your code base itself using module initialization parameters and are set when initializing your thundra variable. A list of Python initialization variables can be found here.

The initialization variables are passed into the Thundra constructor as comma separated parameters. An example can be seen below:

Configuration Precedence

It must be noted that environment variables have a higher precedence over initialization parameters.

Configuration via AWS Console

This allows you to set Thundra’s environment variables in your AWS lambda function console itself. Hence allowing you to set them through AWS.

To do so, ensure that you have all the required python modules zipped in a single file. By choosing the ‘Upload a zip file’ option in the ‘Code entry type’ drop-down field of the console, you can upload your code with a few clicks, and begin to configure Thundra as you prefer.

Environment variables go in the ‘Environment Variables’ field of the console and clicking 'Save' on the top right-hand side will set your configurations.

You can configure Thundra using environment variables or module initialization parameters.
Environment variables have higher precedence over initialization parameters. For detailed information about all configuration options, check out this documentation.

Installation and Configuration


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.