-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sebastienbeau
- Loading branch information
Showing
17 changed files
with
716 additions
and
349 deletions.
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.