Contributors mailing list archives

contributors@odoo-community.org

Avatar

Tracing and in general how can we execute an handler on every request

by
SAS Clouder, Yannick Buron
- 08/12/2021 12:20:04

Hello all,

I have a technical question and I wonder if anyone here already faced this issue.

I am trying to integrate Odoo into our monitoring stack, with the three pillars of observability metrics/logging/tracing, starting with the tracing. My issue is, it doesn't look like we have an easy way to insert the handler which will start the trace. Also no documentation anywhere about how we can easily integrate tracing into Odoo. This is a v12 version but I believe the issue is still here on more recent versions.

We are planning to use Azure Monitor, but the issue will be the same with any other tracing platform : I can't figure a way to override a core function to start the trace and insert the python library I need https://docs.microsoft.com/fr-fr/azure/azure-monitor/app/opencensus-python#tracing

I can of course override some of the most important controllers like https://github.com/odoo/odoo/blob/12.0/addons/web/controllers/main.py#L961:

-----------

from odoo.addons.web.controllers.main import DataSet
class ExtendDataSet(DataSet):
@route()
def call_kw(self, model, method, args, kwargs, path=None):
print("Insert tracer here")
return super(
ExtendDataSet, self).call_kw(
model, method, args, kwargs, path=path)

-----------

But this will force me to override all controllers I can find, and some custom controllers will obviously go under the radar.

I identified some entry point used by all requests like https://github.com/odoo/odoo/blob/12.0/addons/web/controllers/main.py#L961 or https://github.com/odoo/odoo/blob/12.0/odoo/http.py#L316 but I don't think I have a way to override theses functions without having to rely on the terrible idea to patch the core code.

Anything I missed on how we could execute some code on every request ? On Django you would just use a middleware for such purpose https://docs.djangoproject.com/fr/2.2/topics/http/middleware/ and it does the job perfectly, I feel like this is something which is really missing in Odoo when we have such requirements.

Thanks,
Yannick