本文整理汇总了Python中newrelic.agent.callable_name函数的典型用法代码示例。如果您正苦于以下问题:Python callable_name函数的具体用法?Python callable_name怎么用?Python callable_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callable_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _nr_wrapper_RequestHandler__execute_
def _nr_wrapper_RequestHandler__execute_(wrapped, instance, args, kwargs):
handler = instance
request = handler.request
if request is None:
_logger.error('Runtime instrumentation error. Calling _execute on '
'a RequestHandler when no request is present. Please '
'report this issue to New Relic support.\n%s',
''.join(traceback.format_stack()[:-1]))
return wrapped(*args, **kwargs)
transaction = retrieve_request_transaction(request)
if transaction is None:
return wrapped(*args, **kwargs)
if request.method not in handler.SUPPORTED_METHODS:
# If the method isn't one of the supported ones, then we expect the
# wrapped method to raise an exception for HTTPError(405). In this case
# we name the transaction after the wrapped method.
name = callable_name(wrapped)
else:
# Otherwise we name the transaction after the handler function that
# should end up being executed for the request.
name = callable_name(getattr(handler, request.method.lower()))
transaction.set_transaction_name(name)
# We need to set the current transaction so that the user code executed by
# running _execute is traced to the transaction we grabbed off the request
with TransactionContext(transaction):
return wrapped(*args, **kwargs)
示例2: _wrapper
def _wrapper(context, request):
transaction = current_transaction()
if not transaction:
return wrapper(context, request)
name = callable_name(view)
with FunctionTrace(transaction, name=name) as tracer:
try:
return wrapper(context, request)
finally:
attr = instance.attr
if attr:
inst = getattr(request, '__view__')
name = callable_name(getattr(inst, attr))
transaction.set_transaction_name(name, priority=1)
tracer.name = name
else:
inst = getattr(request, '__view__')
method = getattr(inst, '__call__')
if method:
name = callable_name(method)
transaction.set_transaction_name(name, priority=1)
tracer.name = name
示例3: wrapper
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
def _args(request, *args, **kwargs):
return request
view = instance
request = _args(*args, **kwargs)
# We can't intercept the delegated view handler when it
# is looked up by the dispatch() method so we need to
# duplicate the lookup mechanism.
if request.method.lower() in view.http_method_names:
handler = getattr(view, request.method.lower(),
view.http_method_not_allowed)
else:
handler = view.http_method_not_allowed
name = callable_name(handler)
# The priority to be used when naming the transaction is
# bit tricky. If the transaction name is already that of
# the class based view, but not the method, then we want
# the name of the method to override. This can occur
# where the class based view was registered directly in
# urls.py as the view handler. In this case we use the
# priority of 5, matching what would be used by the view
# handler so that it can override the transaction name.
#
# If however the transaction name is unrelated, we
# preferably don't want it overridden. This can happen
# where the class based view was invoked explicitly
# within an existing view handler. In this case we use
# the priority of 4 so it will not override the view
# handler name where used as the transaction name.
priority = 4
if transaction.group == 'Function':
if transaction.name == callable_name(view):
priority = 5
transaction.set_transaction_name(name, priority=priority)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
示例4: _callback_wrapper
def _callback_wrapper(wrapped, instance, args, kwargs):
if retrieve_current_transaction():
return wrapped(*args, **kwargs)
transaction = resume_request_monitoring(request)
if transaction is None:
return wrapped(*args, **kwargs)
try:
name = callable_name(wrapped)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
except Exception:
record_exception(transaction, sys.exc_info())
raise
finally:
if not request_finished(request):
suspend_request_monitoring(request, name='Callback/Wait')
elif not request.connection.stream.writing():
finalize_request_monitoring(request)
else:
suspend_request_monitoring(request, name='Request/Output')
示例5: wrapper
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
def _args(request, *args, **kwargs):
return request
view = instance
request = _args(*args, **kwargs)
# We can't intercept the delegated view handler when it
# is looked up by the dispatch() method so we need to
# duplicate the lookup mechanism.
if request.method.lower() in view.http_method_names:
handler = getattr(view, request.method.lower(),
view.http_method_not_allowed)
else:
handler = view.http_method_not_allowed
name = callable_name(handler)
transaction.set_transaction_name(name, priority=4)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
示例6: callback_wrapper
def callback_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
name = callable_name(wrapped)
# Needs to be at a higher priority so that error handler processing
# below will not override the web transaction being named after the
# actual request handler.
transaction.set_transaction_name(name, priority=2)
with FunctionTrace(transaction, name):
try:
return wrapped(*args, **kwargs)
except: # Catch all
# In most cases this seems like it will never be invoked as
# bottle will internally capture the exception before we
# get a chance and rather than propagate the exception will
# return it instead. This doesn't always seem to be the case
# though when plugins are used, although that may depend on
# the specific bottle version being used.
transaction.record_exception(ignore_errors=should_ignore)
raise
示例7: wrap_view_handler
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 '_nr_django_view_handler' attribute.
if hasattr(wrapped, '_nr_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._nr_django_view_handler = True
return result
示例8: wrap_handle_uncaught_exception
def wrap_handle_uncaught_exception(middleware):
# Wrapper to be applied to handler called when exceptions
# propagate up to top level from middleware. Records the
# time spent in the handler as separate function node. Names
# the web transaction after the name of the handler if not
# already named at higher priority and capture further
# errors in the handler.
name = callable_name(middleware)
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
def _wrapped(request, resolver, exc_info):
transaction.set_transaction_name(name, priority=1)
transaction.record_exception(*exc_info)
try:
return wrapped(request, resolver, exc_info)
except: # Catch all
transaction.record_exception(*sys.exc_info())
raise
with FunctionTrace(transaction, name=name):
return _wrapped(*args, **kwargs)
return FunctionWrapper(middleware, wrapper)
示例9: _coroutine_name
def _coroutine_name(func):
# Because of how coroutines get scheduled they will look like plain
# functions (and not methods) in python 2 and will not have a class
# associated with them. In particular, func will not have the attribute
# im_class. This means callable_name will return the function name without
# the class prefix. See PYTHON-1798.
return '%s %s' % (callable_name(func), '(coroutine)')
示例10: _nr_wrapper_RequestHandler__execute_
def _nr_wrapper_RequestHandler__execute_(wrapped, instance, args, kwargs):
# Prior to Tornado 3.1, the calling of the handler request method
# was performed from within RequestHandler._execute(). Any prepare()
# method was called immediately and could not be a coroutine. For
# later versions of Tornado, if the prepare() method is a coroutine
# and the future cannot be completed immediately, then the handler
# request method will be called from _execute_method() instead when
# prepare() completes.
handler = instance
request = handler.request
# Check to see if we are being called within the context of any sort
# of transaction. If we aren't, then we don't bother doing anything and
# just call the wrapped function.
transaction = retrieve_current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
# If the method isn't one of the supported ones, then we expect the
# wrapped method to raise an exception for HTTPError(405). Name the
# transaction after the wrapped method first so it is used if that
# occurs.
name = callable_name(wrapped)
transaction.set_transaction_name(name)
if request.method not in handler.SUPPORTED_METHODS:
return wrapped(*args, **kwargs)
# Otherwise we name the transaction after the handler function that
# should end up being executed for the request. We don't create a
# function trace node at this point as that is handled by the fact
# that we wrapped the exposed methods from the wrapper for the
# constructor of the request handler.
name = callable_name(getattr(handler, request.method.lower()))
transaction.set_transaction_name(name)
# Call the original RequestHandler._execute(). So long as the
# prepare() method is not a coroutine which doesn't complete
# straight away, then the actual handler function handler should
# also be called at this point.
return wrapped(*args, **kwargs)
示例11: _nr_wrapper_IOLoop_add_callback_
def _nr_wrapper_IOLoop_add_callback_(wrapped, instance, args, kwargs):
transaction = retrieve_current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
name = callable_name(wrapped)
def _args(callback, *args, **kwargs):
return callback
callback = _args(*args, **kwargs)
params = dict(callback=callable_name(callback))
with FunctionTrace(transaction, name, params=params, terminal=True):
return wrapped(*args, **kwargs)
示例12: _requesthandler_function_trace
def _requesthandler_function_trace(wrapped, instance, args, kwargs):
# Use this function tracer when a function you want to trace is called
# synchronously from a function that is already in the transaction, such as
# web.RequestHandler._execute.
transaction = retrieve_current_transaction()
name = callable_name(wrapped)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
示例13: _nr_stack_context_function_wrapper_
def _nr_stack_context_function_wrapper_(wrapped, instance, args, kwargs):
# We can come in here with either an active transaction
# or a request with a transaction bound to it. If there
# is an active transaction then call the wrapped function
# within function trace and return immediately.
transaction = retrieve_current_transaction()
if transaction is not None:
name = callable_name(wrapped)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
# For the case of a request with a transaction bound to
# it, we need to resume the transaction and then call it.
# As we resumed the transaction, need to handle
# suspending or finalizing it.
transaction = resume_request_monitoring(request)
if transaction is None:
return wrapped(*args, **kwargs)
try:
name = callable_name(wrapped)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
except: # Catch all.
record_exception(transaction, sys.exc_info())
raise
finally:
if not request_finished(request):
suspend_request_monitoring(request, name='Callback/Wait')
elif not request.connection.stream.writing():
finalize_request_monitoring(request)
else:
suspend_request_monitoring(request, name='Request/Output')
示例14: __exit__
def __exit__(self, exc, value, tb):
transaction = current_transaction()
name = callable_name(self.__wrapped__.__exit__)
with FunctionTrace(transaction, name):
if exc is None:
with DatabaseTrace(transaction, "COMMIT", self._nr_dbapi2_module):
return self.__wrapped__.__exit__(exc, value, tb)
else:
with DatabaseTrace(transaction, "ROLLBACK", self._nr_dbapi2_module):
return self.__wrapped__.__exit__(exc, value, tb)
示例15: __enter__
def __enter__(self):
transaction = current_transaction()
name = callable_name(self.__wrapped__.__enter__)
with FunctionTrace(transaction, name):
cursor = self.__wrapped__.__enter__()
# The __enter__() method of original connection object returns
# a new cursor instance for use with 'as' assignment. We need
# to wrap that in a cursor wrapper otherwise we will not track
# any queries done via it.
return self.__cursor_wrapper__(cursor, self._nr_dbapi2_module, self._nr_connect_params, None)