本文整理汇总了Python中newrelic.agent.wrap_function_wrapper函数的典型用法代码示例。如果您正苦于以下问题:Python wrap_function_wrapper函数的具体用法?Python wrap_function_wrapper怎么用?Python wrap_function_wrapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wrap_function_wrapper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrap_elasticsearch_client_method
def wrap_elasticsearch_client_method(owner, name, arg_extractor, prefix=None):
def _nr_wrapper_Elasticsearch_method_(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
# When arg_extractor is None, it means there is no target field
# associated with this method. Hence this method will only
# create an operation metric and no statement metric. This is
# handled by setting the target to None when calling the
# DatastoreTrace.
if arg_extractor is None:
index = None
else:
index = arg_extractor(*args, **kwargs)
if prefix:
operation = '%s.%s' % (prefix, name)
else:
operation = name
with DatastoreTrace(transaction, product='Elasticsearch',
target=index, operation=operation):
return wrapped(*args, **kwargs)
if hasattr(owner, name):
wrap_function_wrapper(owner, name, _nr_wrapper_Elasticsearch_method_)
示例2: _wrap_Redis_method_wrapper_
def _wrap_Redis_method_wrapper_(module, instance_class_name, operation):
def _nr_wrapper_Redis_method_(wrapped, instance, args, kwargs):
transaction = current_transaction()
if transaction is None:
return wrapped(*args, **kwargs)
dt = DatastoreTrace(
transaction,
product='Redis',
target=None,
operation=operation
)
transaction._nr_datastore_instance_info = (None, None, None)
with dt:
result = wrapped(*args, **kwargs)
host, port_path_or_id, db = transaction._nr_datastore_instance_info
dt.host = host
dt.port_path_or_id = port_path_or_id
dt.database_name = db
return result
name = '%s.%s' % (instance_class_name, operation)
wrap_function_wrapper(module, name, _nr_wrapper_Redis_method_)
示例3: instrument_flask_app
def instrument_flask_app(module):
wrap_wsgi_application(module, 'Flask.wsgi_app',
framework=framework_details())
wrap_function_wrapper(module, 'Flask.add_url_rule',
wrapper_Flask_add_url_rule_input)
wrap_function_wrapper(module, 'Flask.handle_http_exception',
wrapper_Flask_handle_http_exception)
# Use the same wrapper for initial user exception processing and
# fallback for unhandled exceptions.
if hasattr(module.Flask, 'handle_user_exception'):
wrap_function_wrapper(module, 'Flask.handle_user_exception',
wrapper_Flask_handle_exception)
wrap_function_wrapper(module, 'Flask.handle_exception',
wrapper_Flask_handle_exception)
# The _register_error_handler() method was only introduced in
# Flask version 0.7.0.
if hasattr(module.Flask, '_register_error_handler'):
wrap_function_wrapper(module, 'Flask._register_error_handler',
wrapper_Flask__register_error_handler)
示例4: instrument_tornado_wsgi
def instrument_tornado_wsgi(module):
wrap_function_wrapper(module, 'WSGIContainer.__init__',
_nr_wrapper_WSGIContainer___init___)
wrap_function_wrapper(module, 'WSGIContainer.__call__',
_nr_wrapper_WSGIContainer___call___)
wrap_wsgi_application(module, 'WSGIApplication.__call__')
示例5: instrument_tornado_iostream
def instrument_tornado_iostream(module):
if hasattr(module, 'BaseIOStream'):
wrap_function_wrapper(module, 'BaseIOStream._maybe_run_close_callback',
maybe_run_close_callback_wrapper)
elif hasattr(module.IOStream, '_maybe_run_close_callback'):
wrap_function_wrapper(module, 'IOStream._maybe_run_close_callback',
maybe_run_close_callback_wrapper)
示例6: instrument_urllib3_connection
def instrument_urllib3_connection(module):
# Don't combine the instrument functions into a single function. Keep
# the 'connect' monkey patch separate, because it is also used to patch
# urllib3 within the requests package.
wrap_function_wrapper(module, 'HTTPConnection.connect',
functools.partial(httplib_connect_wrapper, scheme='http'))
wrap_function_wrapper(module, 'HTTPSConnection.connect',
functools.partial(httplib_connect_wrapper, scheme='https'))
示例7: instrument_memcache
def instrument_memcache(module):
wrap_function_wrapper(module.Client, '_get_server', _nr_get_server_wrapper)
for name in _memcache_client_methods:
if hasattr(module.Client, name):
wrap_memcache_single(module, name,
product='Memcached', target=None, operation=name)
for name in _memcache_multi_methods:
if hasattr(module.Client, name):
wrap_datastore_trace(module.Client, name,
product='Memcached', target=None, operation=name)
示例8: instrument_gearman_client
def instrument_gearman_client(module):
wrap_function_trace(module, 'GearmanClient.submit_job')
wrap_function_trace(module, 'GearmanClient.submit_multiple_jobs')
wrap_function_trace(module, 'GearmanClient.submit_multiple_requests')
wrap_function_trace(module, 'GearmanClient.wait_until_jobs_accepted')
wrap_function_trace(module, 'GearmanClient.wait_until_jobs_completed')
wrap_function_trace(module, 'GearmanClient.get_job_status')
wrap_function_trace(module, 'GearmanClient.get_job_statuses')
wrap_function_trace(module, 'GearmanClient.wait_until_job_statuses_received')
wrap_function_wrapper(module, 'GearmanClient.poll_connections_until_stopped',
wrapper_GearmanClient_poll_connections_until_stopped)
示例9: instrument_dyndns53
def instrument_dyndns53(module):
wrap_function_trace(module, 'initialise_database')
wrap_function_trace(module, 'download_database')
wrap_function_trace(module, 'upload_database')
wrap_function_trace(module, 'register_ip')
wrap_function_trace(module, 'BasicAuthDatabase.check_credentials')
wrap_function_wrapper(module, 'register_ip', wrapper_register_ip)
for name, callback in list(module._commands.items()):
module._commands[name] = BackgroundTaskWrapper(callback)
示例10: instrument
def instrument(module):
wrap_function_wrapper(module, 'HTTPConnectionWithTimeout.connect',
_nr_wrapper_httplib2_connect_wrapper('http'))
wrap_function_wrapper(module, 'HTTPSConnectionWithTimeout.connect',
_nr_wrapper_httplib2_connect_wrapper('https'))
def url_request(connection, uri, *args, **kwargs):
return uri
newrelic.api.external_trace.wrap_external_trace(
module, 'Http.request', 'httplib2', url_request)
示例11: instrument_dyndns53
def instrument_dyndns53(module):
wrap_function_trace(module, 'initialise_database')
wrap_function_trace(module, 'download_database')
wrap_function_trace(module, 'upload_database')
wrap_function_trace(module, 'register_ip')
wrap_function_trace(module, 'BasicAuthDatabase.check_credentials')
wrap_background_task(module, 'upload_database_command')
wrap_background_task(module, 'download_database_command')
wrap_function_wrapper(module, 'register_ip', wrapper_register_ip)
示例12: instrument_tornado_gen
def instrument_tornado_gen(module):
# The Return class type was introduced in Tornado 3.0.
global GeneratorReturn
if hasattr(module, 'Return'):
GeneratorReturn = module.Return
# The gen.coroutine decorator was introduced in Tornado 3.0.
if hasattr(module, 'coroutine'):
wrap_function_wrapper(module, 'coroutine', _nr_wrapper_gen_coroutine_)
# The gen.engine decorator, Runner class type and Task class type
# were introduced in Tornado 2.0.
if hasattr(module, 'engine'):
wrap_function_wrapper(module, 'engine', _nr_wrapper_gen_coroutine_)
if hasattr(module, 'Runner'):
wrap_function_wrapper(module, 'Runner.__init__',
_nr_wrapper_gen_Runner___init___)
if hasattr(module, 'Task'):
if hasattr(module.Task, 'start'):
# The start() method was removed in Tornado 4.0.
wrap_function_wrapper(module, 'Task.start',
_nr_wrapper_Task_start_)
示例13: instrument_tornado_wsgi
def instrument_tornado_wsgi(module):
wrap_function_wrapper(module, 'WSGIContainer.__init__',
_nr_wrapper_WSGIContainer___init___)
wrap_function_wrapper(module, 'WSGIContainer.__call__',
_nr_wrapper_WSGIContainer___call___)
import tornado
if hasattr(tornado, 'version_info'):
version = '.'.join(map(str, tornado.version_info))
else:
version = None
wrap_wsgi_application(module, 'WSGIApplication.__call__',
framework=('Tornado/WSGI', version))
示例14: instrument_pybald_app
def instrument_pybald_app(app, name=None):
'''
Monkeypatch the Pybald Router and instrument the WSGI stack with
FunctionTrace wrappers.
This allows the breakdown of all of the components in the Pybald stack and
also sets the transaction names to the controller/action pairs for
user code.
:param app: A WSGI application to apply newrelic instrumentation to
:param name: The (optional) name of the application
'''
import pybald.core.router
wrap_function_wrapper(pybald.core.router, 'Router.get_handler',
wrapper_Pybald_Router_get_handler)
return instrument_pybald(app, name=name)
示例15: patch_motor
def patch_motor(module):
wrap_function_wrapper(module, 'MotorClient.__getattr__',
_nr_wrapper_Motor_getattr_)
wrap_function_wrapper(module, 'MotorReplicaSetClient.__getattr__',
_nr_wrapper_Motor_getattr_)
wrap_function_wrapper(module, 'MotorDatabase.__getattr__',
_nr_wrapper_Motor_getattr_)
wrap_function_wrapper(module, 'MotorCollection.__getattr__',
_nr_wrapper_Motor_getattr_)