This repository was archived by the owner on Oct 19, 2023. It is now read-only.
forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
executable file
·46 lines (36 loc) · 1.53 KB
/
main.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
#!/usr/bin/env python
from opentelemetry import trace
from opentelemetry.ext import opentracing_shim
from opentelemetry.ext.jaeger import JaegerSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from rediscache import RedisCache
# Configure the tracer using the default implementation
trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
tracer_provider = trace.tracer_provider()
# Configure the tracer to export traces to Jaeger
jaeger_exporter = JaegerSpanExporter(
service_name="OpenTracing Shim Example",
agent_host_name="localhost",
agent_port=6831,
)
span_processor = SimpleExportSpanProcessor(jaeger_exporter)
tracer_provider.add_span_processor(span_processor)
# Create an OpenTracing shim. This implements the OpenTracing tracer API, but
# forwards calls to the underlying OpenTelemetry tracer.
opentracing_tracer = opentracing_shim.create_tracer(tracer_provider)
# Our example caching library expects an OpenTracing-compliant tracer.
redis_cache = RedisCache(opentracing_tracer)
# Appication code uses an OpenTelemetry Tracer as usual.
tracer = trace.get_tracer(__name__)
@redis_cache
def fib(number):
"""Get the Nth Fibonacci number, cache intermediate results in Redis."""
if number < 0:
raise ValueError
if number in (0, 1):
return number
return fib(number - 1) + fib(number - 2)
with tracer.start_as_current_span("Fibonacci") as span:
span.set_attribute("is_example", "yes :)")
fib(4)