Skip to content
Open
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ openupgradelib
paramiko<4.0.0
pygount
pysftp
sentry_sdk>=2.0.0,<=2.22.0
sentry_sdk>=2.35.0
2 changes: 1 addition & 1 deletion sentry/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"installable": True,
"external_dependencies": {
"python": [
"sentry_sdk>=2.0.0,<=2.22.0",
"sentry_sdk>=2.35.0",
]
},
"depends": [
Expand Down
3 changes: 3 additions & 0 deletions sentry/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def initialize_sentry(config):
# Remove logging_level, since in sentry_sdk is include in 'integrations'
del options["logging_level"]

if config.get("sentry_enable_logs", False):
options["enable_logs"] = True

client = sentry_sdk.init(**options)

sentry_sdk.set_tag("include_context", config.get("sentry_include_context", True))
Expand Down
1 change: 1 addition & 0 deletions sentry/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ options:
sentry_enabled = true
sentry_logging_level = warn
sentry_exclude_loggers = werkzeug
sentry_enable_logs = true
sentry_ignore_exceptions = odoo.exceptions.AccessDenied,
odoo.exceptions.AccessError,odoo.exceptions.MissingError,
odoo.exceptions.RedirectWarning,odoo.exceptions.UserError,
Expand Down
37 changes: 16 additions & 21 deletions sentry/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Sentry</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="sentry">
<h1 class="title">Sentry</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="sentry">
<h1>Sentry</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e2f1d0bc83bf031b61df768de9c2f6d4f1feb303facf171a8d1889fc6a2635ca
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/sentry"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-sentry"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/sentry"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-sentry"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows painless <a class="reference external" href="https://sentry.io/">Sentry</a> integration
with Odoo.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -398,7 +393,7 @@ <h1>Sentry</h1>
</ul>
</div>
<div class="section" id="installation">
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>The module can be installed just like any other Odoo module, by adding
the module’s directory to Odoo <em>addons_path</em>. In order for the module to
correctly wrap the Odoo WSGI application, it also needs to be loaded as
Expand All @@ -412,7 +407,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
</pre>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>The following additional configuration options can be added to your Odoo
configuration file:</p>
<p>[TABLE]</p>
Expand All @@ -423,7 +418,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
are:
<tt class="docutils literal">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</tt>.</p>
<div class="section" id="example-odoo-configuration">
<h3><a class="toc-backref" href="#toc-entry-3">Example Odoo configuration</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">Example Odoo configuration</a></h2>
<p>Below is an example of Odoo configuration file with <em>Odoo Sentry</em>
options:</p>
<pre class="literal-block">
Expand All @@ -432,6 +427,7 @@ <h3><a class="toc-backref" href="#toc-entry-3">Example Odoo configuration</a></h
sentry_enabled = true
sentry_logging_level = warn
sentry_exclude_loggers = werkzeug
sentry_enable_logs = true
sentry_ignore_exceptions = odoo.exceptions.AccessDenied,
odoo.exceptions.AccessError,odoo.exceptions.MissingError,
odoo.exceptions.RedirectWarning,odoo.exceptions.UserError,
Expand All @@ -445,14 +441,14 @@ <h3><a class="toc-backref" href="#toc-entry-3">Example Odoo configuration</a></h
</div>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-4">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Usage</a></h1>
<p>Once configured and installed, the module will report any logging event
at and above the configured Sentry logging level, no additional actions
are necessary.</p>
<p><a class="reference external image-reference" href="https://runbot.odoo-community.org/runbot/149/14.0"><img alt="Try me on Runbot" src="https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas" /></a></p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-5">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-5">Known issues / Roadmap</a></h1>
<ul class="simple">
<li><strong>No database separation</strong> – This module functions by intercepting
all Odoo logging records in a running Odoo process. This means that
Expand All @@ -468,17 +464,17 @@ <h2><a class="toc-backref" href="#toc-entry-5">Known issues / Roadmap</a></h2>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20sentry%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-7">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-7">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-8">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">Authors</a></h2>
<ul class="simple">
<li>Mohammed Barsi</li>
<li>Versada</li>
Expand All @@ -487,7 +483,7 @@ <h3><a class="toc-backref" href="#toc-entry-8">Authors</a></h3>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-9">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<ul class="simple">
<li>Mohammed Barsi &lt;<a class="reference external" href="mailto:barsintod&#64;gmail.com">barsintod&#64;gmail.com</a>&gt;</li>
<li>Andrius Preimantas &lt;<a class="reference external" href="mailto:andrius&#64;versada.eu">andrius&#64;versada.eu</a>&gt;</li>
Expand All @@ -500,13 +496,13 @@ <h3><a class="toc-backref" href="#toc-entry-9">Contributors</a></h3>
</ul>
</div>
<div class="section" id="other-credits">
<h3><a class="toc-backref" href="#toc-entry-10">Other credits</a></h3>
<h2><a class="toc-backref" href="#toc-entry-10">Other credits</a></h2>
<ul class="simple">
<li>Vauxoo</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -521,6 +517,5 @@ <h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
37 changes: 37 additions & 0 deletions sentry/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ def has_event(self, event_level, event_msg):
return event
return False

def has_log_item(self, log_level: str, log_msg: str) -> bool:
for envelope in self.envelopes:
log_items = filter(
lambda envelope_item: envelope_item.data_category == "log_item",
envelope.items,
)
payload_items = []
for item in log_items:
payload_items.extend(item.payload.json["items"])
if any(
(item["level"] == log_level and item["body"] == log_msg)
for item in payload_items
):
return True

return False

def flush(self, *args, **kwargs):
pass

Expand Down Expand Up @@ -123,6 +140,13 @@ def assertEventNotCaptured(self, client, event_level, event_msg):
msg=f"Event: {event_msg} was captured",
)

def assertLogCaptured(self, client, log_level: str, log_msg: str):
client.flush()
self.assertTrue(
client.transport.has_log_item(log_level, log_msg),
msg=f"Log item: {log_msg} was not captured",
)

def test_initialize_raven_sets_dsn(self):
self.assertEqual(self.client.dsn, self.dsn)

Expand Down Expand Up @@ -224,6 +248,19 @@ def test_exclude_logger(self):
remove_handler_ignore(self.logger.name)
self.assertEventNotCaptured(client, level, msg)

def test_enable_logs(self):
self.patch_config(
{
"sentry_enable_logs": True,
}
)
client = initialize_sentry(config)._client
client.transport = InMemoryTransport({"dsn": self.dsn})
level, msg = logging.WARNING, "Test log sending is enabled"
self.log(level, msg)
level = "warn"
self.assertLogCaptured(client, level, msg)

def test_invalid_logging_level(self):
self.patch_config(
{
Expand Down