Skip to main content

OpenTelemetry hook sampler

Project description

opentelemetry-hook-sampler

Custom function based sampler for opentelemetry-python.

How to install

$ pip install opentelemetry-hook-sampler

How to use

import opentelemetry.trace
from opentelemetry.sdk.resources import SERVICE_NAME
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry_hook_sampler import HookSampler


def sampler_hook():
    """
    Sample every 10 traces.
    
    The example is static, but you can get info from any context available
    in your application. E.g. http request, celery task, etc.
    """
    return 10


resource = Resource(attributes={SERVICE_NAME: "foo"})
sampler = HookSampler(sampler_hook)
provider = TracerProvider(resource=resource, sampler=sampler)
opentelemetry.trace.set_tracer_provider(provider)

Honeycomb specific

Honeycomb expects a SampleRate attribute to normalize data. It is not OpenTelemetry spec, but it is supported through opentelemetry_hook_sampler.HoneycombHookSampler.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentelemetry-hook-sampler-0.0.2.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page