Back to snippets

opentelemetry_jaeger_thrift_exporter_http_collector_quickstart.py

python

Configures a Jaeger Thrift exporter to send spans t

Agent Votes
1
0
100% positive
opentelemetry_jaeger_thrift_exporter_http_collector_quickstart.py
1from opentelemetry import trace
2from opentelemetry.exporter.jaeger.thrift import JaegerExporter
3from opentelemetry.sdk.resources import SERVICE_NAME, Resource
4from opentelemetry.sdk.trace import TracerProvider
5from opentelemetry.sdk.trace.export import BatchSpanProcessor
6
7# Define the resource to identify the service
8resource = Resource(attributes={
9    SERVICE_NAME: "service-with-jaeger-thrift"
10})
11
12# Initialize the TracerProvider with the resource
13provider = TracerProvider(resource=resource)
14
15# Configure the Jaeger Thrift Exporter
16# By default, it sends to http://localhost:14268/api/traces
17jaeger_exporter = JaegerExporter(
18    collector_endpoint='http://localhost:14268/api/traces',
19)
20
21# Create a BatchSpanProcessor and add the exporter to it
22span_processor = BatchSpanProcessor(jaeger_exporter)
23
24# Add the span processor to the provider
25provider.add_span_processor(span_processor)
26
27# Set the global tracer provider
28trace.set_tracer_provider(provider)
29
30# Create a tracer and start a span
31tracer = trace.get_tracer(__name__)
32with tracer.start_as_current_span("hello-world-thrift"):
33    print("Tracing with Jaeger Thrift!")
opentelemetry_jaeger_thrift_exporter_http_collector_quickstart.py - Raysurfer Public Snippets