-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[14.0][MIG] sentry: migrate sentry-raven to new api sentry-sdk #2254
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aecff99
[IMP] sentry: migrate sentry-raven to new api sentry-sdk
fernandahf 8277840
[FIX] sentry: Coerce numerical config values
paradoxxxzero baed834
[FIX] sentry: Patch odoo.service.server wsgi app
paradoxxxzero 1a6829d
[FIX] sentry: warn about sentry_transport only if it is specified in …
paradoxxxzero 4c413fa
[FIX] sentry: Fix bad ported version
paradoxxxzero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ odoorpc | |
openpyxl | ||
openupgradelib | ||
pysftp | ||
raven | ||
sentry_sdk | ||
unidecode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,20 @@ Odoo. | |
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
The module can be installed just like any other Odoo module, by adding the | ||
module's directory to Odoo *addons_path*. In order for the module to correctly | ||
wrap the Odoo WSGI application, it also needs to be loaded as a server-wide | ||
module. This can be done with the ``server_wide_modules`` parameter in your | ||
Odoo config file or with the ``--load`` command-line parameter. | ||
|
||
This module additionally requires the sentry-sdk Python package to be available on | ||
the system. It can be installed using pip:: | ||
|
||
pip install sentry-sdk | ||
|
||
Configuration | ||
============= | ||
|
||
|
@@ -67,16 +81,6 @@ configuration file: | |
odoo.exceptions.Warning, | ||
odoo.exceptions.except_orm`` | ||
|
||
``sentry_processors`` A string of comma-separated processor classes which will be applied ``raven.processors.SanitizePasswordsProcessor, | ||
on an event before sending it to Sentry. odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor`` | ||
|
||
``sentry_transport`` Transport class which will be used to send events to Sentry. ``threaded`` | ||
Possible values: *threaded*: spawns an async worker for processing | ||
messages, *synchronous*: a synchronous blocking transport; | ||
*requests_threaded*: an asynchronous transport using the *requests* | ||
library; *requests_synchronous* - blocking transport using the | ||
*requests* library. | ||
|
||
``sentry_include_context`` If enabled, additional context data will be extracted from current ``True`` | ||
HTTP request and user session (if available). This has no effect | ||
for Cron jobs, as no request/session is available inside a Cron job. | ||
|
@@ -94,11 +98,14 @@ configuration file: | |
============================= ==================================================================== ========================================================== | ||
|
||
Other `client arguments | ||
<https://docs.sentry.io/clients/python/advanced/#client-arguments>`_ can be | ||
<https://docs.sentry.io/platforms/python/configuration/>`_ can be | ||
configured by prepending the argument name with *sentry_* in your Odoo config | ||
file. Currently supported additional client arguments are: ``install_sys_hook, | ||
include_paths, exclude_paths, machine, auto_log_stacks, capture_locals, | ||
string_max_length, list_max_length, site, include_versions, environment``. | ||
file. Currently supported additional client arguments are: ``with_locals, | ||
max_breadcrumbs, release, environment, server_name, shutdown_timeout, | ||
in_app_include, in_app_exclude, default_integrations, dist, sample_rate, | ||
send_default_pii, http_proxy, https_proxy, request_bodies, debug, | ||
attach_stacktrace, ca_certs, propagate_traces, traces_sample_rate, | ||
auto_enabling_integrations``. | ||
|
||
Example Odoo configuration | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
@@ -110,14 +117,15 @@ Below is an example of Odoo configuration file with *Odoo Sentry* options:: | |
sentry_enabled = true | ||
sentry_logging_level = warn | ||
sentry_exclude_loggers = werkzeug | ||
sentry_ignore_exceptions = odoo.exceptions.AccessDenied,odoo.exceptions.AccessError,odoo.exceptions.MissingError,odoo.exceptions.RedirectWarning,odoo.exceptions.UserError,odoo.exceptions.ValidationError,odoo.exceptions.Warning,odoo.exceptions.except_orm | ||
sentry_processors = raven.processors.SanitizePasswordsProcessor,odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor | ||
sentry_transport = threaded | ||
sentry_ignore_exceptions = odoo.exceptions.AccessDenied, | ||
odoo.exceptions.AccessError,odoo.exceptions.MissingError, | ||
odoo.exceptions.RedirectWarning,odoo.exceptions.UserError, | ||
odoo.exceptions.ValidationError,odoo.exceptions.Warning, | ||
odoo.exceptions.except_orm | ||
sentry_include_context = true | ||
sentry_environment = production | ||
sentry_auto_log_stacks = false | ||
sentry_odoo_dir = /home/odoo/odoo/ | ||
sentry_release = 1.3.2 | ||
sentry_odoo_dir = /home/odoo/odoo/ | ||
|
||
Usage | ||
===== | ||
|
@@ -127,7 +135,7 @@ above the configured Sentry logging level, no additional actions are necessary. | |
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/149/13.0 | ||
:target: https://runbot.odoo-community.org/runbot/149/14.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
@@ -163,6 +171,7 @@ Authors | |
* Mohammed Barsi | ||
* Versada | ||
* Nicolas JEUDY | ||
* Vauxoo | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
@@ -172,6 +181,11 @@ Contributors | |
* Naglis Jonaitis <[email protected]> | ||
* Atte Isopuro <[email protected]> | ||
|
||
Other credits | ||
~~~~~~~~~~~~~ | ||
|
||
* Vauxoo | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
|
@@ -185,6 +199,26 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose | |
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-barsi| image:: https://github.com/barsi.png?size=40px | ||
:target: https://github.com/barsi | ||
:alt: barsi | ||
.. |maintainer-naglis| image:: https://github.com/naglis.png?size=40px | ||
:target: https://github.com/naglis | ||
:alt: naglis | ||
.. |maintainer-versada| image:: https://github.com/versada.png?size=40px | ||
:target: https://github.com/versada | ||
:alt: versada | ||
.. |maintainer-moylop260| image:: https://github.com/moylop260.png?size=40px | ||
:target: https://github.com/moylop260 | ||
:alt: moylop260 | ||
.. |maintainer-fernandahf| image:: https://github.com/fernandahf.png?size=40px | ||
:target: https://github.com/fernandahf | ||
:alt: fernandahf | ||
|
||
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-barsi| |maintainer-naglis| |maintainer-versada| |maintainer-moylop260| |maintainer-fernandahf| | ||
|
||
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/14.0/sentry>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1 @@ | ||
# Copyright 2016-2017 Versada <https://versada.eu/> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from odoo.service import wsgi_server | ||
from odoo.tools import config as odoo_config | ||
|
||
from . import const | ||
from .logutils import LoggerNameFilter, OdooSentryHandler | ||
|
||
from collections import abc | ||
|
||
_logger = logging.getLogger(__name__) | ||
HAS_RAVEN = True | ||
try: | ||
import raven | ||
from raven.middleware import Sentry | ||
except ImportError: | ||
HAS_RAVEN = False | ||
_logger.debug('Cannot import "raven". Please make sure it is installed.') | ||
|
||
|
||
def get_odoo_commit(odoo_dir): | ||
"""Attempts to get Odoo git commit from :param:`odoo_dir`.""" | ||
if not odoo_dir: | ||
return | ||
try: | ||
return raven.fetch_git_sha(odoo_dir) | ||
except raven.exceptions.InvalidGitRepository: | ||
_logger.debug('Odoo directory: "%s" not a valid git repository', odoo_dir) | ||
|
||
|
||
def initialize_raven(config, client_cls=None): | ||
""" | ||
Setup an instance of :class:`raven.Client`. | ||
|
||
:param config: Sentry configuration | ||
:param client: class used to instantiate the raven client. | ||
""" | ||
enabled = config.get("sentry_enabled", False) | ||
if not (HAS_RAVEN and enabled): | ||
return | ||
|
||
if config.get("sentry_odoo_dir") and config.get("sentry_release"): | ||
_logger.debug( | ||
"Both sentry_odoo_dir and sentry_release defined, choosing sentry_release" | ||
) | ||
options = {} | ||
for option in const.get_sentry_options(): | ||
value = config.get("sentry_%s" % option.key, option.default) | ||
if isinstance(option.converter, abc.Callable): | ||
value = option.converter(value) | ||
options[option.key] = value | ||
|
||
level = config.get("sentry_logging_level", const.DEFAULT_LOG_LEVEL) | ||
exclude_loggers = const.split_multiple( | ||
config.get("sentry_exclude_loggers", const.DEFAULT_EXCLUDE_LOGGERS) | ||
) | ||
if level not in const.LOG_LEVEL_MAP: | ||
level = const.DEFAULT_LOG_LEVEL | ||
|
||
if not options.get("release"): | ||
options["release"] = config.get( | ||
"sentry_release", get_odoo_commit(config.get("sentry_odoo_dir")) | ||
) | ||
|
||
client_cls = client_cls or raven.Client | ||
client = client_cls(**options) | ||
handler = OdooSentryHandler( | ||
config.get("sentry_include_context", True), | ||
client=client, | ||
level=const.LOG_LEVEL_MAP[level], | ||
) | ||
if exclude_loggers: | ||
handler.addFilter( | ||
LoggerNameFilter(exclude_loggers, name="sentry.logger.filter") | ||
) | ||
raven.conf.setup_logging(handler) | ||
wsgi_server.application = Sentry(wsgi_server.application, client=client) | ||
|
||
client.captureMessage("Starting Odoo Server") | ||
return client | ||
|
||
|
||
sentry_client = initialize_raven(odoo_config) | ||
from .hooks import post_load |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are no rules regarding maintainers quantity, but maybe 5 maintainers is a little too much ?
CC : @OCA/community-maintainers