Jaeger Thrift Exporter for OpenTelemetry

1.21.0 · maintenance · verified Sat Apr 11

The opentelemetry-exporter-jaeger-thrift library allows exporting OpenTelemetry traces to Jaeger using the Thrift protocol over UDP (to an agent) or HTTP (to a collector). This specific exporter, currently at version 1.21.0, is officially deprecated and no longer actively tested; users are strongly encouraged to migrate to the OpenTelemetry Protocol (OTLP) exporter, as Jaeger natively supports OTLP since version 1.35. The broader OpenTelemetry Python project has a regular, frequent release cadence, but this exporter module has ceased active development and testing.

Warnings

Install

Imports

Quickstart

This example demonstrates how to configure the Jaeger Thrift exporter to send traces to a local Jaeger Agent. It sets up a TracerProvider with a service name, initializes the `JaegerExporter` (which by default connects to `localhost:6831`), adds it to a `BatchSpanProcessor`, and then creates a simple trace with parent and child spans. Ensure a Jaeger Agent is running and accessible on the specified host and port for traces to be received. For production environments or newer Jaeger versions, migrating to the OTLP exporter is recommended.

import os
from opentelemetry import trace
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.sdk.resources import Resource, SERVICE_NAME
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# Ensure Jaeger Agent is running, e.g., via Docker: docker run -d --name jaeger -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one:latest

# Configure the TracerProvider
trace.set_tracer_provider(
    TracerProvider(
        resource=Resource.create({SERVICE_NAME: "my-jaeger-service"})
    )
)

# Configure JaegerExporter (defaults to agent_host_name='localhost', agent_port=6831)
jaeger_exporter = JaegerExporter(
    service_name=os.environ.get('OTEL_SERVICE_NAME', 'my-python-app'),
    agent_host_name=os.environ.get('JAEGER_AGENT_HOST', 'localhost'),
    agent_port=int(os.environ.get('JAEGER_AGENT_PORT', 6831))
)

# Add the exporter to a BatchSpanProcessor and then to the TracerProvider
trace.get_tracer_provider().add_span_processor(
    BatchSpanProcessor(jaeger_exporter)
)

# Get a tracer and create some spans
tracer = trace.get_tracer(__name__)

with tracer.start_as_current_span("root-operation"):
    print("Starting root operation...")
    with tracer.start_as_current_span("child-work"):
        print("Performing child work...")
    print("Root operation finished.")

# Spans will be sent to Jaeger Agent, viewable at http://localhost:16686 (if running locally)

view raw JSON →