mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Initial commit of Newrelic addon from https://github.com/hibou-io/odoo-newrelic for 11.0
This commit is contained in:
71
newrelic/__init__.py
Normal file
71
newrelic/__init__.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
from . import controllers
|
||||||
|
|
||||||
|
from logging import getLogger
|
||||||
|
_logger = getLogger(__name__)
|
||||||
|
|
||||||
|
try:
|
||||||
|
import odoo
|
||||||
|
target = odoo.service.server.server
|
||||||
|
|
||||||
|
try:
|
||||||
|
instrumented = target._nr_instrumented
|
||||||
|
except AttributeError:
|
||||||
|
instrumented = target._nr_instrumented = False
|
||||||
|
|
||||||
|
if instrumented:
|
||||||
|
_logger.info("NewRelic instrumented already")
|
||||||
|
else:
|
||||||
|
import odoo.tools.config as config
|
||||||
|
import newrelic.agent
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
newrelic.agent.initialize(config['new_relic_config_file'], config['new_relic_environment'])
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
newrelic.agent.initialize(config['new_relic_config_file'])
|
||||||
|
except KeyError:
|
||||||
|
_logger.info('NewRelic setting up from env variables')
|
||||||
|
newrelic.agent.initialize()
|
||||||
|
|
||||||
|
# Main WSGI Application
|
||||||
|
target._nr_instrumented = True
|
||||||
|
target.app = newrelic.agent.WSGIApplicationWrapper(target.app)
|
||||||
|
|
||||||
|
# Workers new WSGI Application
|
||||||
|
target = odoo.service.wsgi_server
|
||||||
|
target.application_unproxied = newrelic.agent.WSGIApplicationWrapper(target.application_unproxied)
|
||||||
|
|
||||||
|
# Error handling
|
||||||
|
def should_ignore(exc, value, tb):
|
||||||
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
|
# Werkzeug HTTPException can be raised internally by Odoo or in
|
||||||
|
# user code if they mix Odoo with Werkzeug. Filter based on the
|
||||||
|
# HTTP status code.
|
||||||
|
|
||||||
|
if isinstance(value, HTTPException):
|
||||||
|
if newrelic.agent.ignore_status_code(value.code):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _nr_wrapper_handle_exception_(wrapped):
|
||||||
|
def _handle_exception(*args, **kwargs):
|
||||||
|
transaction = newrelic.agent.current_transaction()
|
||||||
|
|
||||||
|
if transaction is None:
|
||||||
|
return wrapped(*args, **kwargs)
|
||||||
|
|
||||||
|
transaction.record_exception(ignore_errors=should_ignore)
|
||||||
|
|
||||||
|
name = newrelic.agent.callable_name(args[1])
|
||||||
|
with newrelic.agent.FunctionTrace(transaction, name):
|
||||||
|
return wrapped(*args, **kwargs)
|
||||||
|
|
||||||
|
return _handle_exception
|
||||||
|
|
||||||
|
target = odoo.http.WebRequest
|
||||||
|
target._handle_exception = _nr_wrapper_handle_exception_(target._handle_exception)
|
||||||
|
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
_logger.warn('newrelic python module not installed or other missing module')
|
||||||
12
newrelic/__manifest__.py
Normal file
12
newrelic/__manifest__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
'name': 'NewRelic Instrumentation',
|
||||||
|
'description': 'Wraps requests etc.',
|
||||||
|
'version': '1.0',
|
||||||
|
'website': 'https://hibou.io/',
|
||||||
|
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'category': 'Tool',
|
||||||
|
'depends': [
|
||||||
|
'web',
|
||||||
|
],
|
||||||
|
}
|
||||||
1
newrelic/controllers/__init__.py
Normal file
1
newrelic/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import main
|
||||||
39
newrelic/controllers/main.py
Normal file
39
newrelic/controllers/main.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from odoo import http, tools
|
||||||
|
import odoo.addons.bus.controllers.main
|
||||||
|
|
||||||
|
try:
|
||||||
|
import newrelic
|
||||||
|
import newrelic.agent
|
||||||
|
except ImportError:
|
||||||
|
newrelic = None
|
||||||
|
|
||||||
|
|
||||||
|
class BusController(odoo.addons.bus.controllers.main.BusController):
|
||||||
|
|
||||||
|
@http.route()
|
||||||
|
def send(self, channel, message):
|
||||||
|
if newrelic:
|
||||||
|
newrelic.agent.ignore_transaction()
|
||||||
|
return super(BusController, self).send(channel, message)
|
||||||
|
|
||||||
|
@http.route()
|
||||||
|
def poll(self, channels, last, options=None):
|
||||||
|
if newrelic:
|
||||||
|
newrelic.agent.ignore_transaction()
|
||||||
|
return super(BusController, self).poll(channels, last, options)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if tools.config['debug_mode']:
|
||||||
|
class TestErrors(http.Controller):
|
||||||
|
@http.route('/test_errors_404', auth='public')
|
||||||
|
def test_errors_404(self):
|
||||||
|
import werkzeug
|
||||||
|
return werkzeug.exceptions.NotFound('Successful test of 404')
|
||||||
|
|
||||||
|
@http.route('/test_errors_500', auth='public')
|
||||||
|
def test_errors_500(self):
|
||||||
|
raise ValueError
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user