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

How to Instrument Python Functions

By instrumenting your functions, you shall enable detailed trace capabilities using Thundra. This will provide great insights into the behavior of your Lambda functions on each invocation made. Those capabilities can be enabled through instrumenting your function either manually or in the automated way. Thundra’s Python agent integrates with the OpenTracing API and by manual instrumentation, you can manually configure the functions you would like to trace. In contrast to manual instrumentation, automated instrumentation will allow you to enable monitoring detailed traces with little effort. You can also change automated instrumentation configuration with Lambda environment variable without requiring a new deployment.

Manual Instrumentation with Open Tracing

Thundra uses the OpenTracing API to implement instrumentation. Thus, you can manually instrument your code by following OpenTracing API instructions as Thundra’s agents are compliant with the OpenTracing API.

To manually instrument your Python functions in order to see detailed spans, you will have to initialize span instances from the tracer object. When a function is called, the tracer will start an active span. If another function is called inside this function, another span is started for the callee and added as a child span to caller’s existing span. This generates a span tree.

The code snippet below is from the example provided in the Thundra blog that can be found here. As can be seen, a ThundraTracer has been procured and a span has been started from it with the method .start_active_span(). The logic to be monitored is defined within the scope, and the span details are set through the parameters passed into the method .start_active_span().

def save_user(self, name, surname, id):
	tracer = ThundraTracer.get_instance()
	with tracer.start_active_span(operation_name='save_user', finish_on_close=True) as scope:
	    user = self.get_user(self, id);
	    if user is not None:
	        raise exception('User with ' + id + ' already exists!')
	    index = randint(10,20)
	        validated = self._validate_id(id)
	    except Exception as e:
	        raise e
	    if validated is True:
	        return self.user_repository.save_user(index, name, surname,id)

Automated Instrumentation

Thundra’s Python agent trace plug-in can allow you to perform automated instrumentation of your Lambda code with a simple configuration using Tracable from Thundra’s trace plugin.

The code snippet below is the same as the one presented in manual instrumentation, but depicting how to perform automated instrumentation.

from sklearn import neighbors
from thundra.plugins.trace.traceable import Traceable

def trainModel():
	knn = neighbors.KNeighborsClassifier()

As can be seen from the example, automated instrumentation simply involves adding the line @Traceable(trace_args=True, trace_return_value=True) above the Python functions you wish to monitor via trace and spans. Also unlike manual instrumentation, here the span names are derived from the names of the functions over which instrumentation is done.

The parameters that are passed to @Tracable are as below:

  • trace_args
  • trace_return_value
  • trace_error

You can find more information on how to use these parameters in Trace Support.

How to Instrument Python Functions

Suggested Edits are limited on API Reference Pages

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