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

Sampling Support

You can reduce the amount of data that Python agent sends to Thundra Web Console by enabling sampling. You can add built-in sampling rules or provide a custom sampler (implement the sampling logic by yourself) for sampling Trace, Metric and/or Log data by Sampling API .

Sampling API

A sampler should implement the abstract class shown below:

from abc import ABC, abstractmethod


class BaseSampler(ABC):

    @abstractmethod
    def is_sampled(self, args):
        raise Exception("should be implemented")

Custom Sampler

A custom sampler is a class with is_sampled function. is_sampled function should return True if you want to send data to Thundra and should return False if you want to omit the data.

from thundra.samplers import BaseSampler

class CustomSampler(BaseSampler):
  def is_sampled(self, data=None):
    # TODO: Your custom logic here

Count Aware Sampler

Count Aware Sampler enables sampling metric data with a count frequency. For example, if the count frequency is 500, data will be sampled with every 500 lambda invocation.

from thundra.samplers import CountAwareSampler

# Sample for every 100 call
sampler = CountAwareSampler(500)

You can update count frequency without re-deploying Lambda functions. After setting Count Aware Sampler as sampler, you can change the count frequency by setting thundra_agent_lambda_metric_sample_sampler_countAware_countFreq environment variable in AWS Lambda.

Time Aware Sampler

Time Aware Sampler enables sampling metric data with a time frequency. For example, if the time frequency is 300000, data will be sampled with every 300 seconds within consecutive lambda invocations.

from thundra.samplers import TimeAwareSampler

# Sample for every 1000 milliseconds
sampler = TimeAwareSampler(1000)

You can update time-frequency without re-deploying lambda functions. After setting Time Aware Sampler as sampler, you can change the time-frequency by setting thundra_agent_lambda_metric_sample_sampler_timeAware_timeFreq environment variable in AWS Lambda.

Composite Sampler

Composite Sampler enables composing multiple Samplers by specified composition operation (and or or).

An example using TimeAwareSampler and CountAwareSampler with or can be seen below:

from thundra.samplers import (
    TimeAwareSampler, CountAwareSampler,
    CompositeSampler
)


sampler = CompositeSampler(
    samplers=[
        TimeAwareSampler(),
        CountAwareSampler()
    ],
    operator='or'
)

Metric Sampling

To use a sampler for metric sampling, you should set sampler using set_sampler function from thundra.plugins.metric.metric_support.

You can use samplers below or can define a custom sampler and use it instead.

Count Aware Sampler

To use Count Aware Sampler for metric sampling, you should import thundra.samplers.CountAwareSampler and set it as sampler using set_sampler function from thundra.plugins.metric.metric_support. Here is an example usage:

from thundra.thundra_agent import Thundra
from thundra.samplers import CountAwareSampler
from thundra.plugins.metric import metric_support

metric_support.set_sampler(CountAwareSampler())
thundra = Thundra()

# Main handler
@thundra
def handler(event, context):  
    return {"result": "hello"}

You can update count frequency without re-deploying Lambda functions. After setting Count Aware Sampler as sampler, you can change the count frequency by setting thundra_agent_lambda_metric_sample_sampler_countAware_countFreq environment variable in AWS Lambda.

Time Aware Sampler

To use Time Aware Sampler for metric sampling, you should import thundra.samplers.TimeAwareSampler and set it as sampler using set_sampler function from thundra.plugins.metric.metric_support. Here is an example usage:

from thundra.thundra_agent import Thundra
from thundra.samplers import TimeAwareSampler
from thundra.plugins.metric import metric_support

metric_support.set_sampler(TimeAwareSampler())
thundra = Thundra()

# Main handler
@thundra
def handler(event, context):  
    return {"result": "hello"}

You can update time-frequency without re-deploying lambda functions. After setting Time Aware Sampler as sampler, you can change the time-frequency by setting thundra_agent_lambda_metric_sample_sampler_timeAware_timeFreq environment variable in AWS Lambda.

Custom sampler

An example usage of custom sampler for metric plugin is shown below:

import requests

from thundra.thundra_agent import Thundra

from thundra.samplers import BaseSampler
from thundra.plugins.metric import metric_support

class CustomSampler(BaseSampler):
  def is_sampled(self, data=None):
    # TODO: Your custom logic here

metric_support.set_sampler(CustomSampler())

thundra = Thundra()
# Main handler
@thundra
def handler(event, context):
  return {"result": "hello"}

Log Sampling

To use a sampler for log sampling, you should set sampler using set_sampler function from thundra.plugins.log.log_support.

Custom sampler

An example usage of custom sampler for log plugin is shown below:

import requests

from thundra.thundra_agent import Thundra

from thundra.samplers import BaseSampler
from thundra.plugins.log import log_support

class CustomSampler(BaseSampler):
  def is_sampled(self, log=None):
    # TODO: Your custom logic here

log_support.set_sampler(CustomSampler())

thundra = Thundra()
# Main handler
@thundra
def handler(event, context):
  return {"result": "hello"}

Trace Sampling

To use a sampler for trace sampling, you should set sampler using set_sampler function from thundra.plugins.trace.trace_support.

You can use samplers below or can define a custom sampler and use it instead.

Duration Aware Sampler

Duration Aware Sampler enables sampling trace data with according to the duration of the lambda. For example, you want to send trace data only if the duration of the lambda is longer than 500 milliseconds.

Here is an example usage of Duration Aware Sampler for trace sampling:

import requests

from thundra.thundra_agent import Thundra
from thundra.plugins.log.thundra_log_handler import ThundraLogHandler

from thundra.samplers import DurationAwareSampler
from thundra.plugins.trace import trace_support

trace_support.set_sampler(DurationAwareSampler(500, True))

thundra = Thundra()
# Main handler
@thundra
def handler(event, context):  
    return {"result": "hello"}

Error Aware Sampler

Error Aware Sampler enables sampling trace data with according to the erroneous invocation of the lambda. For example, you want to send trace data only the lambda execution results with an error.

Here is an example usage of Error Aware Sampler for trace sampling:

import requests

from thundra.thundra_agent import Thundra

from thundra.samplers import ErrorAwareSampler
from thundra.plugins.trace import trace_support

trace_support.set_sampler(ErrorAwareSampler())

thundra = Thundra()
# Main handler
@thundra
def handler(event, context):  
    return {"result": "hello"}

Custom sampler

A Custom sampler can be added for trace plugin by setting sampler using set_sampler function from thundra.plugins.trace.trace_support.

import requests

from thundra.thundra_agent import Thundra

from thundra.samplers import BaseSampler
from thundra.plugins.trace import trace_support

class CustomSampler(BaseSampler):
  def is_sampled(self, span=None):
    # TODO: Your custom logic here

trace_support.set_sampler(CustomSampler())

thundra = Thundra()
# Main handler
@thundra
def handler(event, context):
  return {"result": "hello"}

Sampling Support


Suggested Edits are limited on API Reference Pages

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