From 1dde48de4aeba066a3786c93c2214c442732cc01 Mon Sep 17 00:00:00 2001 From: Shamsidinkhon Date: Mon, 12 Jun 2023 12:33:47 +0200 Subject: [PATCH 1/2] [IMP] newrelic: wrap target server initialization and skip in case odoo stop_after_init --- newrelic/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/newrelic/__init__.py b/newrelic/__init__.py index 6179c9c..7dd656c 100644 --- a/newrelic/__init__.py +++ b/newrelic/__init__.py @@ -1,10 +1,12 @@ import os from . import controllers +from odoo.tools import config import logging _logger = logging.getLogger(__name__) -try: + +def initialization(): import odoo target = odoo.service.server.server if not target: @@ -19,7 +21,6 @@ if instrumented: _logger.info("NewRelic instrumented already") else: - import odoo.tools.config as config import newrelic.agent @@ -122,5 +123,11 @@ def _handle_exception(*args, **kwargs): target = odoo.http.WebRequest target._handle_exception = _nr_wrapper_handle_exception_(target._handle_exception) + +try: + # the Odoo server will stop after its initialization, server will not be available for monkey-patching + if not config.get("stop_after_init"): + initialization() + except ImportError: _logger.warn('newrelic python module not installed or other missing module') From ccc8b07a580ee995ed23f1148f30166590ab7613 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Mon, 4 Sep 2023 18:08:48 +0200 Subject: [PATCH 2/2] [MIG] newrelic: Migration to 16.0 --- newrelic/__init__.py | 17 ++++++++--------- newrelic/__manifest__.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/newrelic/__init__.py b/newrelic/__init__.py index 7dd656c..10c6574 100644 --- a/newrelic/__init__.py +++ b/newrelic/__init__.py @@ -39,13 +39,12 @@ def initialization(): target.app = nr_app # Workers new WSGI Application - target = odoo.service.wsgi_server - target.application_unproxied = newrelic.agent.WSGIApplicationWrapper(target.application_unproxied) - + odoo.http.Application = newrelic.agent.WSGIApplicationWrapper(odoo.http.Application) + try: _logger.info('attaching to bus controller') import odoo.addons.bus.controllers.main - newrelic.agent.wrap_background_task(odoo.addons.bus.controllers.main, 'BusController._poll', application=nr_app) + newrelic.agent.wrap_background_task(odoo.addons.bus.websocket, 'Websocket._dispatch_bus_notifications', application=nr_app) _logger.info('finished attaching to bus controller') except Exception as e: _logger.exception(e) @@ -105,8 +104,8 @@ def status_code(exc, value, tb): if isinstance(value, HTTPException): return value.code - def _nr_wrapper_handle_exception_(wrapped): - def _handle_exception(*args, **kwargs): + def _nr_wrapper_handle_error(wrapped): + def handle_error(*args, **kwargs): transaction = newrelic.agent.current_transaction() if transaction is None: @@ -118,10 +117,10 @@ def _handle_exception(*args, **kwargs): with newrelic.agent.FunctionTrace(transaction, name): return wrapped(*args, **kwargs) - return _handle_exception + return handle_error - target = odoo.http.WebRequest - target._handle_exception = _nr_wrapper_handle_exception_(target._handle_exception) + for target in (odoo.http.HttpDispatcher, odoo.http.JsonRPCDispatcher): + target.handle_error = _nr_wrapper_handle_error(target.handle_error) try: diff --git a/newrelic/__manifest__.py b/newrelic/__manifest__.py index 4bed1d3..c4595e6 100644 --- a/newrelic/__manifest__.py +++ b/newrelic/__manifest__.py @@ -1,7 +1,7 @@ { 'name': 'NewRelic Instrumentation', 'description': 'Wraps requests etc.', - 'version': '15.0.0.9.0', + 'version': '16.0.0.9.0', 'website': 'https://hibou.io/', 'author': 'Hibou Corp. ', 'license': 'AGPL-3',