API request tracing with Django

Hi everyone,

I’m trying to measure the exact time spent in each stage of my API request flow — starting from the browser, through Nginx, into Django, then the database, and back out through Django and Nginx to the client.

Essentially, I want to capture timestamps and time intervals for:

  • When the browser sends the request

  • When Nginx receives it

  • When Django starts processing it

  • Time spent in the database

  • Django response time

  • Nginx response time

  • When the browser receives the response

Is there any Django package or recommended approach that can help log these timing metrics end-to-end? Currently I have to manually add timestamps in nginx conf file, django middleware, before and after the fetch call in the frontend.

Thanks!

You can use sentry to get tracing, profilling and error tracking for your Django project. It’s a paid software, but they have a nice free tier, and it’s a really good service, worth paying for.
You’ll still need something for the nginx part (if you really wish so, I think that you won’t have many performance bottlenecks from this part of your architecture).

1 Like

Hallo!
May be this is nice tool. Okay.
Let’s look thie2 sides. The first side its;s that Sentry/

And else - it’s good old the logging of python. Here everyone self could be write the script by logging of errors and the time (when was errors).
Then, we insert the string template in body of our script and then we will be get the: time, message of error.
String template

logging.Formatter(
        "[%(asctime)s.%(msecs)03d] %(levelname)s - %(name)s:%(lineno)d - %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S.%u",
    )

and log file

[2025-11-16 04:30:39.7.156] INFO - wink.tasks.task_load:22 - [task_on_upload_file]: Received notification
[2025-11-16 04:30:42.7.787] INFO - django.channels.server:181 - HTTP POST /api/v1/wink/cinema/ 201 [11.15, 127.0.0.1:64828]
[2025-11-16 04:30:49.7.229] INFO - django.channels.server:181 - HTTP GET /api/v1/wink/download/b6fe52d102d54560b8c84cd902cd9cef/ 200 [6.46, 127.0.0.1:64833]
[2025-11-16 04:30:49.7.238] ERROR - wink.winkClient:157 - AsyncHttpClient.requestERROR => Response.__init__() got an unexpected keyword argument 'content'
[2025-11-16 04:30:49.7.240] ERROR - asyncio:1833 - Task exception was never retrieved

This is the log file contains the default line and lines fom my text (how a mark) + error message.

Ehat benefits do we get from the sentry?

Well, you can most definitely look into the docs to view the best features. I don’t want this to be an adversiting for sentry, but the core feature is the error tracking.
Errors happen a lot on production systems, from a whole lot of different sources, solo relying in logging is not really a good option, specially when you have more than one source of logging output, and services spread across virtual containers on the cloud.
Take this screenshot as an example:


Here I can view the most recent errors, and warnings, how many and the last time this error happened. This is a lot of information already, plus I receive a notification whenever a new error show up. If I go in the error detail, I can see the entire traceback, queries, http requests, and also logging issued in that specific request. This helps me understand the error, and what can I do to prevent it or handle it.

Again, this is just one feature (the core one), it also deliver tracing and profilling.
You should give it a try if possible.

Hope that helps.

Ok/ May be you right.
and
If you use it now, what you can get by free tier? I mean - do you work in django/React (together) and this service by free tier?
Did i understand correctly what you mean under ‘free tier’ - it is tariff ? Simple. i can’t found the the page of prices. :- )) and Russian banks was removed from the swift : )))

And what is after - it when we will send the our project (and free tier) to the production? Delete his?

Here’s the pricing page: Plans and Pricing

I have a Django + React application, they’re 2 separate projects on sentry.

Sorry, didn’t get it.

then we receive the finished project. What do you do with it (at the completed of the work and project is sending to the production)?

Why?

Quite a few of the times on that list are things that you can’t do anything about anyway, so what is the reason for collecting the information? If you’re trying to optimize a page a profiler seems much more useful than any such timing information for example.