Django / Sentry Integration - No events Reported

I can not for the life of me get 500’s in my django app to create events on sentry.

I’m following the new sdk django integration instructions here. I’ve created a view that triggers the divide by zero error. In production I load the url and get a 500 for sure. I have another 500 from a different error of mine I’ve tried as well.

These show up in my logs, but they do not show up in sentry.

When I run the python-based Verifying Your Setup command in the django command line shell:

sentry_sdk.capture_exception(Exception("This is an example of an error message."))

it does show up in sentry. So I know that my settings are importing the correct dsn.

I had thought my issue might be related to this question, but the answer in this question makes not sense to me.

I really want sentry to work, I’ve used it on a client project and I don’t know what the is wrong with it. I’m frustrated with what should be a simple configuration of this tool.

Here is my logging definition from settings.py:

MIN_LOGGING_LEVEL = 'ERROR'
MIN_DJANGO_LEVEL = 'ERROR'

LOGGING = {
'version': 1,
'disable_existing_loggers': False,  # keep Django's default loggers
'formatters': {
    'verbose': {
        'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
    },
    'simple': {
        'format': '%(levelname)s %(message)s'
    },
    'timestampthread': {
        'format': "%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] [%(name)-20.20s]  %(message)s",
    },
},
'handlers': {
    'logfile': {
        'level': MIN_LOGGING_LEVEL,  # this level or higher goes to the log file
        'class': 'logging.handlers.RotatingFileHandler',
        'filename': LOG_FILE_PATH,
        'maxBytes': 100 * 10 ** 6,  # will 50 MB do?
        'backupCount': 3,  # keep this many extra historical files
        'formatter': 'timestampthread'
    },
    'console': {
        'level': MIN_LOGGING_LEVEL,  # this level or higher goes to the console
        'class': 'logging.StreamHandler',
    },
},
'loggers': {
    'django': {  # configure all of Django's loggers
        'handlers': ['logfile', 'console'],
        'level': MIN_DJANGO_LEVEL,  # this level or higher goes to the console
        'propagate': False,  # don't propagate further, to avoid duplication
    },
    # root configuration – for all of our own apps
    # (feel free to do separate treatment for e.g. brokenapp vs. sth else)
    '': {
        'handlers': ['logfile', 'console'],
        'level': MIN_LOGGING_LEVEL,  # this level or higher goes to the console,
    },
},

}

1 Like

Hi, could you post the version of Django you use and which WSGI server you use?

Hey there, I’m running Django 2.5 and uWSGI 2.0.18.

Could you initialize the SDK with init(debug=True)? This should print a lot of information to stdout/err that might indicate internal errors.

were you able to get this to work?? i’m in the exact same situation. The python-based error shows up, but I can’t get the 500 error from /sentry-debug/ to show up. I’d appreciate any help anyone can provide before I’m forced to ditch Sentry for something else.

1 Like

Same problem here.

My on-prem sentry works out of the box with other languages and frameworks.

On django with the latest sdk I get the following messages after a GET on /sentry-debug/:

DEBUG: Sending event, type:null level:error event_id:94377118d84b40be8e6d48943227588c project:2 host:xxx.xxxxxx.xyz
DEBUG:sentry_sdk.errors:Sending event, type:null level:error event_id:94377118d84b40be8e6d48943227588c project:2 host:xxx.xxxxxx.xyz
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): xxx.xxxxxx.xyz:443

But Sentry never receives anything.

Same here. Please, respond.

FYI: The old raven integration works for me. New sentry-sdk doesn’t.

Everybody who has this issue, please report, at least

  1. Django version and Django-related libraries used (REST framework etc) plus their versions
  2. How you trigger the error
  3. output with init(debug=True, ...)

Without this I cannot do anything.

Strange, it works with debug=True!
Init log with debug:

 [sentry] DEBUG: Setting up integrations (with default = True)
 [sentry] DEBUG: Setting up previously not enabled integration django
 [sentry] DEBUG: Setting up previously not enabled integration logging
 [sentry] DEBUG: Setting up previously not enabled integration stdlib
 [sentry] DEBUG: Setting up previously not enabled integration excepthook
 [sentry] DEBUG: Setting up previously not enabled integration dedupe
 [sentry] DEBUG: Setting up previously not enabled integration atexit
 [sentry] DEBUG: Setting up previously not enabled integration modules
 [sentry] DEBUG: Setting up previously not enabled integration argv
 [sentry] DEBUG: Setting up previously not enabled integration threading
 [sentry] DEBUG: Enabling integration django
 [sentry] DEBUG: Enabling integration logging
 [sentry] DEBUG: Enabling integration stdlib
 [sentry] DEBUG: Enabling integration excepthook
 [sentry] DEBUG: Enabling integration dedupe
 [sentry] DEBUG: Enabling integration atexit
 [sentry] DEBUG: Enabling integration modules
 [sentry] DEBUG: Enabling integration argv
 [sentry] DEBUG: Enabling integration threading

Event:

[sentry] DEBUG: Sending event, type:null level:error event_id:e12c4da44e2e4376be81111111111111 project:11111111 host:11111111.ingest.sentry.io
Internal Server Error: /aaa
Traceback (most recent call last):
  File ".venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File ".venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File ".venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File ".venv/lib/python3.8/site-packages/sentry_sdk/integrations/django/views.py", line 52, in callback
    return old_callback(*args, **kwargs)
  File "prj/prj/urls.py", line 12, in aaaa
    division_by_zero = 1 / 0
ZeroDivisionError: division by zero

The problem is fixed with send_default_pii=False!

Can someone please address this? Your SDK is broken for django. send_default_pii doesn’t help.

Ugh, digging through Sentry, It seems like sentry is rate limiting 100% of my requests.

It works only in case DEBUG = True !!
Any solutions please ?