atomAltera
atomAltera

Reputation: 1781

Is there any solution for delayed python debugging?

I have floating error on Django server in production, it does not causes exceptions, only some wrong behaviour. But I can't reproduce it on my locale machine; So I need to debug it on server side. Are there any tools, that can log all states of all variables so then I could replay problematic requests and figure out what behaves wrong?

Upvotes: 0

Views: 37

Answers (1)

Robert Townley
Robert Townley

Reputation: 3574

I agree with Taras' suggestion that Sentry is a great thing to install. Unfortunately, if the issue isn't generating exceptions (or INFO or WARN messages) then it won't catch the issue on its own.

I'd suggest that (if you haven't already done so) implementing sentry logging to your views: https://raven.readthedocs.io/en/stable/integrations/django.html

Once you've added Sentry to your production app, you can add code like the following into your views:

def my_view(request):
    if some_condition:
        foo = 12
    else:
        foo = 15
    logger.info('Line 45 of the Login view', exc_info=True, extra={
        'request': request,
        'myvar': foo,  # A variable you're interested in 
    })

Then, if you visit the page on production, it will generate a log message that you can view in sentry.

Side Note Once you've determined what your particular error is here, it might be worth examining what's behind you not being able to reproduce the issue locally. This inevitably happens to everyone, but it's a good thing to minimize. Some techniques for doing so include:

  1. Using django-environ to have your settings.py files look similar/identical
  2. Restoring your local databases from one of your production database backups
  3. Limiting code that detects and behaves differently in prod/dev environments to just the settings.py file.
  4. Using docker to keep your local/prod instances nearly-identical.

Upvotes: 2

Related Questions