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

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a4772ffa06bcec11986c4144c0060e725194cc09f00f731b837258225db0b6c8
MD5 f76b5272824fda6c4dc5885b9f3f6ab6
BLAKE2b-256 fe15ec82b535c77762f51e96013af5bde4581eae2dcfa542ca3c2651fab26516

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b4a7f289bdfab385abe93296e57254c1edab7261588f7d7133edcde21682278c
MD5 3f27eea781b2aa8fa77c1ef9328ac7be
BLAKE2b-256 68c9eb0fcef97f56bd830818872c4fcefe4389561ff8ac68db3f15eaa99436a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp313-cp313-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 74cf60da4f2e78aef18e569b937e60457a69a1b18d78e5dc5e32178ecedda18e
MD5 b9c2a0fd2f5eedac3dd10477cc141399
BLAKE2b-256 3f1ae5d78aa92c8e8025688dd7da57f0687970b7c490a5f1634f3be56eac896f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 21582172c14bcbce0a69351b910acc3bf38657d708515fd444a53e2fc6d11129
MD5 dfd3c40eb052f1785ae6e177a0a6f0ed
BLAKE2b-256 4221dcb75e23bd9ef1bc5b0f178020a729abe6485d2c0fa6f18ecc8ed014bd41

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d4686f9a12693559056d22ae8783b702258bda01253773926e1aacd8a7324c79
MD5 fd9e7710ed21c89d4460d2099f121e9f
BLAKE2b-256 f1e570e1b842484123db4ef58acdebc560778c342f9e4280f0a461958f92650b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp312-cp312-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 66ad0744237e0bddf2fa5ea51cc559a1f107d816af3a65e084deeaf7727a518d
MD5 3ab45a2f89e14e3620f8ff478f2df047
BLAKE2b-256 019a015f548f60428ea74cfcccd58a8cefc74d15b8a56270e891200b10825ab5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8767fde9184c423eb3cd7db2f60e2b9801254d61323ecfd3f05dc9f4d1cf0995
MD5 23a32e183731252ab6a1188e6262055b
BLAKE2b-256 0288cf9b82fb6956764861ea7e4fcf8e9e044ae753a2bc04d8ee44eaae496ca2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d4a4148dc6edf4bc8b883ea5a13963adcbbb378843d100d444607ca2c537a691
MD5 42d5dd7d19cbe8658bee7a7497125cff
BLAKE2b-256 ad587cf6df3f45fa9c71465b33b7114e298fac8a6275944f217f562d5241464d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp311-cp311-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 1b26b553bf1617551eace154772a4377504c4cb0e0fb4e65154e111b3f5240a0
MD5 bd1a040ede4acb765b8f14519d7eaf44
BLAKE2b-256 51773175ae87f92b7b5e8f57e02f65ecea545f533a43cfa9f6f0cb8dacc3b8aa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9a28f8cf420cfdde00c889e017effea4641f819be9446ee7254bbc4b118507df
MD5 708ca789f29eaf659ac4ad78f42b9a9f
BLAKE2b-256 08bdb1f024f89f94fef0bb06c78c859a71bfde5b98088bc4db912549bbfaea15

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 65629ec6ce771522330a22925c72db9902e64d3b06389d4d8f7951f179ae52fa
MD5 c9f73230218d5822f68f7073425fc03c
BLAKE2b-256 e559392b9c2ced0bcdff24a0c8b0ace052624843d0174602fb10adb9f8905292

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rotel-0.0.1a13-cp310-cp310-macosx_10_9_universal2.macosx_12_3_arm64.whl
Algorithm Hash digest
SHA256 a9e59b68e4422531e16e442f9b53303edce3c9840c67da4fe7b481a18da3d5e7
MD5 c405d2195676f8b0a12013c6b59f6f94
BLAKE2b-256 ca9f5c2b510767ae2df433f292c83b68b5e7053cda509e194558cb9c56609909

See more details on using hashes here.

Provenance

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