Skip to content

Commit

Permalink
global: remove support for raven
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Oct 12, 2023
1 parent ebdaebc commit 2b1eb04
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 366 deletions.
29 changes: 1 addition & 28 deletions invenio_logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Sentry can, in addition to the configuration variables listed, be further
configured with the folllowing configuration variables (see
`Raven <https://docs.sentry.io/clients/python/integrations/flask/#settings>`_
`Sentry <https://docs.sentry.io/platforms/python/integrations/flask/#configure>`_
for further details):
- ``SENTRY_AUTO_LOG_STACKS``
Expand All @@ -20,21 +20,10 @@
- ``SENTRY_MAX_LENGTH_LIST``
- ``SENTRY_MAX_LENGTH_STRING``
- ``SENTRY_NAME``
- ``SENTRY_PROCESSORS``
- ``SENTRY_RELEASE``
- ``SENTRY_SITE_NAME``
- ``SENTRY_TAGS``
- ``SENTRY_TRANSPORT``
.. note::
Celery does not deal well with the threaded Sentry transport, so you should
make sure that your **Celery workers** are configured with:
.. code-block:: python
SENTRY_TRANSPORT = 'raven.transport.http.HTTPTransport'
"""

# -------
Expand Down Expand Up @@ -85,9 +74,6 @@
# SENTRY
# ------

SENTRY_SDK = True
"""Use of sentry-python SDK, if false raven will be used. """

LOGGING_SENTRY_LEVEL = "WARNING"
"""Sentry logging level.
Expand Down Expand Up @@ -118,16 +104,3 @@

SENTRY_DSN = None
"""Set SENTRY_DSN environment variable."""

SENTRY_PROCESSORS = (
"raven.processors.SanitizePasswordsProcessor",
"invenio_logging.sentry.RequestIdProcessor",
)
"""Default Sentry event processors."""

SENTRY_TRANSPORT = "raven.transport.http.HTTPTransport"
"""Default Sentry transport.
Explicitly set due to Celery incompatibility with threaded transport
(see note above).
"""
72 changes: 2 additions & 70 deletions invenio_logging/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,12 @@
from __future__ import absolute_import, print_function

import logging
import warnings

import pkg_resources
import six
from flask import g
from werkzeug.utils import import_string

from . import config
from .ext import InvenioLoggingBase

try:
pkg_resources.get_distribution("raven")
from raven.processors import Processor
except pkg_resources.DistributionNotFound:

class Processor(object):
"""Dummy class in case Sentry is not installed.."""

def __init__(self, *args, **kwargs):
"""Do nothing."""
pass


class InvenioLoggingSentry(InvenioLoggingBase):
"""Invenio-Logging extension for Sentry."""
Expand Down Expand Up @@ -61,18 +45,15 @@ def install_handler(self, app):
logging_exclusions = None
if not app.config["LOGGING_SENTRY_PYWARNINGS"]:
logging_exclusions = (
"raven",
"gunicorn",
"south",
"sentry.errors",
"django.request",
"dill",
"py.warnings",
)
if app.config["SENTRY_SDK"]:
self.install_sentry_sdk_handler(app, logging_exclusions, level)
else:
self.install_raven_handler(app, logging_exclusions, level)

self.install_sentry_sdk_handler(app, logging_exclusions, level)

# Werkzeug only adds a stream handler if there's no other handlers
# defined, so when Sentry adds a log handler no output is
Expand Down Expand Up @@ -113,59 +94,10 @@ def install_sentry_sdk_handler(self, app, logging_exclusions, level):
with configure_scope() as scope:
scope.level = level

def install_raven_handler(self, app, logging_exclusions, level):
"""Install raven log handler."""
warnings.warn(
"The Raven library will be depricated.", PendingDeprecationWarning
)
from raven.contrib.celery import register_logger_signal, register_signal
from raven.contrib.flask import Sentry
from raven.handlers.logging import SentryHandler

cls = app.config["LOGGING_SENTRY_CLASS"]
if cls:
if isinstance(cls, six.string_types):
cls = import_string(cls)
else:
cls = Sentry
sentry = cls(
app,
logging=True,
level=level,
logging_exclusions=logging_exclusions,
)
app.logger.addHandler(SentryHandler(client=sentry.client, level=level))

# Capture warnings from warnings module
if app.config["LOGGING_SENTRY_PYWARNINGS"]:
self.capture_pywarnings(SentryHandler(sentry.client))

# Setup Celery logging to Sentry
if app.config["LOGGING_SENTRY_CELERY"]:
try:
register_logger_signal(sentry.client, loglevel=level)
except TypeError:
# Compatibility mode for Raven<=5.1.0
register_logger_signal(sentry.client)
register_signal(sentry.client)

def add_request_id_sentry_python(self, event, hint):
"""Add the request id as a tag."""
if g and hasattr(g, "request_id"):
tags = event.get("tags") or []
tags.append(["request_id", g.request_id])
event["tags"] = tags
return event


class RequestIdProcessor(Processor):
"""Sentry event request processor for adding the request id as a tag."""

def process(self, data, **kwargs):
"""Process event data."""
data = super(RequestIdProcessor, self).process(data, **kwargs)
if g and hasattr(g, "request_id"):
tags = data.get("tags", {})
tags["request_id"] = g.request_id
data["tags"] = tags
return data
35 changes: 0 additions & 35 deletions invenio_logging/sentry6.py

This file was deleted.

6 changes: 1 addition & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ tests =
pytest-invenio>=1.4.2
iniconfig>=1.1.1
sphinx>=4.5
raven[flask]>=6
sentry-sdk[flask]>=1.0.0
# Kept for backwards compatibility
docs =
sentry =
raven[flask]>=6
sentry-sdk =
sentry_sdk =
sentry-sdk[flask]>=1.0.0

[options.entry_points]
Expand Down
Loading

0 comments on commit 2b1eb04

Please sign in to comment.