This is a sample app to demonstrate how to instrument Python FastAPI Uvicorn app with Datadog, Elastic, New Relic and OpenTelemetry. It contains source code for the FastAPI Uvicorn app which interacts with various services like Redis, MySQL, etc. to demonstrate tracing for these services. This repository has a docker compose file to set up all these services conveniently.
The code is organized into multiple branches. The main branch has the FastAPI Uvicorn app without any instrumentation. Other branches then build upon the main branch to add specific instrumentations as below:
Branch | Instrumentation | Code changes for instrumentation |
---|---|---|
main | None | - |
datadog | Datadog | main...datadog |
elastic | Elastic | main...elastic |
newrelic | New Relic | main...newrelic |
otel | OpenTelemetry | main...otel |
Clone this repository and go to the project directory. Then run the following commands
python3 -m venv .
source ./bin/activate
pip install -r requirements.txt
docker compose up --build
FastAPI app will now be available at http://localhost:8000
.
The app has various API endpoints to demonstrate integrations with Redis, MySQL, etc. Check out main.py for the list of API endpoints.
Please feel free to raise PR for any enhancements - additional service integrations, library version updates, documentation updates, etc.