-
Notifications
You must be signed in to change notification settings - Fork 648
/
jaeger_exporter_example.py
48 lines (39 loc) · 1.48 KB
/
jaeger_exporter_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
from opentelemetry import trace
from opentelemetry.ext import jaeger
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
tracer = trace.tracer_source().get_tracer(__name__)
# create a JaegerSpanExporter
jaeger_exporter = jaeger.JaegerSpanExporter(
service_name="my-helloworld-service",
# configure agent
agent_host_name="localhost",
agent_port=6831,
# optional: configure also collector
# collector_host_name="localhost",
# collector_port=14268,
# collector_endpoint="/api/traces?format=jaeger.thrift",
# username=xxxx, # optional
# password=xxxx, # optional
)
# create a BatchExportSpanProcessor and add the exporter to it
span_processor = BatchExportSpanProcessor(jaeger_exporter)
# add to the tracer factory
trace.tracer_source().add_span_processor(span_processor)
# create some spans for testing
with tracer.start_as_current_span("foo") as foo:
time.sleep(0.1)
foo.set_attribute("my_atribbute", True)
foo.add_event("event in foo", {"name": "foo1"})
with tracer.start_as_current_span(
"bar", links=[trace.Link(foo.get_context())]
) as bar:
time.sleep(0.2)
bar.set_attribute("speed", 100.0)
with tracer.start_as_current_span("baz") as baz:
time.sleep(0.3)
baz.set_attribute("name", "mauricio")
time.sleep(0.2)
time.sleep(0.1)