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)
示例#2
0
def handle_one(check):
    """ Send an alert for a single check.

    Return True if an appropriate check was selected and processed.
    Return False if no checks need to be processed.

    """
    check.status = check.get_status()

    tmpl = "Sending alert, status=%s, code=%s\n"
    _stdout(tmpl % (check.status, check.code))

    # Save the new status.
    check.status = check.get_status()
    check.save()

    tmpl = "\nSending alert, status=%s, code=%s\n"
    _stdout(tmpl % (check.status, check.code))
    try:
        errors = check.send_alert()
    except:
        agent.record_exception()
    finally:
        connection.close()

    for ch, error in errors:
        _stdout("ERROR: %s %s %s\n" % (ch.kind, ch.value, error))

    return True
示例#3
0
 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)
示例#4
0
    def _function3():
        add_custom_parameter('txn-key-1', 1)

        try:
            raise NotImplementedError(
                    'This is a test error and can be ignored.')
        except:
            record_exception(params={'err-key-2': 2, 'err-key-3': 3.0})

        raise RuntimeError('This is a test error and can be ignored.')
示例#5
0
    def _function3():
        add_custom_parameter('txn-key-1', 1)

        try:
            raise NotImplementedError(
                    'This is a test error and can be ignored.')
        except:
            record_exception(params={'err-key-2': 2, 'err-key-3': 3.0})

        raise RuntimeError('This is a test error and can be ignored.')
示例#6
0
        def inner(*args, **kwargs):
            if group == "Python/napfs":
                set_transaction_name(txn_name)
            with FunctionTrace(
                transaction=current_transaction(),
                name=txn_name,
                group=group

            ):
                try:
                    return f(*args, **kwargs)
                except Exception as e:
                    if not isinstance(e, falcon.HTTPNotFound):
                        record_exception(*sys.exc_info())
                    raise
示例#7
0
def record_exception():
    """
    record the exception currently handled to newrelic
    """
    if agent:
        agent.record_exception()#will record the exception currently handled
示例#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)

        try:
            raise NotImplementedError(
                    'This is a test error and can be ignored.')
        except:
            record_exception(params={'err-key-2': 2, 'err-key-3': 3.0})

        raise RuntimeError('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()

    try:
        raise NotImplementedError('This is a test error and can be ignored.')
    except Exception:
        record_exception(params={'err-key-4': 4}, application=application())
示例#9
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)

        try:
            raise NotImplementedError(
                'This is a test error and can be ignored.')
        except:
            record_exception(params={'err-key-2': 2, 'err-key-3': 3.0})

        raise RuntimeError('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()

    try:
        raise NotImplementedError('This is a test error and can be ignored.')
    except Exception:
        record_exception(params={'err-key-4': 4}, application=application())