Code Monkey home page Code Monkey logo

django-q-sentry's Introduction

django-q-sentry

A Django Q Error Reporter plugin adding Sentry support.

Before version 0.1.3 sentry raven was a dependency. After 0.1.3 sentry-sdk used as raven is being deprecated.

Installation

This plugin is intended to be included with Django Q as setuptools extra.

$ pip install django-q[sentry]

Or add django-q[sentry] to requirements.txt.

This plugin requires Django Q version 0.8.1 or greater.

Usage

Configure Sentry via the Django Q Q_CLUSTER dictionary in your Django project's settings.py. It is important that the sentry key be set in the error_reporter dictionary, as this name aligns with the project's entry point for this plugin. The only required configuration entry is your Sentry DSN.

Q_CLUSTER = {
    'error_reporter': {
        'sentry': {
            'dsn': 'https://******@sentry.io/<project>'
        }
    }
}

Please check the python sentry client configuration docs for more options. Additional key-value pairs defined in Q_CLUSTER['error_reporter']['sentry'] are passed directly as kwargs to instantiation of raven.Client.

django-q-sentry's People

Contributors

c-goosen avatar danielwelch avatar wtracyliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-q-sentry's Issues

Error when trying to install

Hi there,

I'm trying to follow the Installation instructions in the README, but I'm getting an error. Below is the output from pip install django-q[sentry]

(venv) Jordans-15-MBP:my_project jordan$ pip install django-q[sentry]
Requirement already satisfied: django-q[sentry] in ./venv/lib/python3.5/site-packages
Requirement already satisfied: arrow in ./venv/lib/python3.5/site-packages (from django-q[sentry])
Requirement already satisfied: django-picklefield in ./venv/lib/python3.5/site-packages (from django-q[sentry])
Requirement already satisfied: blessed in ./venv/lib/python3.5/site-packages (from django-q[sentry])
Requirement already satisfied: django>=1.8 in ./venv/lib/python3.5/site-packages (from django-q[sentry])
Collecting django-q-sentry>=0.1; extra == "sentry" (from django-q[sentry])
  Could not find a version that satisfies the requirement django-q-sentry>=0.1; extra == "sentry" (from django-q[sentry]) (from versions: )
No matching distribution found for django-q-sentry>=0.1; extra == "sentry" (from django-q[sentry])

I actually can't seem to find django-q-sentry on https://pypi.python.org so I'm thinking the issue might be that the package hasn't been published to PyPI yet? Any suggestions?

django-q-sentry tarball seems to be packaged incorrectly

Hi,

I am porting django-q-sentry as an optional dependency of django-q on FreeBSD, but I noticed that it packages from a directory called /home/goose and even contains a .venv directory. Commonly it should contain the source tree with an setup.py or a pyproject.toml.

$ tar tf django-q-sentry-0.1.6.linux-x86_64.tar.gz
./
./home/
./home/goose/
./home/goose/Development/
./home/goose/Development/django-q-sentry/
./home/goose/Development/django-q-sentry/.venv/
./home/goose/Development/django-q-sentry/.venv/lib/
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry/
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry/__init__.py
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry/__pycache__/
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry/__pycache__/__init__.cpython-39.pyc
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry/__pycache__/sentry.cpython-39.pyc
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry/sentry.py
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry-0.1.6-py3.9.egg-info/
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry-0.1.6-py3.9.egg-info/PKG-INFO
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry-0.1.6-py3.9.egg-info/SOURCES.txt
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry-0.1.6-py3.9.egg-info/dependency_links.txt
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry-0.1.6-py3.9.egg-info/requires.txt
./home/goose/Development/django-q-sentry/.venv/lib/python3.9/site-packages/django_q_sentry-0.1.6-py3.9.egg-info/top_level.txt

Internal django-q errors are not ignored

An attempt is made to ignore internal logging from Django-Q itself in

# Important to not log the logger.error nessages from django-q
# We only want to catch the exceptions, not the logger
ignore_logger('django-q')
. Introduced in #4.

This doesn't seem to work however: in Sentry I'm receiving ERROR log messages about failed tasks in Django (generated at https://github.com/django-q2/django-q2/blob/7fb7fca176eceb5112196b6620cd336a616124df/django_q/monitor.py#L57-L65)

After some research I'm now trying to suppress these in a Sentry before_send hook:

def before_send(event, hint):
    """Suppress certain events from being submitted to Sentry"""
    if "log_record" in hint:
        rec = hint["log_record"]
        if rec.name == "django-q":
            # See https://github.com/django-q2/django-q2/blob/7fb7fca176eceb5112196b6620cd336a616124df/django_q/monitor.py#L58  # noqa: E501
            logger.info("Suppressing Sentry event submission for Django-Q internals")
            return None

    return event

It would be nice if this would work out if the box.

django-q-sentry breaks normal Sentry integration

If you follow the current docs for using Sentry with Python/Django you will add something like the following code to your settings.py:

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn="https://[email protected]/1234",
    integrations=[DjangoIntegration()],
    traces_sample_rate=0.05,
    send_default_pii=True,
    release="[email protected]",
)

If you then follow the django-q-sentry docs, you will also add this:

Q_CLUSTER {
   # ...
   'error_reporter': {
        'sentry': {
            'dsn': SENTRY_DSN
        }
    }
}

The problem is that doing this will break your earlier config. In particular, I noticed that the performance tracing was not working at all - Sentry was not receiving any performance traces. When I disabled the error_report key in the Q_CLUSTER setting, it started working.

Digging it, it looks like django-q-sentry does its own call to sentry_sdk.init in

sentry_sdk.init(dsn, **kwargs)
which I presume is overriding my call, and breaking things.

With django-q-sentry disabled, it appears that Sentry works just fine for reporting crashes inside my tasks. So is django-q-sentry needed at all? Would it be best to deprecate this package?

extra configuration, eg. before_send

When configuring Sentry normally, one can pass the before send function to filter or manipulate events client side before sending to Sentry. Does the config json inside of the django q config for sentry accept the before_send field?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.