Skip to content

No request data with django #267

Closed

Description

@bluesurfer

I recently decided to switch from Raven to sentry-sdk version 0.7.3.

When an event was reported using Raven I use to have many useful tags (the URLs originating the error, the user browser/device, OS information and much more). All this comes out of the box without the need to include any scripts in the frontend.

Despite sentry-sdk has simplified the configuration process I find myself with a weaker error tracking system (fewer information on each event).

I am working on a Django project and followed the docs

Am I missing something?

Activity

  1. changed the title [-]Where are all the Raven (deprecated) default tags?[/-] [+]Where are all the Raven default tags?[/+] on Feb 19, 2019
  2. untitaker commented on Feb 19, 2019

    @untitaker
    Member

    The tags you see are generated serverside and are inferred from HTTP headers and the current URL. All of this should be there when you turn on the Django integration. We're using this for Sentry itself and it generally is supposed to work.

    From what you've told me it seems that you generally have no request data attached to your events. Could you paste the exact code you're using, and more importantly, where do you call init of the SDK?

  3. untitaker commented on Feb 24, 2019

    @untitaker
    Member

    @bluesurfer any update on this? This seems like a bug in the SDK, even if just a UX bug.

  4. bluesurfer commented on Feb 24, 2019

    @bluesurfer
    Author

    @untitaker oops, sorry for delay.. I just put the docs code (with init sentry) at the end of my settings file and I haven't defined any LOGGING configuration.

    From what you've told me it seems that you generally have no request data attached to your events.

    Yes, that's the issue. My previously working logging configuration with Raven was:

    # Raven
    # ------------------------------------------------------------------------------
    INSTALLED_APPS += ['raven.contrib.django.raven_compat']  # noqa F405
    MIDDLEWARE = ['raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware'] + MIDDLEWARE
    
    # Sentry
    # ------------------------------------------------------------------------------
    SENTRY_DSN = env('DJANGO_SENTRY_DSN')
    SENTRY_CLIENT = env('DJANGO_SENTRY_CLIENT', default='raven.contrib.django.raven_compat.DjangoClient')
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'root': {
            'level': 'WARNING',
            'handlers': ['sentry'],
        },
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s '
                          '%(process)d %(thread)d %(message)s'
            },
        },
        'handlers': {
            'sentry': {
                'level': 'ERROR',
                'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
            },
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'verbose'
            }
        },
        'loggers': {
            'django.db.backends': {
                'level': 'ERROR',
                'handlers': ['console'],
                'propagate': False,
            },
            'raven': {
                'level': 'DEBUG',
                'handlers': ['console'],
                'propagate': False,
            },
            'sentry.errors': {
                'level': 'DEBUG',
                'handlers': ['console'],
                'propagate': False,
            },
            'django.security.DisallowedHost': {
                'level': 'WARNING',
                'handlers': ['console', 'sentry'],
                'propagate': False,
            },
        },
    }
    
    SENTRY_CELERY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
    RAVEN_CONFIG = {
        'dsn': SENTRY_DSN
    }
    

    Than using sentry-sdk I simply replaced it with:

    import sentry_sdk
    from sentry_sdk.integrations.django import DjangoIntegration
    
    sentry_sdk.init(
        dsn=SENTRY_DSN,
        integrations=[DjangoIntegration()]
    )
    
  5. untitaker commented on Feb 24, 2019

    @untitaker
    Member

    Which version of Django and Python are you using?

  6. bluesurfer commented on Feb 24, 2019

    @bluesurfer
    Author

    @untitaker Django 2.1.7 with python 3.6.7.

    Also I am using Channels

  7. changed the title [-]Where are all the Raven default tags?[/-] [+]No request data with django[/+] on Apr 7, 2019
  8. bcollazo commented on May 22, 2019

    @bcollazo

    I am also experiencing the same thing. Very similar setup to the one described by @bluesurfer. The Raven Python setup included a 'Cookies' section as well as better 'User' information (these both seem to be Django request object information).

    I am using Django 1.11.20, Python 3.6.7 and was trying Sentry 0.8.0.

  9. bluesurfer commented on May 23, 2019

    @bluesurfer
    Author

    @bcollazo @untitaker I have some updates.

    I am following cookiecutter-django repository to lay down my project. It seems that with recent updates (also from sentry-sdk) the following configuration to me is working:

    # LOGGING
    # ------------------------------------------------------------------------------
    LOGGING = {
        "version": 1,
        "disable_existing_loggers": True,
        "formatters": {
            "verbose": {
                "format": "%(levelname)s %(asctime)s %(module)s "
                          "%(process)d %(thread)d %(message)s"
            }
        },
        "handlers": {
            "console": {
                "level": "DEBUG",
                "class": "logging.StreamHandler",
                "formatter": "verbose",
            }
        },
        "loggers": {
            "django.db.backends": {
                "level": "ERROR",
                "handlers": ["console"],
                "propagate": False,
            },
            # Errors logged by the SDK itself
            "sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False},
            "django.security.DisallowedHost": {
                "level": "ERROR",
                "handlers": ["console"],
                "propagate": False,
            },
        },
    }
    
    # Sentry
    # ------------------------------------------------------------------------------
    SENTRY_DSN = env("SENTRY_DSN")
    SENTRY_LOG_LEVEL = env.int("DJANGO_SENTRY_LOG_LEVEL", logging.INFO)
    
    sentry_logging = LoggingIntegration(
        level=SENTRY_LOG_LEVEL,  # Capture info and above as breadcrumbs
        event_level=logging.ERROR,  # Send no events from log messages
    )
    
    sentry_sdk.init(
        dsn=SENTRY_DSN,
        integrations=[sentry_logging, DjangoIntegration(), CeleryIntegration()],
    )
    

    Therefore to me this issue could be closed.

  10. untitaker commented on May 23, 2019

    @untitaker
    Member

    Ah that's neat, I wasn't aware of cookiecutter/cookiecutter-django#1820!

    Tbh I think it's highly unlikely that @bluesurfer has the same actual problem as you, @bcollazo. Could you open a new issue with more information?

  11. anush0247 commented on May 31, 2019

    @anush0247

    We are also facing the same issue

    We are not getting the Django request data info in sentry console with updated sentry SDK

    With old raven Django client, there is no issue about getting request data in sentry

    We are getting request data in sentry console, only if there is some exception raised before our program did access the request.body

    We are getting can't read requst data once its already read error at sentry_sdk.integrations.django.DjangoRequestExtractor#raw_data

  12. untitaker commented on May 31, 2019

    @untitaker
    Member

    @anush0247 could you link an event that exhibits this behavior?

  13. anush0247 commented on Jun 19, 2019

    @anush0247

    @untitaker any update ?

  14. untitaker commented on Jun 19, 2019

    @untitaker
    Member
  15. untitaker commented on Jun 19, 2019

    @untitaker
    Member

    PR at #393... I am pretty sure the issue is with django-rest-framework and not Django.

  16. untitaker commented on Jun 21, 2019

    @untitaker
    Member

    0.9.1 is out with this fix :) I hope it fixes all cases, but certainly should fix a few of them

  17. anush0247 commented on Jun 25, 2019

    @anush0247

    @untitaker I am getting circular settings import issue after upgrading to 0.9.1

    please check below stack trace once

    File ".venv/local/lib/python2.7/site-packages/sentry_sdk/hub.py", line 74, in init
        client = Client(*args, **kwargs)
      File ".venv/local/lib/python2.7/site-packages/sentry_sdk/client.py", line 88, in __init__
        options["integrations"], with_defaults=options["default_integrations"]
      File ".venv/local/lib/python2.7/site-packages/sentry_sdk/integrations/__init__.py", line 80, in setup_integrations
        type(integration).setup_once()
      File ".venv/local/lib/python2.7/site-packages/sentry_sdk/integrations/django/__init__.py", line 128, in setup_once
        from rest_framework.views import APIView  # type: ignore
      File ".venv/local/lib/python2.7/site-packages/rest_framework/views.py", line 18, in <module>
        from rest_framework import exceptions, status
      File ".venv/local/lib/python2.7/site-packages/rest_framework/exceptions.py", line 17, in <module>
        from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
      File ".venv/local/lib/python2.7/site-packages/rest_framework/utils/serializer_helpers.py", line 9, in <module>
        from rest_framework.compat import unicode_to_repr
      File ".venv/local/lib/python2.7/site-packages/rest_framework/compat.py", line 156, in <module>
        from django.contrib.postgres import fields as postgres_fields
      File ".venv/local/lib/python2.7/site-packages/django/contrib/postgres/fields/__init__.py", line 1, in <module>
        from .array import *  # NOQA
      File ".venv/local/lib/python2.7/site-packages/django/contrib/postgres/fields/array.py", line 3, in <module>
        from django.contrib.postgres import lookups
      File ".venv/local/lib/python2.7/site-packages/django/contrib/postgres/lookups.py", line 4, in <module>
        from .search import SearchVector, SearchVectorExact, SearchVectorField
      File ".venv/local/lib/python2.7/site-packages/django/contrib/postgres/search.py", line 47, in <module>
        class SearchVector(SearchVectorCombinable, Func):
      File ".venv/local/lib/python2.7/site-packages/django/contrib/postgres/search.py", line 50, in SearchVector
        _output_field = SearchVectorField()
      File ".venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 172, in __init__
        self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
      File ".venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
        self._setup(name)
      File ".venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
        self._wrapped = Settings(settings_module)
      File ".venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 129, in __init__
        raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
    django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
    
  18. untitaker commented on Jun 25, 2019

    @untitaker
    Member

    @anush0247 the issue has been reported as #397 and is fixed in 0.9.2 :)

  19. anush0247 commented on Jun 26, 2019

    @anush0247

    @untitaker thank you it's working now

  20. ghost added on Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions