本文整理汇总了Python中newrelic.api.object_wrapper.callable_name函数的典型用法代码示例。如果您正苦于以下问题:Python callable_name函数的具体用法?Python callable_name怎么用?Python callable_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callable_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _callable_name
def _callable_name():
# This is pretty ugly and inefficient, but a stack
# frame doesn't provide any information about the
# original callable object. We thus need to try and
# deduce what it is by searching through the stack
# frame globals. This will still not work in many
# cases, including lambdas, generator expressions,
# and decoratored attributes such as properties of
# classes.
try:
if func_name in frame.f_globals:
if frame.f_globals[func_name].func_code is co:
return callable_name(frame.f_globals[func_name])
except Exception:
pass
for name, obj in six.iteritems(frame.f_globals):
try:
if obj.__dict__[func_name].func_code is co:
return callable_name(obj.__dict__[func_name])
except Exception:
pass
示例2: 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 = ObjectWrapper(wrapped, None, wrapper)
result._nr_django_view_handler = True
return result
示例3: wrapper
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.name_transaction(name, priority=2)
return ObjectWrapper(wrapped, None, wrapper)
示例4: 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.name_transaction(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 ObjectWrapper(middleware, None, wrapper)
示例5: __init__
def __init__(self, consumer, source, name, settings, **properties):
self.consumer = consumer
self.properties = source(settings)
self.factory = self.properties['factory']
self.instance = None
self.properties.update(properties)
self.name = (name or self.properties.get('name') or
callable_name(source))
self.group = self.properties.get('group')
if self.group:
self.group = self.group.rstrip('/')
environ = {}
environ['consumer.name'] = consumer
environ['consumer.vendor'] = 'New Relic'
environ['producer.name'] = self.name
environ['producer.group'] = self.group
self.environ = environ
_logger.debug('Initialising data sampler for %r.', self.environ)
示例6: dynamic_wrapper
def dynamic_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
if callable(name):
if instance and inspect.ismethod(wrapped):
_name = name(instance, *args, **kwargs)
else:
_name = name(*args, **kwargs)
elif name is None:
_name = callable_name(wrapped)
else:
_name = name
if callable(group):
if instance and inspect.ismethod(wrapped):
_group = group(instance, *args, **kwargs)
else:
_group = group(*args, **kwargs)
else:
_group = group
transaction.name_transaction(_name, _group, priority)
return wrapped(*args, **kwargs)
示例7: on_connection_close_wrapper
def on_connection_close_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction:
return wrapped(*args, **kwargs)
handler = instance
request = handler.request
transaction = getattr(request, '_nr_transaction', None)
if not transaction:
return wrapped(*args, **kwargs)
transaction.save_transaction()
if request._nr_wait_function_trace:
request._nr_wait_function_trace.__exit__(None, None, None)
name = callable_name(wrapped)
try:
with FunctionTrace(transaction, name):
return wrapped(*args, **kwargs)
except Exception:
transaction.record_exception(*sys.exc_info())
finally:
transaction.__exit__(None, None, None)
示例8: wrapper
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if callable(name):
# Start Hotfix v2.2.1.
#if instance and inspect.ismethod(wrapped):
# _name = name(instance, *args, **kwargs)
#else:
# _name = name(*args, **kwargs)
if instance is not None:
_name = name(instance, *args, **kwargs)
else:
_name = name(*args, **kwargs)
# End Hotfix v2.2.1.
elif name is None:
_name = callable_name(wrapped)
else:
_name = name
# Helper for obtaining the appropriate application object. If
# has an activate() method assume it is a valid application
# object. Don't check by type so se can easily mock it for
# testing if need be.
def _application():
if hasattr(application, 'activate'):
return application
return application_instance(application)
# Check to see if we are being called within the context of an
# existing transaction. If we are, then we will record the call
# as a function trace node instead. This situation can occur
# when a function wrapped with Celery task decorator is called
# explicitly in the context of an existing transaction.
if transaction:
with FunctionTrace(transaction, callable_name(wrapped)):
return wrapped(*args, **kwargs)
# Otherwise treat it as top level background task.
with BackgroundTask(_application(), _name, 'Celery'):
return wrapped(*args, **kwargs)
示例9: render_wrapper
def render_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
name = callable_name(wrapped)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
示例10: _name_transaction
def _name_transaction(*args, **kwargs):
transaction = newrelic.api.transaction.current_transaction()
if transaction:
if isinstance(args[1], six.string_types):
f = args[1]
else:
f = callable_name(args[1])
transaction.name_transaction(f)
return (args, kwargs)
示例11: callback_wrapper
def callback_wrapper(wrapped, instance, args, kwargs):
if current_transaction():
return wrapped(*args, **kwargs)
if not hasattr(transaction, '_nr_current_request'):
return wrapped(*args, **kwargs)
request = transaction._nr_current_request()
if not request:
return wrapped(*args, **kwargs)
if not hasattr(request, '_nr_wait_function_trace'):
return wrapped(*args, **kwargs)
if not request._nr_wait_function_trace:
return wrapped(*args, **kwargs)
transaction.save_transaction()
if request._nr_wait_function_trace:
request._nr_wait_function_trace.__exit__(None, None, None)
request._nr_wait_function_trace = None
try:
name = callable_name(wrapped)
with FunctionTrace(transaction, name=name):
return wrapped(*args, **kwargs)
except Exception:
transaction.record_exception(*sys.exc_info())
raise
finally:
if not request._nr_request_finished:
request._nr_wait_function_trace = FunctionTrace(
transaction, name='Callback/Wait',
group='Python/Tornado')
request._nr_wait_function_trace.__enter__()
transaction.drop_transaction()
elif not request.connection.stream.writing():
transaction.__exit__(None, None, None)
request._nr_transaction = None
else:
request._nr_wait_function_trace = FunctionTrace(
transaction, name='Request/Output',
group='Python/Tornado')
request._nr_wait_function_trace.__enter__()
transaction.drop_transaction()
示例12: literal_wrapper
def literal_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
_name = name or callable_name(wrapped)
with FunctionTrace(transaction, _name, group, label, params):
return wrapped(*args, **kwargs)
示例13: literal_wrapper
def literal_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
_name = name or callable_name(wrapped)
transaction.name_transaction(_name, group, priority)
return wrapped(*args, **kwargs)
示例14: wrap_url_resolver
def wrap_url_resolver(wrapped):
# Wrap URL resolver. If resolver returns valid result then
# wrap the view handler returned. The type of the result
# changes across Django versions so need to check and adapt
# as necessary. For a 404 then a user supplied 404 handler
# or the default 404 handler should get later invoked and
# transaction should be named after that.
name = callable_name(wrapped)
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
if hasattr(transaction, '_nr_django_url_resolver'):
return wrapped(*args, **kwargs)
# Tag the transaction so we know when we are in the top
# level call to the URL resolver as don't want to show
# the inner ones as would be one for each url pattern.
transaction._nr_django_url_resolver = True
def _wrapped(path):
# XXX This can raise a Resolver404. If this is not dealt
# with, is this the source of our unnamed 404 requests.
with FunctionTrace(transaction, name=name, label=path):
result = wrapped(path)
if type(result) == type(()):
callback, callback_args, callback_kwargs = result
result = (wrap_view_handler(callback, priority=3),
callback_args, callback_kwargs)
else:
result.func = wrap_view_handler(result.func, priority=3)
return result
try:
return _wrapped(*args, **kwargs)
finally:
del transaction._nr_django_url_resolver
return ObjectWrapper(wrapped, None, wrapper)
示例15: wrap_template_block
def wrap_template_block(wrapped):
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=instance.name,
group='Template/Block'):
return wrapped(*args, **kwargs)
return ObjectWrapper(wrapped, None, wrapper)