Exemplo n.º 1
0
def wrap_task(wrapped, instance, args, kwargs):
    task, *_ = args
    task_name = callable_name(task)
    app = application()

    with BackgroundTask(app, task_name):
        return wrapped(*args, **kwargs)
Exemplo n.º 2
0
def record_exception():
    """
    record the exception currently handled to newrelic
    """
    if agent:
        agent.notice_error(application=agent.application()
                           )  # will record the exception currently handled
Exemplo n.º 3
0
 def wrapper(*args, **kwargs):
     if agent and agent.current_transaction() is None:
         with agent.BackgroundTask(agent.application(),
                                   name=name,
                                   group=group):
             return func(*args, **kwargs)
     else:
         return func(*args, **kwargs)
Exemplo n.º 4
0
    def perform(self):
        # This is the jobs own method to execute the task. Time
        # this as a background task where name is the name of
        # the queued task. This should also capture any record
        # any unhandled exceptions that occurred when running
        # the task.
 
        with BackgroundTask(application(), self.func_name):
            return _perform(self)
Exemplo n.º 5
0
def record_custom_event(event_type, params):
    """
    record an event
    Event doesn't share anything with request so we track the request id
    """
    if agent:
        try:
            if not params:
                params = {}
            params['navitia_request_id'] = flask.request.id
        except RuntimeError:
            pass  # we are outside of a flask context :(
        try:
            agent.record_custom_event(event_type, params, agent.application())
        except:
            logger = logging.getLogger(__name__)
            logger.exception('failure while reporting to newrelic')
Exemplo n.º 6
0
 def wrapper(self):
     with agent.BackgroundTask(agent.application(), self.func_name):
         return orig(self)
Exemplo n.º 7
0
 def config(self, config):
     self.active = config.newrelic_active
     if self.active:
         agent.initialize(config.newrelic_ini_path,
                                   config.newrelic_application_env)
         self.newrelic_application = agent.application()
Exemplo n.º 8
0
def _run_validation_test():
    import time

    from newrelic.agent import (background_task, error_trace, external_trace,
                                function_trace, wsgi_application,
                                add_custom_parameter, record_exception,
                                application)

    @external_trace(library='test', url='http://localhost/test', method='GET')
    def _external1():
        time.sleep(0.1)

    @function_trace(label='label',
                    params={
                        'fun-key-1': '1',
                        'fun-key-2': 2,
                        'fun-key-3': 3.0
                    })
    def _function1():
        _external1()

    @function_trace()
    def _function2():
        for i in range(10):
            _function1()

    @error_trace()
    @function_trace()
    def _function3():
        add_custom_parameter('txn-key-1', 1)

        _function4()

        raise RuntimeError('This is a test error and can be ignored.')

    @function_trace()
    def _function4(params=None, application=None):
        try:
            _function5()
        except:
            record_exception(params=(params or {
                'err-key-2': 2,
                'err-key-3': 3.0
            }),
                             application=application)

    @function_trace()
    def _function5():
        raise NotImplementedError('This is a test error and can be ignored.')

    @wsgi_application()
    def _wsgi_application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'

        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)

        for i in range(10):
            _function1()

        _function2()

        time.sleep(1.0)

        try:
            _function3()
        except Exception:
            pass

        return [output]

    @background_task()
    def _background_task():
        for i in range(10):
            _function1()

        _function2()

        time.sleep(0.5)

        try:
            _function3()
        except Exception:
            pass

    def _start_response(*args):
        pass

    _environ = {
        'SCRIPT_NAME': '',
        'PATH_INFO': '/test',
        'QUERY_STRING': 'key=value'
    }

    _iterable = _wsgi_application(_environ, _start_response)
    _iterable.close()

    _background_task()

    _function4(params={
        'err-key-4': 4,
        'err-key-5': 5.0
    },
               application=application())
def _run_validation_test():
    import time

    from newrelic.agent import (background_task, error_trace,
            external_trace, function_trace, wsgi_application,
            add_custom_parameter, record_exception, application)

    @external_trace(library='test',
            url='http://localhost/test', method='GET')
    def _external1():
        time.sleep(0.1)

    @function_trace(label='label',
            params={'fun-key-1': '1', 'fun-key-2': 2, 'fun-key-3': 3.0})
    def _function1():
        _external1()

    @function_trace()
    def _function2():
        for i in range(10):
            _function1()

    @error_trace()
    @function_trace()
    def _function3():
        add_custom_parameter('txn-key-1', 1)

        _function4()

        raise RuntimeError('This is a test error and can be ignored.')

    @function_trace()
    def _function4(params=None, application=None):
        try:
            _function5()
        except:
            record_exception(params=(params or {
                    'err-key-2': 2, 'err-key-3': 3.0}),
                    application=application)

    @function_trace()
    def _function5():
        raise NotImplementedError(
                'This is a test error and can be ignored.')

    @wsgi_application()
    def _wsgi_application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'

        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)

        for i in range(10):
            _function1()

        _function2()

        time.sleep(1.0)

        try:
            _function3()
        except Exception:
            pass

        return [output]

    @background_task()
    def _background_task():
        for i in range(10):
            _function1()

        _function2()

        time.sleep(0.5)

        try:
            _function3()
        except Exception:
            pass

    def _start_response(*args):
        pass

    _environ = { 'SCRIPT_NAME': '', 'PATH_INFO': '/test',
                 'QUERY_STRING': 'key=value' }

    _iterable = _wsgi_application(_environ, _start_response)
    _iterable.close()

    _background_task()

    _function4(params={'err-key-4': 4, 'err-key-5': 5.0},
            application=application())