API request tracing with NextJS, Nginx and Django

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. There is Datadog but for now I want a django lightweight solution.

Thanks!

django-silk

it is usefull in ur case -lightweight -Native -no heavy setu

let me know u want a setup for that or u can figureout

Additionally to the already recommended Django middleware, you can log the following nginx internal variables:

  • $upstream_connect_time (the time taken to establish a connection with an upstream application server);
  • $upstream_response_time (the time from establishing a connection to an upstream server until the last byte of the response body is received from that server);
  • $request_time (represents the total time elapsed for a request, from the first byte read from the client to the last byte of the response body sent).
Вернуться на верх