def wrap_view_handler(wrapped, priority=3): # Ensure we don't wrap the view handler more than once. This # looks like it may occur in cases where the resolver is # called recursively. We flag that view handler was wrapped # using the '_bw_django_view_handler' attribute. if hasattr(wrapped, '_bw_django_view_handler'): return wrapped name = callable_name(wrapped) def wrapper(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) transaction.set_transaction_name(name, priority=priority) with FunctionTrace(transaction, name=name): try: return wrapped(*args, **kwargs) except: # Catch all transaction.record_exception(ignore_errors=should_ignore) raise result = FunctionWrapper(wrapped, wrapper) result._bw_django_view_handler = True return result
def wrapper(wrapped): # The middleware if a class method would already be # bound at this point, so is safe to determine the name # when it is being wrapped rather than on each # invocation. name = callable_name(wrapped) def wrapper(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) before = (transaction.name, transaction.group) with FunctionTrace(transaction, name=name): try: return wrapped(*args, **kwargs) finally: # We want to name the transaction after this # middleware but only if the transaction wasn't # named from within the middleware itself explicity. after = (transaction.name, transaction.group) if before == after: transaction.set_transaction_name(name, priority=2) return FunctionWrapper(wrapped, wrapper)
def _bw_stack_context_wrap_wrapper_(wrapped, instance, args, kwargs): def _args(fn, *args, **kwargs): return fn transaction = retrieve_current_transaction() if not transaction: return wrapped(*args, **kwargs) request = retrieve_transaction_request(transaction) if request is None: return wrapped(*args, **kwargs) fn = _args(*args, **kwargs) # We need to filter out certain out types of wrapped functions. # Tornado 3.1 doesn't use _StackContextWrapper and checks for a # '_wrapped' attribute instead which makes this a bit more fragile. if hasattr(module_stack_context, '_StackContextWrapper'): if (fn is None or fn.__class__ is module_stack_context._StackContextWrapper): return fn else: if fn is None or hasattr(fn, '_wrapped'): return fn fn = FunctionWrapper(fn, _bw_stack_context_wrap_wrapped_(request)) return wrapped(fn)
def wrapper(wrapped): # The middleware if a class method would already be # bound at this point, so is safe to determine the name # when it is being wrapped rather than on each # invocation. name = callable_name(wrapped) def wrapper(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) with FunctionTrace(transaction, name=name): return wrapped(*args, **kwargs) return FunctionWrapper(wrapped, wrapper)