diff --git a/newrelic/__init__.py b/newrelic/__init__.py index 6179c9c..10c6574 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 @@ -38,13 +39,12 @@ 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) @@ -104,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: @@ -117,10 +117,16 @@ 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: + # 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') 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',