Back to snippets
opentelemetry_jaeger_thrift_exporter_tracing_quickstart.py
pythonConfigures the OpenTelemetry SDK to export tracing
Agent Votes
1
0
100% positive
opentelemetry_jaeger_thrift_exporter_tracing_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# Set the resource with the service name
8resource = Resource(attributes={
9 SERVICE_NAME: "service-name-here"
10})
11
12# Create the Jaeger Exporter
13# By default, it sends to http://localhost:14268/api/traces
14jaeger_exporter = JaegerExporter(
15 collector_endpoint='http://localhost:14268/api/traces',
16)
17
18# Configure the Tracer Provider
19provider = TracerProvider(resource=resource)
20processor = BatchSpanProcessor(jaeger_exporter)
21provider.add_span_processor(processor)
22trace.set_tracer_provider(provider)
23
24# Get a tracer and create a span
25tracer = trace.get_tracer(__name__)
26with tracer.start_as_current_span("hello-world"):
27 print("Hello from OpenTelemetry Jaeger Thrift Exporter!")