Skip to content

[20.0][MIG] sentry: Migration to 20.0 - #3897

Open
fetouaki-younes wants to merge 60 commits into
OCA:20.0from
fetouaki-younes:20.0-mig-sentry
Open

fetouaki-younes wants to merge 60 commits into
OCA:20.0from
fetouaki-younes:20.0-mig-sentry

Conversation

@fetouaki-younes

Copy link
Copy Markdown

Migration of sentry from 19.0 to 20.0.

    Part of #3772

    ### Summary of changes
    - Ported commit history from `19.0`.
    - Added `sentry_sdk>=2.0.0,<=2.22.0` to `requirements.txt` via `oca-gen-external-dependencies`.
    - Bumped manifest version to `20.0.1.0.0`.
    - Updated `hooks.py` and `tests/test_client.py` to use `odoo.http.router.root` and `odoo.http.router.Application` instead of `odoo.http.root` / `odoo.http.Application`.
    - Applied `ruff` fixes in `processor.py` and `tests/test_generalutils.py`.
    - Regenerated `README.rst` and `static/description/index.html` via `oca-gen-addon-readme`.

naglis and others added 30 commits December 1, 2026 16:04
* [ADD] sentry module

* [FIX] updated sentry module according to PR comments
- [FIX] sentry: fixes missing `raven` library preventing loading of modules
- [FIX] 2to3 script on py file
- [FIX] add requirements.txt
sentry: It is not always possible to read commit information from
a production environment. In those cases it is useful to be able
to set a release version manually.

[UPD] Update sentry.pot
[UPD] Update sentry.pot
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-14.0/server-tools-14.0-sentry
Translate-URL: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-sentry/
The following warning is fixed:

    DeprecationWarning: Using or importing the ABCs from 'collections' instead of
    from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop
    working
Allow using `sentry_release` or `sentry_odoo_dir` in the Odoo
configuration file.

Previously, the `sentry_odoo_dir` was never actually respected. It would
always be overridden by `sentry_release`. Even if `sentry_release` is
not set, it will use an empty value instead of using `sentry_odoo_dir`
to find the Git commit hash.

After this commit, the `sentry_release` parameter still takes
precedence. However, if `sentry_release` is not set and
`sentry_odoo_dir` is set, then `sentry_odoo_dir` will be used to find
the appropriate Git commit hash, which will be used as the `release`
value.

Both cases are covered by the added unit tests.
Because post_load is called after odoo.service.server start
It has already registered the unpatched   odoo.service.wsgi_server.application
So patch it here too.
This enables wsgi performance reporting with sentry_traces_sample_rate
The test code uses a "mock" Transport object to ensure that events are
stored locally in memory, instead of triggering network requests.

The Sentry client is cleaned up once done, and this triggers a call to
capture_envelope, a different way of sending events to Sentry. Since
our mock class did not fully complete initialization, and also did
not provide an overriding method, the original was called, which
depends on proper initialization to work.

We introduce an override for capture_envelope: as it is meant to be
a "sibling" to capture_event, it makes sense for us to also make sure
events registrered in this way are intercepted, even if we don't
currently expect any of our tests to explicitly cause it to be used.
Currently, version 1.17.0 of sentry_sdk is causing the following error:

SentryOption("with_locals", DEFAULT_OPTIONS["with_locals"], None),
KeyError: 'with_locals'.

Where the with_locals key is not found in the dictionary, generating an
error, stopping the installation of the sentry module.

In version 1.17.0 rename 'with_locals'  to 'include_local_variables'
getsentry/sentry-python@79e3316

This commit adjust the  get_sentry_options() method in
https://github.com/Vauxoo/server-tools/blob/16.0/sentry/const.py file, set the new variable.
aisopuro and others added 26 commits December 1, 2026 16:04
…repository

Debian Bullseye is used as base docker image for odoo:15.0
To avoid following error:
AttributeError: 'InMemoryTransport' object has no attribute 'options'
Fixes

```
  File "/home/odoo/.local/lib/python3.12/site-packages/sentry_sdk/client.py", line 595, in _prepare_event
    new_event = before_send(event, hint or {})
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/user/oca-server-tools/sentry/hooks.py", line 66, in before_send
    if event.setdefault("tags", {})["include_context"]:
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'include_context'
2025-07-08 14:45:45,907 14296 INFO quatra-18-0-development-21441249 sentry_sdk.errors: before send dropped event
```

Error is only logged when running Sentry in debug mode, otherwise events are dropped silently.
Odoo.sh loads the application quite frequently during normal operation (even when not restarting the server). Each time it does, sentry get reinitialzied. This sends to a substantial amount of messages to Sentry, draining a non-trivial portion of monitoring budget when using SaaS Sentry.
@oca-cla-bot

oca-cla-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

@fetouaki-younes fetouaki-younes mentioned this pull request Dec 2, 2026
4 of 30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.