Tracing FastAPI applications
Tracing helps you understand what’s happening under the hood when an api is called. You get to understand the path, context used, latency taken when you run your fast api using TrueFoundry’s tracing functionality.
TrueFoundry enhances FastAPI applications with powerful observability features, offering real-time monitoring of API requests, response times, and performance metrics. By integrating with TrueFoundry’s tracing, metrics collection, and error detection capabilities, you gain deep insights into how your FastAPI endpoints are performing, where bottlenecks occur, and how to optimize your API workflows. Additionally, TrueFoundry provides end-to-end traceability for your API-driven systems, making your FastAPI implementations more transparent, reliable, and scalable.
setup requirements.txt:
Install requirements:
Setup environment variables:
Add the necessary environment variables to enable tracing. You can create a .env
file for this example
Create a Tracing Project
Follow the steps to create a tracing project here to get the tracing project FQN.
Generate API Key
Generate a API Key here. This can be a Person Access Token or Virtual Account Token which has access to the ML Repo of the Tracing Project you created.
Demo FastAPI
The following is a simple FastAPI application that demonstrates how to integrate TrueFoundry’s tracing capabilities. It includes a basic /greet
endpoint that returns a Hi there, wishing you a great day!
message, with OpenTelemetry instrumentation enabled for tracing.