This project demonstrates how to add Distributed Tracing to a Python microscopic application using OpenTelemetry.
Tracing is essential in microservice architectures to monitor requests that bounce between multiple services. You can trace bottlenecks, see exact times taken for database operations, and visualize the call tree.
- FastAPI Backend: Emits tracing information (Spans and Traces) to the console using the
ConsoleSpanExporter. - Streamlit Frontend: Triggers requests to test the tracing in action.
# Install dependencies
pip install -r requirements.txt-
Start the Traced API Server:
python main.py
This starts the FastAPI server on port 8000.
-
Open a new terminal and run the Frontend Dashboard:
streamlit run app.py
-
Interact and Observe:
- Click the button on the Streamlit UI to trigger a request.
- Look at the terminal where
main.pyis running. You will see JSON blocks describing theSpan, identifying the duration of both the root request and the nested sub-traces (heavy_processing_task,db_query).