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>) def handler(event, context): print("Hello Thundra!")
To initialize your Thundra variable in your function, you can pass in your Thundra generated API key.
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.
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:
Serverless Framework - Setting environment variables in .yml file
Programmatically - Setting initialization parameters in modules
Configuration via AWS console - Setting environment variables in AWS console
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 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.
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:
It must be noted that environment variables have a higher precedence over initialization parameters.
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.