Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

raven.contrib.celery.register_logger_signal ignores subclasses of SentryHandler #961

@mpistrang

Description

@mpistrang

raven.contrib.celery.register_logger_signal attempts to find an existing handler to add a CeleryFilter to. It only considers existing handlers that are of type: raven.handlers.logging.SentryHandler. This means that if a subclass of this handler is found (such as raven.contrib.django.handlers.SentryHandler) the existing handler is ignored and a brand new handler with default settings is added, resulting in two potentially duplicate handlers.

The fix for this would be to change the type check here to an isinstance check.

I'm interested in submitting a PR for this with tests, if this change is considered appropriate.

Here is the skeleton of a test that would help cover this:

def test_subclassed_handler_updated(self):
    client = InMemoryClient()
    register_logger_signal(client)

    class CustomHandler(SentryHandler):
        pass

    root = logging.getLogger()
    handler = CustomHandler(client)
    root.addHandler(handler)

    celery.signals.after_setup_logger.send(
        sender=None, logger=root,
        loglevel=logging.WARNING, logfile=None,
        format=u'', colorize=False,
    )

    assert len(root.handlers) == 1

    handler = root.handlers[0]
    assert isinstance(handler, CustomHandler)

    assert len(handler.filters) == 1

    _filter = handler.filters[0]
    assert isinstance(_filter, CeleryFilter)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions