本文整理汇总了Python中newrelic.api.transaction.current_transaction函数的典型用法代码示例。如果您正苦于以下问题:Python current_transaction函数的具体用法?Python current_transaction怎么用?Python current_transaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current_transaction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: error_wrapper
def error_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is not None:
record_exception(transaction, sys.exc_info())
return wrapped(*args, **kwargs)
示例3: generate_headers_wrapper
def generate_headers_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
transaction._thread_utilization_start = None
status = '%d ???' % instance.get_status()
# The HTTPHeaders class with get_all() only started to
# be used in Tornado 3.0. For older versions have to fall
# back to combining the dictionary and list of headers.
try:
response_headers = instance._headers.get_all()
except AttributeError:
try:
response_headers = itertools.chain(
instance._headers.items(),
instance._list_headers)
except AttributeError:
response_headers = itertools.chain(
instance._headers.items(),
instance._headers)
additional_headers = transaction.process_response(
status, response_headers, *args)
for name, value in additional_headers:
instance.add_header(name, value)
return wrapped(*args, **kwargs)
示例4: wrapper
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
def _wrapped(request, view_func, view_args, view_kwargs):
# This strips the view handler wrapper before call.
if hasattr(view_func, '_nr_last_object'):
view_func = view_func._nr_last_object
return wrapped(request, view_func, view_args, view_kwargs)
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)
示例5: dynamic_wrapper
def dynamic_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
if callable(url):
if instance and inspect.ismethod(wrapped):
_url = url(instance, *args, **kwargs)
else:
_url = url(*args, **kwargs)
else:
_url = url
if callable(method):
if instance and inspect.ismethod(wrapped):
_method = method(instance, *args, **kwargs)
else:
_method = method(*args, **kwargs)
else:
_method = method
with ExternalTrace(transaction, library, _url, _method):
return wrapped(*args, **kwargs)
示例6: 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)
示例7: literal_wrapper
def literal_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
with ExternalTrace(transaction, library, url, method):
return wrapped(*args, **kwargs)
示例8: wrapper
def wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
with ErrorTrace(transaction, ignore_errors):
return wrapped(*args, **kwargs)
示例9: template_generate_wrapper
def template_generate_wrapper(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
with FunctionTrace(transaction, name=instance.name, group="Template/Render"):
return wrapped(*args, **kwargs)
示例10: 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)
示例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: finish_request_wrapper
def finish_request_wrapper(wrapped, instance, args, kwargs):
assert instance is not None
request = instance._request
transaction = current_transaction()
if transaction:
request._nr_request_finished = True
try:
result = wrapped(*args, **kwargs)
if (hasattr(request, '_nr_wait_function_trace') and
request._nr_wait_function_trace):
request._nr_wait_function_trace.__exit__(None, None, None)
finally:
request._nr_wait_function_trace = None
return result
else:
if not hasattr(request, '_nr_transaction'):
return wrapped(*args, **kwargs)
transaction = request._nr_transaction
if transaction is None:
return wrapped(*args, **kwargs)
transaction.save_transaction()
request._nr_request_finished = True
try:
result = wrapped(*args, **kwargs)
if request._nr_wait_function_trace:
request._nr_wait_function_trace.__exit__(None, None, None)
transaction.__exit__(None, None, None)
except: # Catch all
transaction.__exit__(*sys.exc_info())
raise
finally:
request._nr_wait_function_trace = None
request._nr_transaction = None
return result
示例15: inner_fn_wrapper
def inner_fn_wrapper(inner_fn, instance, args, kwargs):
transaction = current_transaction()
if transaction is None or name is None:
return inner_fn(*args, **kwargs)
transaction.name_transaction(name, group, priority=4)
with FunctionTrace(transaction, name, group):
try:
return inner_fn(*args, **kwargs)
except:
transaction.record_exception(*sys.exc_info())