# trace all my code of an http request (like \`set -x\`)

**URL:** <https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410>\
**Category:** Using Django\
**Created:** [April 7, 2021, 9:05am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410 "2021-04-07T09:05:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![guettli](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/guettli/32/1896_2.png) [@guettli](https://forum.djangoproject.com/u/guettli)\
**Post date:** [April 7, 2021, 9:05am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/1 "2021-04-07T09:05:05Z")

</div>

I am new to a huge code base, and to better understand what is going on, I would love to see every line which gets executed during one http request.

similar to `set -x` on the shell.

I would like to exclude the details of the python standard library and of the django framework. I would like to see only my code.

I googled a bit. I found this debug-toolbar-plugin, but it is unclear how to install it:

> **[mikekeda/django-debug-toolbar-line-profiler](https://github.com/mikekeda/django-debug-toolbar-line-profiler)**
>
> Contribute to mikekeda/django-debug-toolbar-line-profiler development by creating an account on GitHub.

Is there a simple way to print every line of my code which gets executed during a http request?

This is only needed for development (runserver).

---

<div class="post-metadata">

**Author:** ![theRealBithive](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/therealbithive/32/3616_2.png) [@theRealBithive](https://forum.djangoproject.com/u/theRealBithive)\
**Post date:** [April 7, 2021, 9:21am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/2 "2021-04-07T09:21:11Z")

</div>

If you want to see how a particular piece of code is executed you can use breakpoint() in the code which will give you a pbd shell:

> **[PEP 553 -- Built-in breakpoint()](https://www.python.org/dev/peps/pep-0553/)**
>
> The official home of the Python Programming Language

---

<div class="post-metadata">

**Author:** ![guettli](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/guettli/32/1896_2.png) [@guettli](https://forum.djangoproject.com/u/guettli)\
**Post date:** [April 7, 2021, 10:37am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/3 "2021-04-07T10:37:51Z")

</div>

breakpoint() is cool, but does not help me in my current context. I am new to a huge legacy code base, and i have no clue which view method handles this request.

---

<div class="post-metadata">

**Author:** ![guettli](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/guettli/32/1896_2.png) [@guettli](https://forum.djangoproject.com/u/guettli)\
**Post date:** [April 7, 2021, 10:48am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/4 "2021-04-07T10:48:31Z")

</div>

BTW, I found a way to install the django-debug-toolbar-line-profiler. See: [How to install this fork? · Issue #5 · mikekeda/django-debug-toolbar-line-profiler · GitHub](https://github.com/mikekeda/django-debug-toolbar-line-profiler/issues/5)

Nevertheless I am curious how you would solve this (log/print/trace all lines which get executed during a http request)

---

<div class="post-metadata">

**Author:** ![theRealBithive](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/therealbithive/32/3616_2.png) [@theRealBithive](https://forum.djangoproject.com/u/theRealBithive)\
**Post date:** [April 7, 2021, 11:17am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/5 "2021-04-07T11:17:34Z")

</div>

> [@guettli](#):
>
> breakpoint() is cool, but does not help me in my current context. I am new to a huge legacy code base, and i have no clue which view method handles this request

I would use the inspection tool of the browser and see to which urls it connects. The endpoint has to be somewhere in `urls.py` - this will lead to the view that is used. From there I would look up which Models are involved or which other methods are used.  
There could be some Middleware involved but this must be listed in the `settings.py` file and all request will go through it.

Yeah so in short: Find out which URLs are triggered; look them up in the project and find the associated views to them. This will lead to Models, Functions and Templates that are used. Debug them with Tests and Breakpoints.

This project sounds interesting.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 7, 2021, 12:33pm UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/6 "2021-04-07T12:33:54Z")

</div>

You really don’t want to do that (print _all_ lines which get executed during an http request). The volume of output, and the interleaving of code from all the function calls would be too much to try to comprehend when you include all the Django and Python libraries involved.

I agree with the answer from @theRealBithive - the easiest way to start understanding this is start from the root urls.py file identified in the settings, and see where the chain of events takes you from there.

---

<div class="post-metadata">

**Author:** ![guettli](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/guettli/32/1896_2.png) [@guettli](https://forum.djangoproject.com/u/guettli)\
**Post date:** [April 8, 2021, 8:37am UTC](https://forum.djangoproject.com/t/trace-all-my-code-of-an-http-request-like-set-x/7410/7 "2021-04-08T08:37:08Z")

</div>

[Python Hunter](https://github.com/ionelmc/python-hunter) has a cool simple domain-lanuage for filtering lines. So you can easily trace only the lines you are interested in.
