Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0.0 #70

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ on:
branches: master
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 3 * * 6'
- cron: "0 3 * * 6"
workflow_dispatch:
inputs:
reason:
description: 'Reason'
description: "Reason"
required: false
default: 'Manual trigger'
default: "Manual trigger"

jobs:
Tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
requirements-level: [pypi]
python-version: [3.8, 3.9]
requirements-level: [pypi]

env:
EXTRAS: tests
Expand Down
8 changes: 2 additions & 6 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
Changes
=======

Version 1.3.4 (released 2023-10-12)
Version 2.0.0 (released 2023-10-12)

- add back in setup sentry and sentry-sdk extras

Version 1.3.3 (released 2023-10-12)

- Adds `LOGGING_SENTRY_INIT_KWARGS` to allow extra config on sentry initialization
- removes support for raven

Version 1.3.2 (released 2022-02-28)

Expand Down
3 changes: 0 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ File System
Sentry
------

.. automodule:: invenio_logging.sentry6
:members:

.. automodule:: invenio_logging.sentry
:members:
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"https://docs.python.org/": None,
"python": ("https://docs.python.org/", None),
"flask": ("https://flask.palletsprojects.com/en/latest/", None),
"celery": ("https://docs.celeryproject.org/en/stable/", None),
}
Expand Down
2 changes: 1 addition & 1 deletion invenio_logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@

from __future__ import absolute_import, print_function

__version__ = "1.3.4"
__version__ = "2.0.0"

__all__ = ("__version__",)
33 changes: 2 additions & 31 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 All @@ -109,25 +95,10 @@
LOGGING_SENTRY_CLASS = None
"""Import path of sentry Flask extension class.

This allows you to customize the Sentry extension class. In particular if you
are logging to Sentry v6, you can set this to
:class:`invenio_logging.sentry6.Sentry6`."""
This allows you to customize the Sentry extension class."""

LOGGING_SENTRY_INIT_KWARGS = None
"""Pass extra options when initializing Sentry instance."""

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.

9 changes: 2 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers =
[options]
include_package_data = True
packages = find:
python_requires = >=3.7
python_requires = >=3.8
zip_safe = False
install_requires =
invenio-celery>=1.2.4
Expand All @@ -39,13 +39,8 @@ 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
Loading