Search code examples
pythondjangoherokupycharmtrace

How to trace code in a Heroku production system


My Python/Django code behaves different in the heroku production code, than on my development machine.

I would like to debug/trace it.

Since it runs on Heroku. AFAIK I can't insert import pydevd_pycharm; pydevd_pycharm.settrace(... into the code.

I use PyCharm.

But I don't need a fancy GUI. A command-line tool would be fine, too.

I would be happy if I could see all lines which get executed during a particular http request.

How to solve this for production systems?


Solution

  • In order to understand the difference between your local development environment and the Heroku production I would first deploy the application on another Heroku Dyno, for example a Free Dyno which you can easily create and manage.
    You can then integrate the tools you want and add the log statements as needed.

    Even if you are able to debug/inspect the production runtime it is very important to be able to test on production-like systems to capture problems early and investigate problems without guessing.

    On the Prod system you have limited options to debug the application:

    • consider code changes (i.e. add logging stamements) but as you have pointed out this involves PRs and a new release
    • debugger: connect your favourite debugger (i.e. PyCharm) to the remote application. This is something that (almost) no one does (given the security aspects and the likely impact on the application performance) and I doubt your system admins/DevOps would agree