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
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()

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.1a14-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.1a14-cp313-cp313-manylinux_2_34_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

rotel-0.0.1a14-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.1a14-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.1a14-cp312-cp312-manylinux_2_34_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

rotel-0.0.1a14-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.1a14-cp311-cp311-manylinux_2_34_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

rotel-0.0.1a14-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.1a14-cp310-cp310-manylinux_2_34_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

rotel-0.0.1a14-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.1a14-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5ebac81507fdf3945e778e17dabbd6bafdb5da8379d9996a6d17e3b481e1f351
MD5 e67d19843b2d9318302f9fa031d2e148
BLAKE2b-256 3711e44a9f1a52a56c5712e58c596eee94e7aea52884596ee2b1916d524069a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3ac74835c288c502475f276e105249ddf2c5d6cec5e241cf0ffe89616280f568
MD5 9966aca4c8d6599149df52a2b67c6f84
BLAKE2b-256 c79f2aca733d2d4757b3bd96ac156ae201b043ef7c735e5d2ce92d47f7a6c1b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 33fd1a131af7f564470dadbfd244c44dc26916b8ca1adf4f43ed57230a22e4ef
MD5 a003c05af91585b8e43067f4ccbc45ca
BLAKE2b-256 5307c778ac4af47c4ae6c9c517d7b4dfd5a312c11c4dfef3c2fb85d5bf16068a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f72d22465d8748929d1d5c77fbfc72c518f03300ef101b5f7922fafce71c267c
MD5 819122c8332a3ec4b70e0def67a6a340
BLAKE2b-256 f73c6417ae73ab70c648484e30d46aa4422fa6c4152541ea0f8afefdde1a19ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 63e96fd71827e6dab84d9496376b3077704caaa138ca31a8a91924b88bc9d5b9
MD5 179430f5d31b4e740ab000fe183e5326
BLAKE2b-256 db2a7a0440cebff58add13d1f323e1c97c938221bb518ac2fe02621375cb0ce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 058e4af7e7e6d43f73f950aeb1c687057f0a528ba4f8339e8a3e23a06ca7b0b3
MD5 eda7382467681c31670fee6dc50e6beb
BLAKE2b-256 f5ac331f280813f8c228bbc8b8ef8e3ddaa3639c6c41769b222ca3e2f8aa632a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 535b2347761874c20dcfbed92a28d23ec174ba43a385ab8b2332e47d81564fad
MD5 fc65cefdc159beccc4c8a2384fa1b795
BLAKE2b-256 d82dc0a5ce30ba366139dc719d94617c2ac2fc7eb021b196e180a307da305b8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d1c57a60a044bec2724497ea0174ba0dd8a4019d88b1aae8b7772fd42ac7800c
MD5 9942028ce9b98ebbd7422b24f507dfec
BLAKE2b-256 8c0f44ea728090c161e65f4d88402cf4c7ca02cdc808a9a345da66d81e5122b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 966c135cc1fc591950c9dcd284e7e98dd443ae30dd3077bba76f83fc2e8c035a
MD5 88a92a267abebefc27fe70243b39b662
BLAKE2b-256 e32daff5f5993630f4d3bf913e522c8688af4dcc1cf4b7f9995ceceb57d4dc94

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e9d1e414a62438ce0c96a0e293c79dbf702b5e211ca4677f4e9906bdba31523b
MD5 fde6713753247503a76325c98a5f2b74
BLAKE2b-256 1bb46fe6edcd9636e344e0dd6fd3c60aeba0eaf0f7b0ae39e0a901abee302b9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 475cda1f05cc654d27054ca8ca3ee025dbc101327d1986b955c1299767c3ec0e
MD5 2cdd0920692add74d2c9f43d5b69ca3b
BLAKE2b-256 23f2039d71adafe9cdfe68795ea953c4f5266657bc207f312a724a9a67ad8944

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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.1a14-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl.

File metadata

File hashes

Hashes for rotel-0.0.1a14-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 2537d6a986284efd0756809c1a0e3c4417e2e6e402db0d0d150f0469b514ffdf
MD5 db41321cd319e72c6bb2c3c2756ebc58
BLAKE2b-256 1b4260b6d482875f37b60e0abb99ed8268f502a8891e12b5dd2bbbb653715554

See more details on using hashes here.

Provenance

The following attestation bundles were made for rotel-0.0.1a14-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