Skip to main content

Lightweight OpenTelemetry collector

Project description

rotel 🌶️ 🍅

Python package for the Rotel lightweight OpenTelemetry collector.

PyPI - Version PyPI - Python Version

Description

This package provides an embedded OpenTelemetry collector, built on the lightweight Rotel collector. When started, it spawns a background daemon that accepts OpenTelemetry metrics, traces, and logs. Designed for minimal overhead, Rotel reduces resource consumption while simplifying telemetry collection and processing in complex Python applications—without requiring additional sidecar containers.

Telemetry Type Support
Metrics Alpha
Traces Alpha
Logs Alpha

How it works

By default, the Rotel agent listens for OpenTelemetry data over gRPC (port 4317) and HTTP (port 4318) on localhost. It efficiently batches telemetry signals and forwards them to a configurable OpenTelemetry protocol (OTLP) compatible endpoint.

In your application, you use the OpenTelemetry Python SDK to add instrumentation for traces, metrics, and logs. The SDK by default will communicate over ports 4317 or 4318 on localhost to the Rotel agent. You can now ship your instrumented application and efficiently export OpenTelemetry data to your vendor or observability tool of choice with a single deployment artifact.

Future updates will introduce support for filtering data, transforming telemetry, and exporting to different vendors and tools.

Getting started

Rotel configuration

Add the rotel Python package to your project's dependencies. There are two approaches to configuring rotel:

  1. typed config dicts
  2. environment variables

Typed dicts

In the startup section of your main.py add the following code block. Replace the endpoint with the endpoint of your OpenTelemetry vendor and any required API KEY headers.

from rotel import Config, Rotel

rotel = Rotel(
    enabled = True,
    exporters = {
        'otlp': Config.otlp_exporter(
            endpoint = "https://foo.example.com",
            headers = {
                "x-api-key" : settings.API_KEY,
                "x-data-set": "testing"
            }
        ),
    },
    # Define exporters per telemetry type
    exporters_traces = ['otlp'],
    exporters_metrics = ['otlp'],
    exporters_logs = ['otlp']
)
rotel.start()

Environment variables

You can also configure rotel entirely with environment variables. In your application startup, insert:

import rotel
rotel.start()

In your application deployment configuration, set the following environment variables. These match the typed configuration above:

  • ROTEL_ENABLED=true
  • ROTEL_EXPORTERS=otlp
  • ROTEL_EXPORTER_OTLP_ENDPOINT=https://foo.example.com
  • ROTEL_EXPORTER_OTLP_CUSTOM_HEADERS=x-api-key={API_KEY},x-data-set=testing
  • ROTEL_EXPORTERS_TRACES=otlp
  • ROTEL_EXPORTERS_METRICS=otlp
  • ROTEL_EXPORTERS_LOGS=otlp

Any typed configuration options will override environment variables of the same name.


See the Configuration section for the full list of options.

OpenTelemetry SDK configuration

Once the rotel collector agent is running, you may need to configure your application's instrumentation. If you are using the default rotel endpoints of localhost:4317 and localhost:4318, then you should not need to change anything.

To set the endpoint the OpenTelemetry SDK will use, set the following environment variable:

  • OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

Configuration

This is the full list of global options and their environment variable alternatives. Any defaults left blank in the table are either False or None.

Option Name Type Environ Default Options
enabled bool ROTEL_ENABLED
pid_file str ROTEL_PID_FILE /tmp/rotel-agent.pid
log_file str ROTEL_LOG_FILE /tmp/rotel-agent.log
log_format str ROTEL_LOG_FORMAT text json, text
debug_log list[str] ROTEL_DEBUG_LOG traces, metrics, logs
debug_log_verbosity str ROTEL_DEBUG_LOG_VERBOSITY basic basic, detailed
otlp_grpc_endpoint str ROTEL_OTLP_GRPC_ENDPOINT localhost:4317
otlp_http_endpoint str ROTEL_OTLP_HTTP_ENDPOINT localhost:4318

For each exporter you would like to use, see the configuration options below. Exporters should be assigned to the exporters dict with a custom name.

OTLP Exporter

To construct an OTLP exporter, use the method Config.otlp_exporter() with the following options.

Option Name Type Default Options
endpoint str
protocol str grpc grpc or http
headers dict[str, str]
compression str gzip gzip or none
request_timeout str 5s
retry_initial_backoff str 5s
retry_max_backoff str 30s
retry_max_elapsed_time str 300s
batch_max_size int 8192
batch_timeout str 200ms
tls_cert_file str
tls_key_file str
tls_ca_file str
tls_skip_verify bool

Datadog Exporter

Rotel provides an experimental Datadog exporter that supports traces at the moment. Construct a Datadog exporter with the method Config.datadog_exporter() using the following options.

Option Name Type Default Options
region str us1 us1, us3, us5, eu, ap1
custom_endpoint str
api_key str

Clickhouse Exporter

Rotel provides a Clickhouse exporter with support metrics, logs, and traces. Construct a Clickhouse exporter with the method Config.clickhouse_exporter() using the following options.

Option Name Type Default Options
endpoint str
database str otel
table_prefix str otel
compression str lz4
async_insert bool true
user str
password str
enable_json bool
json_underscore bool

Kafka Exporter

Rotel provides a Kafka exporter with support for metrics, logs, and traces. Construct a Kafka exporter with the method Config.kafka_exporter() using the following options.

Option Name Type Default Options
brokers list localhost:9092
traces_topic str otlp_traces
logs_topic str otlp_logs
metrics_topic str otlp_metrics
format str protobuf json, protobuf
compression str none gzip, snappy, lz4, zstd, none
acks str one all, one, none
client_id str rotel
max_message_bytes int 1000000
linger_ms int 5
retries int 2147483647
retry_backoff_ms int 100
retry_backoff_max_ms int 1000
message_timeout_ms int 300000
request_timeout_ms int 30000
batch_size int 1000000
partitioner str consistent-random consistent, consistent-randomm, murmur2-random, murmur2, fnv1a, fnv1a-random
partitioner_metrics_by_resource_attributes str 1000
partitioner_logs_by_resource_attributes str 1000
custom_config str 1000
sasl_username str
sasl_password str
sasl_mechanism str plain, scram-sha256, scram-sha512
security_protocol str plaintext plaintext, ssl, sasl-plaintext, sasl-ssl

Multiple exporters

Pyrotel supports multiple exporters, allowing you to send data to different destinations per telemetry type. Just set the exporters entry to a dict map of exporter definitions and then configure the exporters per telemetry type. For example, this will send metrics and logs to an OTLP endpoint while sending traces to Datadog:

from rotel import Config, Rotel

rotel = Rotel(
    enabled = True,
    exporters = {
        'logs_and_metrics': Config.otlp_exporter(
            endpoint = "https://foo.example.com",
            headers = {
                "x-api-key" : settings.API_KEY,
                "x-data-set": "testing"
            }
        ),
        'tracing': Config.datadog_exporter(
            api_key = "1234abcd",
        ),
    },
    # Define exporters per telemetry type
    exporters_traces = ['tracing'],
    exporters_metrics = ['logs_and_metrics'],
    exporters_logs = ['logs_and_metrics']
)
rotel.start()

Processors

You can pass a list of Python files to Rotel that support the Python Processor SDK, by settting the following top-level config values. Each takes a list of absolute file paths to files implementing the processor SDK.

Option Name Type
processors_metrics list[str]
processors_traces list[str]
processors_logs list[str]

See the Python Processor SDK docs for more information.

Retries and timeouts

You can override the default request timeout of 5 seconds for the OTLP Exporter with the exporter setting:

  • request_timeout: Takes a string time duration, so "250ms" for 250 milliseconds, "3s" for 3 seconds, etc.

Requests will be retried if they match retryable error codes like 429 (Too Many Requests) or timeout. You can control the behavior with the following exporter options:

  • retry_initial_backoff: Initial backoff duration
  • retry_max_backoff: Maximum backoff interval
  • retry_max_elapsed_time: Maximum wall time a request will be retried for until it is marked as permanent failure

All options should be represented as string time durations.

Full OTEL example

To illustrate this further, here's a full example of how to use Rotel to send trace spans to Axiom from an application instrumented with OpenTelemetry.

The code sample depends on the following environment variables:

  • ROTEL_ENABLED=true: Turn on or off based on the deployment environment
  • AXIOM_DATASET: Name of an Axiom dataset
  • AXIOM_API_TOKEN: Set to an API token that has access to the Axiom dataset
import os

from rotel import Config, Rotel

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.resources import Resource, SERVICE_NAME
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import SimpleSpanProcessor


# Enable at deploy time with ROTEL_ENABLED=true
if os.environ.get("ROTEL_ENABLED") == "true":
    #
    # Configure Rotel to export to Axiom
    #
    otlp_exporter = Config.otlp_exporter(
        endpoint="https://api.axiom.co",
        protocol="http", # Axiom only supports HTTP
        headers={
            "Authorization": f"Bearer {os.environ['AXIOM_API_TOKEN']}",
            "X-Axiom-Dataset": os.environ["AXIOM_DATASET"],
        },
    )

    rotel = Rotel(
        enabled=True,
        exporters = {
            'axiom': otlp_exporter,
        },
        exporters_traces = ['axiom']
    )

    # Start the agent
    rotel.start()

    #
    # Configure OpenTelemetry SDK to export to the localhost Rotel
    #

    # Define the service name resource for the tracer.
    resource = Resource(
        attributes={
            SERVICE_NAME: "pyrotel-test"
        }
    )

    # Create a TracerProvider with the defined resource for creating tracers.
    provider = TracerProvider(resource=resource)

    # Create the OTel exporter to send to the localhost Rotel agent
    exporter = OTLPSpanExporter(endpoint = "http://localhost:4318/v1/traces")

    # Create a processor with the OTLP exporter to send trace spans.
    #
    # You could also use the BatchSpanProcessor, but since Rotel runs locally
    # and will batch, you can avoid double batching.
    processor = SimpleSpanProcessor(exporter)
    provider.add_span_processor(processor)

    # Set the TracerProvider as the global tracer provider.
    trace.set_tracer_provider(provider)

For the complete example, see the hello world application.

Debugging

If you set the option debug_log to ["traces"], or the environment variable ROTEL_DEBUG_LOG=traces, then rotel will log a summary to the log file /tmp/rotel-agent.log each time it processes trace spans. You can add also specify metrics to debug metrics and logs to debug logs.

FAQ

Do I need to call rotel.stop() when I exit?

In most deployment environments you do not need to call rotel.stop() and it is generally recommended that you don't. Calling rotel.stop() will terminate the running agent on a host, so any further export calls from OTEL instrumentation will fail. In a multiprocess environment, such as gunicorn, terminating the Rotel agent from one process will terminate it for all other processes. On ephemeral deployment platforms, it is usually fine to leave the agent running until the compute instance, VM/container/isolate, terminate.

Community

Want to chat about this project, share feedback, or suggest improvements? Join our Discord server! Whether you're a user of this project or not, we'd love to hear your thoughts and ideas. See you there! 🚀

Developing

See the DEVELOPING.md doc for building and development instructions.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rotel-0.0.1a15-cp313-cp313-manylinux_2_34_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

rotel-0.0.1a15-cp313-cp313-manylinux_2_34_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

rotel-0.0.1a15-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl (9.4 MB view details)

Uploaded CPython 3.13macOS 10.9+ universal2 (ARM64, x86-64)macOS 12.3+ ARM64

rotel-0.0.1a15-cp312-cp312-manylinux_2_34_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

rotel-0.0.1a15-cp312-cp312-manylinux_2_34_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

rotel-0.0.1a15-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl (9.4 MB view details)

Uploaded CPython 3.12macOS 10.9+ universal2 (ARM64, x86-64)macOS 12.3+ ARM64

rotel-0.0.1a15-cp311-cp311-manylinux_2_34_x86_64.whl (10.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

rotel-0.0.1a15-cp311-cp311-manylinux_2_34_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

rotel-0.0.1a15-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl (9.4 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)macOS 12.3+ ARM64

rotel-0.0.1a15-cp310-cp310-manylinux_2_34_x86_64.whl (10.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

rotel-0.0.1a15-cp310-cp310-manylinux_2_34_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

rotel-0.0.1a15-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl (9.4 MB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)macOS 12.3+ ARM64

File details

Details for the file rotel-0.0.1a15-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 322a830deed963dd5dcc460007e917eec071c5977e51c3a06029348f39e4eec9
MD5 1ed09f80f4b6dbcfe828020086bf96ca
BLAKE2b-256 9f0c281932a0524d5f1db2dfa67a5102cd12ddf133c37c6502c0953a1921f1cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 71475e9b9861626c558717f74e3a064ac3cb96121eb6973ea997fe2448ae81fe
MD5 838dca3ddcf4a9e15af9d8a50b5de022
BLAKE2b-256 e2042ceb9273dff1b29bf232e0a9237639763e834d7ce0df8dcd1d316cecb901

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 021a0d24d33cb97dba9a73560908b016e140db0ed72432b8dae2e9a935d15d38
MD5 c0bf59d46728cc11489d2965dc5d4478
BLAKE2b-256 0ae759b3527d8628f91fe136d0f4c1e13e93a054ac2c3d4d73de50ee8c95b72e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6b1a12b2d6d52ab10574cb111053402f2bc195fa55453b19294af57c0d35bece
MD5 e174a407f3e0f95cd51a5b8d9647caac
BLAKE2b-256 9ed2e9249cc7be4c26fdef6e2a2ca7836f8b1fc4607bf07289b822407783e285

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ad64b2ce04e37d2c0e88bf34f90b8981381576dc6af2e9604bac69259e106470
MD5 b92be2c87b123572bf7d2b674dd40a3e
BLAKE2b-256 f1d366c5e557879d97d61f8db8db96998850f68cbc63db92da6422939c153630

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp312-cp312-manylinux_2_34_aarch64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 3805d4a9b52e8d0d4c2f70ce9ed29a451f0c5d57587938261a1ac467b6f93baa
MD5 d6336f1179c8307008baf54947694ad7
BLAKE2b-256 ab62fbefa813d7f77f570c6eb090b3261fc4a6b646d7243b52b643e394351f54

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2f4117e58410c933e0dc042a268ef738dab2e3a5d63b5831209acdac2a6ddcb7
MD5 eaa2901327643f628ab1908798e494b2
BLAKE2b-256 956e707655c5b3f6e42287a22b47fef2e9a9ae57ad33ac6cd3efb6f8c1cc1b8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4eb01f9e5d228e4086f63e16cf1d0fa6e92b724bde51f120932a742acec5b0ba
MD5 c934bdf8e07f731e9a740af22458cea5
BLAKE2b-256 9eee40e800505aff294699288d0e18e8d96c327a86af49bbc01f93ee6fa81ae6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp311-cp311-manylinux_2_34_aarch64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 bcb27da321920ef4ba36367f6c51b22f0d69535e43bdf22f9a593384be87a55f
MD5 f6db0316a8675b88cf2cbc6b3a81d93a
BLAKE2b-256 28451826fe04cd318c5daef82c1af9c5f3372a9dc42b399bdb3180bd08987295

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 797faed4ec003b0b1ab65fee25a18c991cb863c221f503d383425f0958aaa5fa
MD5 826dd5b552bdc8cd40d23e9eac1ee383
BLAKE2b-256 6fcc6cb9c16851213a4d06ea8011a39bb259d6cb86684235a1f6203a0ce44215

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 817514e91c57467615784f48c0f055bfdfa245d8e3a2946d829e4a7cb943b389
MD5 c9d21a27d8cc7c6327166c49574e8778
BLAKE2b-256 fade80e26e3eb4c2341447af915f81c341c4b239140952e54a85d4dafe74b955

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp310-cp310-manylinux_2_34_aarch64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rotel-0.0.1a15-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a15-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 87751d14ace9e3ec19e14adbcbfa182f9dfe7416b8f7c77f77c8ae75f320e51a
MD5 96a45e86060c9d5fcd683648d5a67d6c
BLAKE2b-256 95628a0637d343e62ae831235e33dfc6349f5bca711abbe806dda678310fe902

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a15-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl:

Publisher: build-release.yml on streamfold/pyrotel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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