コード例 #1
0
def test_py2_transaction_exception_message_unicode():
    """Assert unicode message when using non-ascii characters is preserved,
    with sys default encoding"""
    try:
        raise ValueError(UNICODE_MESSAGE)
    except ValueError:
        notice_error()
コード例 #2
0
def test_py2_transaction_exception_message_unicode_english():
    """Assert unicode message when using ascii compatible characters preserved,
    with sys default encoding"""
    try:
        raise ValueError(UNICODE_ENGLISH)
    except ValueError:
        notice_error()
コード例 #3
0
def test_py3_transaction_exception_message_bytes_non_english_unicode():
    """Assert (native) unicode exception message is preserved when when
    non-ascii compatible characters present"""
    try:
        raise ValueError(UNICODE_MESSAGE)
    except ValueError:
        notice_error()
コード例 #4
0
def test_py2_application_exception_message_bytes_english():
    """Assert byte string of ascii characters decodes sensibly"""
    try:
        raise ValueError(BYTES_ENGLISH)
    except ValueError:
        app = application()
        notice_error(application=app)
コード例 #5
0
def test_py3_transaction_exception_message_unicode_english():
    """Assert (native) unicode exception message is preserved, when characters
    are ascii-compatible"""
    try:
        raise ValueError(UNICODE_ENGLISH)
    except ValueError:
        notice_error()
コード例 #6
0
def test_application_notice_error_params_not_a_dict():
    try:
        raise RuntimeError()
    except RuntimeError:
        notice_error(sys.exc_info(),
                     attributes=[1, 2, 3],
                     application=application())
コード例 #7
0
def test_application_exception_custom_params():
    try:
        raise RuntimeError("one")
    except RuntimeError:
        application_instance = application()
        notice_error(attributes={"key": "value"},
                     application=application_instance)
コード例 #8
0
def _nr_wrap_handle_exception(wrapped, instance, args, kwargs):

    response = wrapped(*args, **kwargs)

    notice_error(status_code=response.status_code)

    return response
コード例 #9
0
def wrapper_RoutesDispatcher_find_handler(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    try:
        # Call the original wrapped function to find the handler.

        handler = wrapped(*args, **kwargs)

    except:  # Catch all
        # Can end up here when the URL was invalid in some way.
        notice_error(status_code=status_code)
        raise

    if handler:
        # Should be the actual handler, wrap it with the handler
        # wrapper.

        handler = handler_wrapper(handler)

    else:
        # No handler could be found so name the web transaction
        # after the 404 status code.

        transaction.set_transaction_name("404", group="StatusCode")

    return handler
コード例 #10
0
def test_application_exception_custom_params():
    try:
        raise RuntimeError('one')
    except RuntimeError:
        application_instance = application()
        notice_error(attributes={'key': 'value'},
                     application=application_instance)
コード例 #11
0
def test_multiple_error_events_outside_transaction():
    app = application()
    for i in range(2):
        try:
            raise ErrorEventOutsideTransactionError(ERR_MESSAGE + str(i))
        except ErrorEventOutsideTransactionError:
            notice_error(sys.exc_info(), application=app)
コード例 #12
0
def test_notice_error_strip_message_disabled():
    settings = application_settings()
    assert not settings.strip_exception_messages.enabled

    try:
        raise RuntimeError('one')
    except RuntimeError:
        notice_error()
コード例 #13
0
def test_py2_transaction_exception_message_unicode_utf8_encoding():
    """Assert unicode error message is preserved with sys non-default utf-8
    encoding
    """
    try:
        raise ValueError(UNICODE_MESSAGE)
    except ValueError:
        notice_error()
コード例 #14
0
def test_notice_error_strip_message_enabled():
    settings = application_settings()
    assert settings.strip_exception_messages.enabled

    try:
        raise RuntimeError("message not displayed")
    except RuntimeError:
        notice_error()
コード例 #15
0
 def _function4(params=None, application=None):
     try:
         _function5()
     except:
         notice_error(attributes=(params or {
             'err-key-2': 2,
             'err-key-3': 3.0
         }),
                      application=application)
コード例 #16
0
def test_py2_transaction_exception_message_bytes_non_english():
    """Assert known situation where (explicitly) utf-8 encoded byte string gets
    mangled when default sys encoding is ascii. THIS TEST ASSERTS THAT THE
    MESSAGE IS WRONG. We do not expect it to work now, or in the future.
    """
    try:
        raise ValueError(BYTES_UTF8_ENCODED)
    except ValueError:
        notice_error()
コード例 #17
0
def _nr_wrap_Api_handle_error_(wrapped, instance, args, kwargs):

    # If calling wrapped raises an exception, the error will bubble up to
    # flask's exception handler and we will capture it there.
    resp = wrapped(*args, **kwargs)

    notice_error(status_code=status_code)

    return resp
コード例 #18
0
    def _test():
        transaction = current_transaction()
        transaction._sampled = True

        with trace_type(*args):
            try:
                raise ValueError("whoops")
            except:
                notice_error()
コード例 #19
0
def test_notice_error_strip_message_in_whitelist():
    settings = application_settings()
    assert settings.strip_exception_messages.enabled
    assert _runtime_error_name in settings.strip_exception_messages.whitelist

    try:
        raise RuntimeError('original error message')
    except RuntimeError:
        notice_error()
コード例 #20
0
def test_notice_error_strip_message_not_in_allowlist():
    settings = application_settings()
    assert settings.strip_exception_messages.enabled
    assert _runtime_error_name not in settings.strip_exception_messages.allowlist

    try:
        raise RuntimeError("message not displayed")
    except RuntimeError:
        notice_error()
コード例 #21
0
def test_span_event_notice_error_overrides_observed(trace_type, args):
    try:
        with trace_type(*args):
            try:
                raise ERROR
            except:
                notice_error()
                raise ValueError
    except ValueError:
        pass
コード例 #22
0
def test_notice_error_multiple_different_type():
    try:
        raise RuntimeError("one")
    except RuntimeError:
        notice_error()

    try:
        raise TypeError("two")
    except TypeError:
        notice_error()
コード例 #23
0
        def _wrapped(request, resolver, exc_info):
            transaction.set_transaction_name(name, priority=1)
            notice_error(exc_info)

            try:
                return wrapped(request, resolver, exc_info)

            except:  # Catch all
                notice_error()
                raise
コード例 #24
0
def test_notice_error_multiple_same_type():
    try:
        raise RuntimeError("one")
    except RuntimeError:
        notice_error()

    try:
        raise RuntimeError("two")
    except RuntimeError:
        notice_error()
コード例 #25
0
def test_notice_error_multiple_same_type():
    try:
        raise RuntimeError('one')
    except RuntimeError:
        notice_error()

    try:
        raise RuntimeError('two')
    except RuntimeError:
        notice_error()
コード例 #26
0
def test_py2_transaction_exception_message_bytes_utf8_encoding_non_english():
    """Assert utf-8 encoded byte produces correct exception message when sys
    encoding is also utf-8.
    """
    try:

        # Bytes literal with non-ascii compatible characters only allowed in
        # python 2

        raise ValueError('I💜🐍')
    except ValueError:
        notice_error()
コード例 #27
0
def test_py3_transaction_exception_message_bytes_non_english():
    """An issue can occur if you cast from bytes to a string in
    python 3 (that is using str(), not using encode/decode methods).
    This is because all characters in bytes are literals, no implicit
    decoding happens, like it does in python 2. You just shouldn't use bytes
    for exception messages in Python 3. THIS TEST ASSERTS THAT THE
    MESSAGE IS WRONG. We do not expect it to work now, or in the future.
    """
    try:
        raise ValueError(BYTES_UTF8_ENCODED)
    except ValueError:
        notice_error()
コード例 #28
0
def fully_featured_app(environ, start_response):
    status = '200 OK'

    path = environ.get('PATH_INFO')
    use_user_attrs = environ.get('record_attributes', 'TRUE') == 'TRUE'

    environ['wsgi.input'].read()
    environ['wsgi.input'].readline()
    environ['wsgi.input'].readlines()

    if use_user_attrs:

        for attr, val in _custom_parameters.items():
            add_custom_parameter(attr, val)

    if 'db' in environ and int(environ['db']) > 0:
        connection = db.connect(":memory:")
        for i in range(int(environ['db']) - 1):
            connection.execute("create table test_db%d (a, b, c)" % i)

    if 'external' in environ:
        for i in range(int(environ['external'])):
            r = urlopen('http://www.python.org')
            r.read(10)

    if 'err_message' in environ:
        n_errors = int(environ.get('n_errors', 1))
        for i in range(n_errors):
            try:

                # append number to stats engine to get unique errors, so they
                # don't immediately get filtered out.

                raise ValueError(environ['err_message'] + str(i))
            except ValueError:
                if use_user_attrs:
                    notice_error(attributes=_err_param)
                else:
                    notice_error()

    text = '<html><head>%s</head><body><p>RESPONSE</p>%s</body></html>'

    output = (text % (get_browser_timing_header(),
                      get_browser_timing_footer())).encode('UTF-8')

    response_headers = [('Content-type', 'text/html; charset=utf-8'),
                        ('Content-Length', str(len(output)))]
    write = start_response(status, response_headers)

    write(b'')

    return [output]
コード例 #29
0
 def __call__(self, *args, **kwargs):
     current_transaction = newrelic.api.transaction.current_transaction()
     if current_transaction:
         webob_exc = newrelic.api.import_hook.import_module('webob.exc')
         try:
             return self.__wrapped(*args, **kwargs)
         except webob_exc.HTTPException:
             raise
         except:  # Catch all
             notice_error()
             raise
     else:
         return self.__wrapped(*args, **kwargs)
コード例 #30
0
def test_py2_transaction_exception_message_bytes_implicit_encoding_non_english():
    """Assert known situation where (implicitly) utf-8 encoded byte string gets
    mangled when default sys encoding is ascii. THIS TEST ASSERTS THAT THE
    MESSAGE IS WRONG. We do not expect it to work now, or in the future.
    """
    try:

        # Bytes literal with non-ascii compatible characters only allowed in
        # python 2

        raise ValueError('I💜🐍')
    except ValueError:
        notice_error()