/greet
endpoint that demonstrates how to integrate TrueFoundry’s tracing capabilities.
1
Create Tracing Project, API Key and copy tracing code
Follow the instructions in Getting Started to create a tracing project, generate API key and copy the
tracing code.
2
Install Dependencies
First, you need to install the following
3
Add Tracing code to FastAPI application
For FastAPI applications, we need to add the
Traceloop.init()
call to the application and instrument the FastAPI app with OpenTelemetry.FastAPI Code
4
Run your application and view logged trace

5
Trace custom internal functions
OpenTelemetry’s FastAPI instrumentation automatically handles tracing for incoming HTTP requests to your ASGI app. It creates and completes spans for the request/response lifecycle without any additional setup.However, it does not automatically trace other parts of your application, such as internal function calls, outgoing HTTP requests to other services, background tasks or database queries.To trace such operations, you can use OpenTelemetry’s existing instrumentation libraries . For example, if your app makes HTTP requests using
httpx
, you can use the opentelemetry-instrumentation-httpx
package. The same GitHub repository provides instrumentation libraries for many popular Python frameworks and libraries.
For a broader overview of how to integrate these libraries into your app, refer to our Distributed Tracing guide, which also includes examples with httpx
instrumentation.If you’re working with custom internal logic that isn’t covered by existing instrumentation, you can use Traceloop’s decorators to manually trace specific functions.Here’s an example of adding tracing to an internal function using the @task
decorator:FastAPI Code
6
Run your application and view traces, including custom function spans
