Ejemplo n.º 1
0
def record_exception(exc=None,
                     value=None,
                     tb=None,
                     params={},
                     ignore_errors=[]):
    transaction = current_transaction()
    if transaction:
        transaction.record_exception(exc, value, tb, params, ignore_errors)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def record_exception(exc=None, value=None, tb=None, params={},
        ignore_errors=[], application=None):
    if application is None:
        transaction = current_transaction()
        if transaction:
            transaction.record_exception(exc, value, tb, params,
                    ignore_errors)
    else:
        if application.enabled:
            application.record_exception(exc, value, tb, params,
                    ignore_errors)
Ejemplo n.º 4
0
def record_exception(exc=None,
                     value=None,
                     tb=None,
                     params={},
                     ignore_errors=[],
                     application=None):
    if application is None:
        transaction = current_transaction()
        if transaction:
            transaction.record_exception(exc, value, tb, params, ignore_errors)
    else:
        if application.enabled:
            application.record_exception(exc, value, tb, params, ignore_errors)
 def __call__(self, *args, **kwargs):
     transaction = newrelic.api.transaction.current_transaction()
     if transaction:
         transaction.name_transaction(name=self.__name, priority=2)
         with newrelic.api.error_trace.ErrorTrace(transaction):
             with newrelic.api.function_trace.FunctionTrace(
                     transaction, name=self.__name):
                 try:
                     return self.__wrapped(*args, **kwargs)
                 except:  # Catch all
                     transaction.record_exception(*sys.exc_info())
                     raise
     else:
         return self.__wrapped(*args, **kwargs)
Ejemplo n.º 6
0
 def __call__(self, *args, **kwargs):
     transaction = newrelic.api.transaction.current_transaction()
     if transaction:
         transaction.name_transaction(name=self.__name, priority=2)
         with newrelic.api.error_trace.ErrorTrace(transaction):
             with newrelic.api.function_trace.FunctionTrace(
                     transaction, name=self.__name):
                 try:
                     return self.__wrapped(*args, **kwargs)
                 except:
                     transaction.record_exception(*sys.exc_info())
                     raise
     else:
         return self.__wrapped(*args, **kwargs)
 def __call__(self, *args, **kwargs):
     transaction = newrelic.api.transaction.current_transaction()
     if transaction:
         try:
             handler = self.__wrapped(*args, **kwargs)
             if handler:
                 handler = HandlerWrapper(handler)
             else:
                 transaction.name_transaction('404', group='Uri')
             return handler
         except:  # Catch all
             transaction.record_exception(*sys.exc_info())
             raise
     else:
         return self.__wrapped(*args, **kwargs)
Ejemplo n.º 8
0
 def __call__(self, *args, **kwargs):
     transaction = newrelic.api.transaction.current_transaction()
     if transaction:
         try:
             handler = self.__wrapped(*args, **kwargs)
             if handler:
                 handler = HandlerWrapper(handler)
             else:
                 transaction.name_transaction('404', group='Uri')
             return handler
         except:
             transaction.record_exception(*sys.exc_info())
             raise
     else:
         return self.__wrapped(*args, **kwargs)
 def __call__(self, *args, **kwargs):
     transaction = newrelic.api.transaction.current_transaction()
     if transaction:
         try:
             obj, vpath = self.__wrapped(*args, **kwargs)
             if obj:
                 klass = self.__instance.__class__
                 if klass.__name__ == 'MethodDispatcher':
                     transaction.name_transaction('405', group='Uri')
                     obj = ResourceWrapper(obj)
                 else:
                     obj = HandlerWrapper(obj)
             else:
                 transaction.name_transaction('404', group='Uri')
             return obj, vpath
         except:  # Catch all
             transaction.record_exception(*sys.exc_info())
             raise
     else:
         return self.__wrapped(*args, **kwargs)
Ejemplo n.º 10
0
 def __call__(self, *args, **kwargs):
     transaction = newrelic.api.transaction.current_transaction()
     if transaction:
         try:
             obj, vpath = self.__wrapped(*args, **kwargs)
             if obj:
                 klass = self.__instance.__class__
                 if klass.__name__ == 'MethodDispatcher':
                     transaction.name_transaction('405', group='Uri')
                     obj = ResourceWrapper(obj)
                 else:
                     obj = HandlerWrapper(obj)
             else:
                 transaction.name_transaction('404', group='Uri')
             return obj, vpath
         except:
             transaction.record_exception(*sys.exc_info())
             raise
     else:
         return self.__wrapped(*args, **kwargs)
Ejemplo n.º 11
0
def wrap_handle_exception(self):
    transaction = newrelic.api.transaction.current_transaction()
    if transaction:
        transaction.record_exception(*sys.exc_info())
def record_exception(exc, value, tb, params={}, ignore_errors=[]):
    transaction = current_transaction()
    if transaction:
        transaction.record_exception(exc, value, tb, params, ignore_errors)
Ejemplo n.º 13
0
    def __call__(self):
        assert self._nr_instance != None

        # Call finish() method straight away if request is not even
        # associated with a transaction.

        if not hasattr(self._nr_instance, '_nr_transaction'):
            return self._nr_next_object()

        # Technically we should only be able to be called here without
        # an active transaction if we are in the wait state. If we
        # are called in context of original request process() function
        # or a deferred the transaction should already be registered.

        transaction = self._nr_instance._nr_transaction

        if self._nr_instance._nr_wait_function_trace:
            if newrelic.api.transaction.current_transaction():
                _logger.debug('The Twisted.Web request finish() method is '
                        'being called while in wait state but there is '
                        'already a current transaction.')
            else:
                transaction.save_transaction()

        elif not newrelic.api.transaction.current_transaction():
            _logger.debug('The Twisted.Web request finish() method is '
                    'being called from request process() method or a '
                    'deferred but there is not a current transaction.')

        # Except for case of being called when in wait state, we can't
        # actually exit the transaction at this point as may be called
        # in context of an outer function trace node. We thus flag that
        # are finished and pop back out allowing outer scope to actually
        # exit the transaction.

        self._nr_instance._nr_is_request_finished = True

        # Now call the original finish() function.

        if self._nr_instance._nr_is_deferred_callback:

            # If we are in a deferred callback log any error against the
            # transaction here so we know we will capture it. We
            # possibly don't need to do it here as outer scope may catch
            # it anyway. Duplicate will be ignored so not too important.
            # Most likely the finish() call would never fail anyway.

            try:
                with newrelic.api.function_trace.FunctionTrace(transaction,
                        name='Request/Finish', group='Python/Twisted'):
                    result = self._nr_next_object()

            except:  # Catch all
                transaction.record_exception(*sys.exc_info())
                raise

        elif self._nr_instance._nr_wait_function_trace:

            # Now handle the special case where finish() was called
            # while in the wait state. We might get here through
            # Twisted.Web itself somehow calling finish() when still
            # waiting for a deferred. If this were to occur though then
            # the transaction will not be popped if we simply marked
            # request as finished as no outer scope to see that and
            # clean up. We will thus need to end the function trace and
            # exit the transaction. We end function trace here and then
            # the transaction down below.

            try:
                self._nr_instance._nr_wait_function_trace.__exit__(
                        None, None, None)

                with newrelic.api.function_trace.FunctionTrace(transaction,
                        name='Request/Finish', group='Python/Twisted'):
                    result = self._nr_next_object()

                transaction.__exit__(None, None, None)

            except:  # Catch all
                transaction.__exit__(*sys.exc_info())
                raise

            finally:
                self._nr_instance._nr_wait_function_trace = None
                self._nr_instance._nr_transaction = None
                self._nr_instance = None

        else:
            # This should be the case where finish() is being called in
            # the original render() function.

            with newrelic.api.function_trace.FunctionTrace(transaction,
                    name='Request/Finish', group='Python/Twisted'):
                result = self._nr_next_object()

        return result
    def __call__(self):
        assert self._nr_instance != None

        # Call finish() method straight away if request is not even
        # associated with a transaction.

        if not hasattr(self._nr_instance, '_nr_transaction'):
            return self._nr_next_object()

        # Technically we should only be able to be called here without
        # an active transaction if we are in the wait state. If we
        # are called in context of original request process() function
        # or a deferred the transaction should already be registered.

        transaction = self._nr_instance._nr_transaction

        if self._nr_instance._nr_wait_function_trace:
            if newrelic.api.transaction.current_transaction():
                _logger.debug('The Twisted.Web request finish() method is '
                              'being called while in wait state but there is '
                              'already a current transaction.')
            else:
                transaction.save_transaction()

        elif not newrelic.api.transaction.current_transaction():
            _logger.debug('The Twisted.Web request finish() method is '
                          'being called from request process() method or a '
                          'deferred but there is not a current transaction.')

        # Except for case of being called when in wait state, we can't
        # actually exit the transaction at this point as may be called
        # in context of an outer function trace node. We thus flag that
        # are finished and pop back out allowing outer scope to actually
        # exit the transaction.

        self._nr_instance._nr_is_request_finished = True

        # Now call the original finish() function.

        if self._nr_instance._nr_is_deferred_callback:

            # If we are in a deferred callback log any error against the
            # transaction here so we know we will capture it. We
            # possibly don't need to do it here as outer scope may catch
            # it anyway. Duplicate will be ignored so not too important.
            # Most likely the finish() call would never fail anyway.

            try:
                with newrelic.api.function_trace.FunctionTrace(
                        transaction, name='Request/Finish',
                        group='Python/Twisted'):
                    result = self._nr_next_object()

            except:  # Catch all
                transaction.record_exception(*sys.exc_info())
                raise

        elif self._nr_instance._nr_wait_function_trace:

            # Now handle the special case where finish() was called
            # while in the wait state. We might get here through
            # Twisted.Web itself somehow calling finish() when still
            # waiting for a deferred. If this were to occur though then
            # the transaction will not be popped if we simply marked
            # request as finished as no outer scope to see that and
            # clean up. We will thus need to end the function trace and
            # exit the transaction. We end function trace here and then
            # the transaction down below.

            try:
                self._nr_instance._nr_wait_function_trace.__exit__(
                    None, None, None)

                with newrelic.api.function_trace.FunctionTrace(
                        transaction, name='Request/Finish',
                        group='Python/Twisted'):
                    result = self._nr_next_object()

                transaction.__exit__(None, None, None)

            except:  # Catch all
                transaction.__exit__(*sys.exc_info())
                raise

            finally:
                self._nr_instance._nr_wait_function_trace = None
                self._nr_instance._nr_transaction = None
                self._nr_instance = None

        else:
            # This should be the case where finish() is being called in
            # the original render() function.

            with newrelic.api.function_trace.FunctionTrace(
                    transaction, name='Request/Finish',
                    group='Python/Twisted'):
                result = self._nr_next_object()

        return result
Ejemplo n.º 15
0
def wrap_handle_exception(self):
    transaction = newrelic.api.transaction.current_transaction()
    if transaction:
        transaction.record_exception(*sys.exc_info())