CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-opentelemetry-exporter-otlp

OpenTelemetry Collector Exporters for sending telemetry data via OTLP protocol

Pending
Overview
Eval results
Files

http-exporters.mddocs/

HTTP Exporters

OTLP exporters using HTTP protocol with protobuf serialization. These exporters provide HTTP-based communication with OpenTelemetry Collector endpoints, suitable for environments where HTTP is preferred over gRPC or where firewall restrictions make HTTP more accessible.

Capabilities

Span Exporter (HTTP)

Exports distributed tracing data using the HTTP protocol. Provides reliable HTTP-based transmission of span data to OpenTelemetry Collector endpoints with support for SSL/TLS and custom authentication.

class OTLPSpanExporter:
    def __init__(
        self,
        endpoint: str | None = None,
        certificate_file: str | None = None,
        client_key_file: str | None = None,
        client_certificate_file: str | None = None,
        headers: dict[str, str] | None = None,
        timeout: float | None = None,
        compression: Compression | None = None,
        session: requests.Session | None = None
    ):
        """
        Create an HTTP OTLP span exporter.

        Parameters:
        - endpoint (str, optional): Collector endpoint URL. Defaults to "http://localhost:4318/v1/traces"
        - certificate_file (str, optional): Path to SSL certificate file for server verification
        - client_key_file (str, optional): Path to client private key file for mutual TLS
        - client_certificate_file (str, optional): Path to client certificate file for mutual TLS
        - headers (dict, optional): Additional headers to send with requests
        - timeout (int, optional): Export timeout in seconds. Defaults to 10
        - compression (Compression, optional): HTTP compression algorithm
        - session (requests.Session, optional): Custom requests session for connection pooling

        Environment Variables:
        - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
        - OTEL_EXPORTER_OTLP_TRACES_HEADERS
        - OTEL_EXPORTER_OTLP_TRACES_TIMEOUT
        - OTEL_EXPORTER_OTLP_TRACES_COMPRESSION
        - OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE
        """

    def export(self, spans) -> SpanExportResult:
        """Export span data to the collector."""

    def shutdown(self) -> None:
        """Shutdown the exporter and clean up resources."""

    def force_flush(self, timeout_millis: int = 30000) -> bool:
        """Force flush any pending spans."""

Metric Exporter (HTTP)

Exports metrics data using the HTTP protocol. Enables HTTP-based transmission of measurement data with support for different temporality preferences and aggregation methods.

class OTLPMetricExporter:
    def __init__(
        self,
        endpoint: str = None,
        certificate_file: str = None,
        client_key_file: str = None,
        client_certificate_file: str = None,
        headers: dict = None,
        timeout: int = None,
        compression: Compression = None,
        session: requests.Session = None,
        preferred_temporality: dict = None,
        preferred_aggregation: dict = None
    ):
        """
        Create an HTTP OTLP metric exporter.

        Parameters:
        - endpoint (str, optional): Collector endpoint URL. Defaults to "http://localhost:4318/v1/metrics"
        - certificate_file (str, optional): Path to SSL certificate file for server verification
        - client_key_file (str, optional): Path to client private key file for mutual TLS
        - client_certificate_file (str, optional): Path to client certificate file for mutual TLS
        - headers (dict, optional): Additional headers to send with requests
        - timeout (int, optional): Export timeout in seconds. Defaults to 10
        - compression (Compression, optional): HTTP compression algorithm
        - session (requests.Session, optional): Custom requests session for connection pooling
        - preferred_temporality (dict, optional): Preferred temporality for metric instruments
        - preferred_aggregation (dict, optional): Preferred aggregation for metric instruments

        Environment Variables:
        - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
        - OTEL_EXPORTER_OTLP_METRICS_HEADERS
        - OTEL_EXPORTER_OTLP_METRICS_TIMEOUT
        - OTEL_EXPORTER_OTLP_METRICS_COMPRESSION
        - OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE
        """

    def export(self, metrics) -> MetricExportResult:
        """Export metric data to the collector."""

    def shutdown(self) -> None:
        """Shutdown the exporter and clean up resources."""

    def force_flush(self, timeout_millis: int = 30000) -> bool:
        """Force flush any pending metrics."""

Log Exporter (HTTP)

Exports structured log data using the HTTP protocol. Provides HTTP-based transmission of log records with full OpenTelemetry context correlation and support for secure connections.

class OTLPLogExporter:
    def __init__(
        self,
        endpoint: str = None,
        certificate_file: str = None,
        client_key_file: str = None,
        client_certificate_file: str = None,
        headers: dict = None,
        timeout: int = None,
        compression: Compression = None,
        session: requests.Session = None
    ):
        """
        Create an HTTP OTLP log exporter.

        Parameters:
        - endpoint (str, optional): Collector endpoint URL. Defaults to "http://localhost:4318/v1/logs"
        - certificate_file (str, optional): Path to SSL certificate file for server verification
        - client_key_file (str, optional): Path to client private key file for mutual TLS
        - client_certificate_file (str, optional): Path to client certificate file for mutual TLS
        - headers (dict, optional): Additional headers to send with requests
        - timeout (int, optional): Export timeout in seconds. Defaults to 10
        - compression (Compression, optional): HTTP compression algorithm
        - session (requests.Session, optional): Custom requests session for connection pooling

        Environment Variables:
        - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
        - OTEL_EXPORTER_OTLP_LOGS_HEADERS
        - OTEL_EXPORTER_OTLP_LOGS_TIMEOUT
        - OTEL_EXPORTER_OTLP_LOGS_COMPRESSION
        - OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE
        """

    def export(self, logs) -> LogExportResult:
        """Export log data to the collector."""

    def shutdown(self) -> None:
        """Shutdown the exporter and clean up resources."""

    def force_flush(self, timeout_millis: int = 30000) -> bool:
        """Force flush any pending logs."""

Types

Compression Enumeration

class Compression:
    """HTTP compression options for OTLP exporters."""
    
    NoCompression = "none"
    """No compression applied to the request body."""
    
    Deflate = "deflate"
    """Deflate compression algorithm."""
    
    Gzip = "gzip"
    """Gzip compression algorithm."""

Constants

# Default HTTP headers for OTLP requests
_OTLP_HTTP_HEADERS: dict = {
    "Content-Type": "application/x-protobuf",
    "User-Agent": "opentelemetry-python"
}

# Default compression setting
DEFAULT_COMPRESSION: Compression = Compression.NoCompression

# Default collector endpoints
DEFAULT_ENDPOINT: str = "http://localhost:4318/"

Usage Examples

Basic HTTP Export Setup

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# Create exporter with default settings
exporter = OTLPSpanExporter()

# Set up tracer provider with batch processor
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(BatchSpanProcessor(exporter))

# Use the tracer
tracer = tracer_provider.get_tracer(__name__)
with tracer.start_as_current_span("example-span"):
    print("Hello, World!")

HTTPS with Custom Headers

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.exporter.otlp.proto.http import Compression

# Create exporter with HTTPS and authentication
exporter = OTLPSpanExporter(
    endpoint="https://my-collector:4318/v1/traces",
    headers={
        "Authorization": "Bearer your-token",
        "X-Custom-Header": "custom-value"
    },
    compression=Compression.Gzip,
    timeout=30
)

Mutual TLS (mTLS) Configuration

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

# Create exporter with mutual TLS
exporter = OTLPSpanExporter(
    endpoint="https://secure-collector:4318/v1/traces",
    certificate_file="/path/to/ca-cert.pem",
    client_certificate_file="/path/to/client-cert.pem",
    client_key_file="/path/to/client-key.pem"
)

Custom Session with Connection Pooling

import requests
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

# Create custom session with connection pooling
session = requests.Session()
session.mount('https://', requests.adapters.HTTPAdapter(
    pool_connections=10,
    pool_maxsize=20,
    max_retries=3
))

# Create exporter with custom session
exporter = OTLPSpanExporter(
    endpoint="https://my-collector:4318/v1/traces",
    session=session
)

Environment Variable Configuration

import os

# Set environment variables
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = "https://collector:4318/v1/traces"
os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = "api-key=your-key,content-type=application/x-protobuf"
os.environ["OTEL_EXPORTER_OTLP_TRACES_COMPRESSION"] = "gzip"
os.environ["OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE"] = "/path/to/ca-cert.pem"

# Create exporter - will automatically use environment variables
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
exporter = OTLPSpanExporter()

Multi-Signal Export Setup

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter

# Create all three exporters with consistent configuration
base_config = {
    "endpoint": "https://my-collector:4318",
    "headers": {"Authorization": "Bearer token"},
    "timeout": 30
}

# Each exporter will append the appropriate path automatically
span_exporter = OTLPSpanExporter(
    endpoint=f"{base_config['endpoint']}/v1/traces",
    headers=base_config["headers"],
    timeout=base_config["timeout"]
)

metric_exporter = OTLPMetricExporter(
    endpoint=f"{base_config['endpoint']}/v1/metrics",
    headers=base_config["headers"],
    timeout=base_config["timeout"]
)

log_exporter = OTLPLogExporter(
    endpoint=f"{base_config['endpoint']}/v1/logs",
    headers=base_config["headers"],
    timeout=base_config["timeout"]
)

Install with Tessl CLI

npx tessl i tessl/pypi-opentelemetry-exporter-otlp

docs

grpc-exporters.md

http-exporters.md

index.md

tile.json