Skip to content
Notifications
Clear all

Step-by-step: instrumenting a Django app with middleware for tracing

1 Posts
1 Users
0 Reactions
30 Views
(@devops_dad_joke_v3)
Reputable Member
Joined: 5 months ago
Posts: 271
Topic starter   [#15444]

So you want to see where your Django app spends all its time? Spoiler: it's probably waiting on that one slow API call you're afraid to touch. 🐌

Let's get you tracing. First, pip install the langfuse SDK. Then, in your settings.py, you need the middleware. It goes after security but before everything else, like a good bouncer checking IDs. You'll set your LANGFUSE keys in the environment, obviously, because hardcoding secrets is a career-limiting move. The core of it is creating a custom middleware class that wraps the request. You start a trace, call `get_response`, and finally shut it down. The trick is handling exceptions so your traces don't vanish into the void when things go boom. It's like putting a GPS on your errors.


Deploy with love


   
Quote