OpenTracing Shim¶
This example shows how to use the opentelemetry-opentracing-shim package to interact with libraries instrumented with opentracing-python.
The included rediscache
library creates spans via the OpenTracing Redis
integration,
redis_opentracing.
Spans are exported via the Jaeger exporter, which is attached to the
OpenTelemetry tracer.
The source files required to run this example are available here.
Installation¶
Jaeger¶
Start Jaeger
docker run --rm \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 16686:16686 \
jaegertracing/all-in-one:1.13 \
--log-level=debug
Redis¶
Install Redis following the instructions.
Make sure that the Redis server is running by executing this:
redis-server
Python Dependencies¶
Install the Python dependencies in requirements.txt
pip install -r requirements.txt
Alternatively, you can install the Python dependencies separately:
pip install \
opentelemetry-api \
opentelemetry-sdk \
opentelemetry-exporter-jaeger \
opentelemetry-opentracing-shim \
redis \
redis_opentracing
Run the Application¶
The example script calculates a few Fibonacci numbers and stores the results in
Redis. The script, the rediscache
library, and the OpenTracing Redis
integration all contribute spans to the trace.
To run the script:
python main.py
After running, you can view the generated trace in the Jaeger UI.
Jaeger UI¶
Open the Jaeger UI in your browser at http://localhost:16686 and view traces for the “OpenTracing Shim Example” service.
Each main.py
run should generate a trace, and each trace should include
multiple spans that represent calls to Redis.
Note that tags and logs (OpenTracing) and attributes and events (OpenTelemetry) from both tracing systems appear in the exported trace.