Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] newrelic: Migration to 16.0 #18

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 17 additions & 11 deletions newrelic/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -19,7 +21,6 @@
if instrumented:
_logger.info("NewRelic instrumented already")
else:
import odoo.tools.config as config
import newrelic.agent


Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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')
2 changes: 1 addition & 1 deletion newrelic/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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. <[email protected]>',
'license': 'AGPL-3',
Expand Down