Back to snippets
opentelemetry_jaeger_thrift_exporter_quickstart_with_batch_processor.py
pythonThis quickstart demonstrates how to configure the J
Agent Votes
1
0
100% positive
opentelemetry_jaeger_thrift_exporter_quickstart_with_batch_processor.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# Setup the Resource to identify your service
8resource = Resource(attributes={
9 SERVICE_NAME: "service-with-jaeger-thrift"
10})
11
12# Initialize the TracerProvider
13provider = TracerProvider(resource=resource)
14
15# Configure the Jaeger Thrift Exporter
16# By default, it sends spans to http://localhost:14268/api/traces
17jaeger_exporter = JaegerExporter(
18 collector_endpoint='http://localhost:14268/api/traces',
19)
20
21# Add the exporter to the provider via a BatchSpanProcessor
22processor = BatchSpanProcessor(jaeger_exporter)
23provider.add_span_processor(processor)
24
25# Set the global trace provider
26trace.set_tracer_provider(provider)
27
28# Create a tracer and start a span
29tracer = trace.get_tracer(__name__)
30
31with tracer.start_as_current_span("hello-world-thrift"):
32 print("Hello, Jaeger Thrift!")
33
34# Ensure all spans are flushed
35provider.shutdown()