Skip to main content

OpenTelemetry span exporter that writes to stdout in OTLP format

Reason this release was yanked:

wrong packaging

Project description

OpenTelemetry Stdout Span Exporter

A Python span exporter that writes OpenTelemetry spans to stdout in OTLP format. Part of the serverless-otlp-forwarder project.

This exporter is particularly useful in serverless environments like AWS Lambda where writing to stdout is a common pattern for exporting telemetry data.

Features

  • Uses OTLP Protobuf serialization for efficient encoding
  • Applies GZIP compression with configurable levels
  • Detects service name from environment variables
  • Supports custom headers via environment variables
  • Consistent JSON output format

Installation

pip install otlp-stdout-span-exporter

Usage

Basic usage:

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from otlp_stdout_span_exporter import OTLPStdoutSpanExporter

# Create and set the tracer provider
provider = TracerProvider()
trace.set_tracer_provider(provider)

# Create and register the exporter with optional GZIP compression level
exporter = OTLPStdoutSpanExporter(gzip_level=6)
provider.add_span_processor(BatchSpanProcessor(exporter))

# Your instrumentation code here
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("my-operation") as span:
    span.set_attribute("my.attribute", "value")

For a more comprehensive example including nested spans, custom attributes, events, and environment variable configuration:

# Clone the repository
git clone https://github.com/dev7a/serverless-otlp-forwarder
cd serverless-otlp-forwarder/packages/python/otlp-stdout-span-exporter

# Install the package
pip install -e .

# Run the example
python examples/basic_usage.py

Environment Variables

The exporter respects the following environment variables:

  • OTEL_SERVICE_NAME: Service name to use in output
  • AWS_LAMBDA_FUNCTION_NAME: Fallback service name (if OTEL_SERVICE_NAME not set)
  • OTEL_EXPORTER_OTLP_HEADERS: Global headers for OTLP export
  • OTEL_EXPORTER_OTLP_TRACES_HEADERS: Trace-specific headers (takes precedence)

Output Format

The exporter writes each batch of spans as a JSON object to stdout:

{
  "__otel_otlp_stdout": "0.1.0",
  "source": "my-service",
  "endpoint": "http://localhost:4318/v1/traces",
  "method": "POST",
  "content-type": "application/x-protobuf",
  "content-encoding": "gzip",
  "headers": {
    "api-key": "secret123",
    "custom-header": "value"
  },
  "payload": "<base64-encoded-gzipped-protobuf>",
  "base64": true
}

Development

  1. Create a virtual environment:
uv venv && source .venv/bin/activate
  1. Install development dependencies:
uv pip install -e ".[dev]"
  1. Run tests:
pytest
  1. Run linting:
ruff check .
ruff format .

License

Apache License 2.0

See Also

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

otlp_stdout_span_exporter-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

otlp_stdout_span_exporter-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file otlp_stdout_span_exporter-0.1.1.tar.gz.

File metadata

File hashes

Hashes for otlp_stdout_span_exporter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b2b3d2696eadd28c7fed7e0bd31a60abc1cdd44b4a2cde7a3f00c7dbc5060125
MD5 4dbd2749856835dab9af55715ed2c5f1
BLAKE2b-256 c72b82c4d22bdf10cf4625aadde59b71bfe09dcb5d2e2ad72ed5e4e1e3f4d172

See more details on using hashes here.

File details

Details for the file otlp_stdout_span_exporter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for otlp_stdout_span_exporter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 553d2135ecb887f7cfccdc178957148d3f601548d4d0d34a4283b04f5acac4d1
MD5 b1898a4ab51ceaf31749e7553b14384e
BLAKE2b-256 93b22cb893da9d309a91c1586234ce8b41285988ac7eb2add84397b2b8fa65f9

See more details on using hashes here.

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