Skip to content

Commit b9a06fb

Browse files
committed
[19.0][MIG] sentry
1 parent 401a34f commit b9a06fb

28 files changed

+1893
-0
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# generated from manifests external_dependencies
2+
sentry_sdk>=2.0.0,<=2.22.0

sentry/README.rst

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
======
6+
Sentry
7+
======
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:e2f1d0bc83bf031b61df768de9c2f6d4f1feb303facf171a8d1889fc6a2635ca
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
22+
:alt: License: AGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
24+
:target: https://github.com/OCA/server-tools/tree/19.0/sentry
25+
:alt: OCA/server-tools
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-sentry
28+
:alt: Translate me on Weblate
29+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
This module allows painless `Sentry <https://sentry.io/>`__ integration
36+
with Odoo.
37+
38+
**Table of contents**
39+
40+
.. contents::
41+
:local:
42+
43+
Installation
44+
============
45+
46+
The module can be installed just like any other Odoo module, by adding
47+
the module's directory to Odoo *addons_path*. In order for the module to
48+
correctly wrap the Odoo WSGI application, it also needs to be loaded as
49+
a server-wide module. This can be done with the ``server_wide_modules``
50+
parameter in your Odoo config file or with the ``--load`` command-line
51+
parameter.
52+
53+
This module additionally requires the sentry-sdk Python package to be
54+
available on the system. It can be installed using pip:
55+
56+
::
57+
58+
pip install sentry-sdk
59+
60+
Configuration
61+
=============
62+
63+
The following additional configuration options can be added to your Odoo
64+
configuration file:
65+
66+
[TABLE]
67+
68+
Other `client
69+
arguments <https://docs.sentry.io/platforms/python/configuration/>`__
70+
can be configured by prepending the argument name with *sentry\_* in
71+
your Odoo config file. Currently supported additional client arguments
72+
are:
73+
``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``.
74+
75+
Example Odoo configuration
76+
--------------------------
77+
78+
Below is an example of Odoo configuration file with *Odoo Sentry*
79+
options:
80+
81+
::
82+
83+
[options]
84+
sentry_dsn = https://<public_key>:<secret_key>@sentry.example.com/<project id>
85+
sentry_enabled = true
86+
sentry_logging_level = warn
87+
sentry_exclude_loggers = werkzeug
88+
sentry_ignore_exceptions = odoo.exceptions.AccessDenied,
89+
odoo.exceptions.AccessError,odoo.exceptions.MissingError,
90+
odoo.exceptions.RedirectWarning,odoo.exceptions.UserError,
91+
odoo.exceptions.ValidationError,odoo.exceptions.Warning,
92+
odoo.exceptions.except_orm
93+
sentry_include_context = true
94+
sentry_environment = production
95+
sentry_release = 1.3.2
96+
sentry_odoo_dir = /home/odoo/odoo/
97+
98+
Usage
99+
=====
100+
101+
Once configured and installed, the module will report any logging event
102+
at and above the configured Sentry logging level, no additional actions
103+
are necessary.
104+
105+
|Try me on Runbot|
106+
107+
.. |Try me on Runbot| image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
108+
:target: https://runbot.odoo-community.org/runbot/149/14.0
109+
110+
Known issues / Roadmap
111+
======================
112+
113+
- **No database separation** -- This module functions by intercepting
114+
all Odoo logging records in a running Odoo process. This means that
115+
once installed in one database, it will intercept and report errors
116+
for all Odoo databases, which are used on that Odoo server.
117+
- **Frontend integration** -- In the future, it would be nice to add
118+
Odoo client-side error reporting to this module as well, by
119+
integrating `raven-js <https://github.com/getsentry/raven-js>`__.
120+
Additionally, `Sentry user feedback
121+
form <https://docs.sentry.io/learn/user-feedback/>`__ could be
122+
integrated into the Odoo client error dialog window to allow users
123+
shortly describe what they were doing when things went wrong.
124+
125+
Bug Tracker
126+
===========
127+
128+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
129+
In case of trouble, please check there if your issue has already been reported.
130+
If you spotted it first, help us to smash it by providing a detailed and welcomed
131+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20sentry%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
132+
133+
Do not contact contributors directly about support or help with technical issues.
134+
135+
Credits
136+
=======
137+
138+
Authors
139+
-------
140+
141+
* Mohammed Barsi
142+
* Versada
143+
* Nicolas JEUDY
144+
* Vauxoo
145+
146+
Contributors
147+
------------
148+
149+
- Mohammed Barsi <barsintod@gmail.com>
150+
- Andrius Preimantas <andrius@versada.eu>
151+
- Naglis Jonaitis <naglis@versada.eu>
152+
- Atte Isopuro <atte.isopuro@avoin.systems>
153+
- Florian Mounier <florian.mounier@akretion.com>
154+
- Jon Ashton <jon@monkeyinferno.com>
155+
- Mark Schuit <mark@gig.solutions>
156+
- Atchuthan <atchuthan@sodexis.com>
157+
158+
Other credits
159+
-------------
160+
161+
- Vauxoo
162+
163+
Maintainers
164+
-----------
165+
166+
This module is maintained by the OCA.
167+
168+
.. image:: https://odoo-community.org/logo.png
169+
:alt: Odoo Community Association
170+
:target: https://odoo-community.org
171+
172+
OCA, or the Odoo Community Association, is a nonprofit organization whose
173+
mission is to support the collaborative development of Odoo features and
174+
promote its widespread use.
175+
176+
.. |maintainer-barsi| image:: https://github.com/barsi.png?size=40px
177+
:target: https://github.com/barsi
178+
:alt: barsi
179+
.. |maintainer-naglis| image:: https://github.com/naglis.png?size=40px
180+
:target: https://github.com/naglis
181+
:alt: naglis
182+
.. |maintainer-versada| image:: https://github.com/versada.png?size=40px
183+
:target: https://github.com/versada
184+
:alt: versada
185+
.. |maintainer-moylop260| image:: https://github.com/moylop260.png?size=40px
186+
:target: https://github.com/moylop260
187+
:alt: moylop260
188+
.. |maintainer-fernandahf| image:: https://github.com/fernandahf.png?size=40px
189+
:target: https://github.com/fernandahf
190+
:alt: fernandahf
191+
192+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
193+
194+
|maintainer-barsi| |maintainer-naglis| |maintainer-versada| |maintainer-moylop260| |maintainer-fernandahf|
195+
196+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/sentry>`_ project on GitHub.
197+
198+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

sentry/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .hooks import post_load

sentry/__manifest__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2016-2017 Versada <https://versada.eu/>
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Sentry",
5+
"summary": "Report Odoo errors to Sentry",
6+
"version": "19.0.1.0.0",
7+
"category": "Extra Tools",
8+
"website": "https://github.com/OCA/server-tools",
9+
"author": "Mohammed Barsi,"
10+
"Versada,"
11+
"Nicolas JEUDY,"
12+
"Odoo Community Association (OCA),"
13+
"Vauxoo",
14+
"maintainers": ["barsi", "naglis", "versada", "moylop260", "fernandahf"],
15+
"license": "AGPL-3",
16+
"application": False,
17+
"installable": True,
18+
"external_dependencies": {
19+
"python": [
20+
"sentry_sdk>=2.0.0,<=2.22.0",
21+
]
22+
},
23+
"depends": [
24+
"base",
25+
],
26+
"post_load": "post_load",
27+
}

sentry/const.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Copyright 2016-2017 Versada <https://versada.eu/>
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
import collections
4+
import logging
5+
6+
from sentry_sdk import HttpTransport
7+
from sentry_sdk.consts import DEFAULT_OPTIONS
8+
from sentry_sdk.integrations.logging import LoggingIntegration
9+
10+
import odoo.loglevels
11+
12+
13+
def split_multiple(string, delimiter=",", strip_chars=None):
14+
"""Splits :param:`string` and strips :param:`strip_chars` from values."""
15+
if not string:
16+
return []
17+
return [v.strip(strip_chars) for v in string.split(delimiter)]
18+
19+
20+
def to_int_if_defined(value):
21+
if value == "" or value is None:
22+
return
23+
return int(value)
24+
25+
26+
def to_float_if_defined(value):
27+
if value == "" or value is None:
28+
return
29+
return float(value)
30+
31+
32+
SentryOption = collections.namedtuple("SentryOption", ["key", "default", "converter"])
33+
34+
# Mapping of Odoo logging level -> Python stdlib logging library log level.
35+
LOG_LEVEL_MAP = {
36+
getattr(odoo.loglevels, f"LOG_{x}"): getattr(logging, x)
37+
for x in ("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET")
38+
}
39+
DEFAULT_LOG_LEVEL = "warn"
40+
41+
ODOO_USER_EXCEPTIONS = [
42+
"odoo.exceptions.AccessDenied",
43+
"odoo.exceptions.AccessError",
44+
"odoo.exceptions.DeferredException",
45+
"odoo.exceptions.MissingError",
46+
"odoo.exceptions.RedirectWarning",
47+
"odoo.exceptions.UserError",
48+
"odoo.exceptions.ValidationError",
49+
"odoo.exceptions.Warning",
50+
"odoo.exceptions.except_orm",
51+
]
52+
DEFAULT_IGNORED_EXCEPTIONS = ",".join(ODOO_USER_EXCEPTIONS)
53+
54+
EXCLUDE_LOGGERS = ("werkzeug",)
55+
DEFAULT_EXCLUDE_LOGGERS = ",".join(EXCLUDE_LOGGERS)
56+
57+
DEFAULT_ENVIRONMENT = "develop"
58+
59+
DEFAULT_TRANSPORT = "threaded"
60+
61+
62+
def select_transport(name=DEFAULT_TRANSPORT):
63+
return {
64+
"threaded": HttpTransport,
65+
}.get(name, HttpTransport)
66+
67+
68+
def get_sentry_logging(level=DEFAULT_LOG_LEVEL):
69+
if level not in LOG_LEVEL_MAP:
70+
level = DEFAULT_LOG_LEVEL
71+
72+
return LoggingIntegration(
73+
# Gather warnings into breadcrumbs regardless of actual logging level
74+
level=logging.WARNING,
75+
event_level=LOG_LEVEL_MAP[level],
76+
)
77+
78+
79+
def get_sentry_options():
80+
res = [
81+
SentryOption("dsn", "", str.strip),
82+
SentryOption("transport", DEFAULT_OPTIONS["transport"], select_transport),
83+
SentryOption("logging_level", DEFAULT_LOG_LEVEL, get_sentry_logging),
84+
SentryOption(
85+
"include_local_variables", DEFAULT_OPTIONS["include_local_variables"], None
86+
),
87+
SentryOption(
88+
"max_breadcrumbs", DEFAULT_OPTIONS["max_breadcrumbs"], to_int_if_defined
89+
),
90+
SentryOption("release", DEFAULT_OPTIONS["release"], None),
91+
SentryOption("environment", DEFAULT_OPTIONS["environment"], None),
92+
SentryOption("server_name", DEFAULT_OPTIONS["server_name"], None),
93+
SentryOption("shutdown_timeout", DEFAULT_OPTIONS["shutdown_timeout"], None),
94+
SentryOption("integrations", DEFAULT_OPTIONS["integrations"], None),
95+
SentryOption(
96+
"in_app_include", DEFAULT_OPTIONS["in_app_include"], split_multiple
97+
),
98+
SentryOption(
99+
"in_app_exclude", DEFAULT_OPTIONS["in_app_exclude"], split_multiple
100+
),
101+
SentryOption(
102+
"default_integrations", DEFAULT_OPTIONS["default_integrations"], None
103+
),
104+
SentryOption("dist", DEFAULT_OPTIONS["dist"], None),
105+
SentryOption(
106+
"sample_rate", DEFAULT_OPTIONS["sample_rate"], to_float_if_defined
107+
),
108+
SentryOption("send_default_pii", DEFAULT_OPTIONS["send_default_pii"], None),
109+
SentryOption("http_proxy", DEFAULT_OPTIONS["http_proxy"], None),
110+
SentryOption("https_proxy", DEFAULT_OPTIONS["https_proxy"], None),
111+
SentryOption("ignore_exceptions", DEFAULT_IGNORED_EXCEPTIONS, split_multiple),
112+
SentryOption(
113+
"max_request_body_size", DEFAULT_OPTIONS["max_request_body_size"], None
114+
),
115+
SentryOption("attach_stacktrace", DEFAULT_OPTIONS["attach_stacktrace"], None),
116+
SentryOption("ca_certs", DEFAULT_OPTIONS["ca_certs"], None),
117+
SentryOption("propagate_traces", DEFAULT_OPTIONS["propagate_traces"], None),
118+
SentryOption(
119+
"traces_sample_rate",
120+
DEFAULT_OPTIONS["traces_sample_rate"],
121+
to_float_if_defined,
122+
),
123+
]
124+
125+
if "auto_enabling_integrations" in DEFAULT_OPTIONS:
126+
res.append(
127+
SentryOption(
128+
"auto_enabling_integrations",
129+
DEFAULT_OPTIONS["auto_enabling_integrations"],
130+
None,
131+
)
132+
)
133+
134+
return res

0 commit comments

Comments
 (0)