当前位置: 首页>>代码示例>>Python>>正文


Python agent.current_transaction函数代码示例

本文整理汇总了Python中newrelic.agent.current_transaction函数的典型用法代码示例。如果您正苦于以下问题:Python current_transaction函数的具体用法?Python current_transaction怎么用?Python current_transaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了current_transaction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:28,代码来源:framework_bottle.py

示例2: 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)
开发者ID:TheTincho,项目名称:python-newrelic,代码行数:27,代码来源:framework_django.py

示例3: _nr_wrapper_Elasticsearch_method_

    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)
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:25,代码来源:datastore_elasticsearch.py

示例4: httplib_getresponse_wrapper

def httplib_getresponse_wrapper(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    connection = instance
    tracer = getattr(connection, "_nr_external_tracer", None)

    if not tracer:
        return wrapped(*args, **kwargs)

    response = wrapped(*args, **kwargs)

    # Make sure we remove the tracer from the connection object so that it
    # doesn't hold onto objects. Do this after we call the wrapped function so
    # if an exception occurs the higher library might retry the call again with
    # the same connection object. Both urllib3 and requests do this in Py2.7

    del connection._nr_external_tracer

    if hasattr(tracer, "process_response_headers"):
        tracer.process_response_headers(response.getheaders())

    return response
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:25,代码来源:external_httplib.py

示例5: httplib_endheaders_wrapper

def httplib_endheaders_wrapper(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    connection = instance

    # Check if the NR headers have already been added. This is just in
    # case a higher level library which uses httplib underneath so
    # happened to have been instrumented to also add the headers.

    try:
        skip_headers = getattr(connection, "_nr_skip_headers", False)

        if skip_headers:
            return wrapped(*args, **kwargs)

        outgoing_headers = ExternalTrace.generate_request_headers(transaction)
        for header_name, header_value in outgoing_headers:
            connection.putheader(header_name, header_value)

        return wrapped(*args, **kwargs)

    finally:
        try:
            del connection._nr_skip_headers
        except AttributeError:
            pass
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:29,代码来源:external_httplib.py

示例6: wrapper_RoutesDispatcher_find_handler

def wrapper_RoutesDispatcher_find_handler(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    try:
        # Call the original wrapped function to find the handler.

        handler = wrapped(*args, **kwargs)

    except:  # Catch all
        # Can end up here when the URL was invalid in some way.

        transaction.record_exception()
        raise

    if handler:
        # Should be the actual handler, wrap it with the handler
        # wrapper.

        handler = handler_wrapper(handler)

    else:
        # No handler could be found so name the web transaction
        # after the 404 status code.

        transaction.set_transaction_name('404', group='StatusCode')

    return handler
开发者ID:Arable,项目名称:evepod,代码行数:30,代码来源:framework_cherrypy.py

示例7: _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
开发者ID:dmathewwws,项目名称:twitter-sentiment-analysis-python,代码行数:25,代码来源:framework_pyramid.py

示例8: _nr_wrapper_httplib2_connect_wrapper_inner

    def _nr_wrapper_httplib2_connect_wrapper_inner(wrapped, instance, args,
            kwargs):
        transaction = current_transaction()

        if transaction is None:
            return wrapped(*args, **kwargs)

        def _connect_unbound(instance, *args, **kwargs):
            return instance

        if instance is None:
            instance = _connect_unbound(*args, **kwargs)

        connection = instance

        url = '%s://%s:%s' % (scheme, connection.host, connection.port)

        with ExternalTrace(transaction, library='httplib2', url=url) as tracer:
            # Add the tracer to the connection object. The tracer will be
            # used in getresponse() to add back into the external trace,
            # after the trace has already completed, details from the
            # response headers.

            connection._nr_external_tracer = tracer

            return wrapped(*args, **kwargs)
开发者ID:bobbyrward,项目名称:newrelic,代码行数:26,代码来源:external_httplib2.py

示例9: callproc

 def callproc(self, procname, parameters=DEFAULT):
     transaction = current_transaction()
     with DatabaseTrace(transaction, "CALL %s" % procname, self._nr_dbapi2_module):
         if parameters is not DEFAULT:
             return self.__wrapped__.callproc(procname, parameters)
         else:
             return self.__wrapped__.callproc(procname)
开发者ID:kuangchanglang,项目名称:python-newrelic,代码行数:7,代码来源:database_dbapi2.py

示例10: wrapper_GearmanConnectionManager_handle_function

def wrapper_GearmanConnectionManager_handle_function(wrapped, instance,
        args, kwargs):

    def _bind_params(current_connection, *args, **kwargs):
        return current_connection

    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    tracer = transaction.active_node()

    if not isinstance(tracer, ExternalTrace):
        return wrapped(*args, **kwargs)

    # Now override the URL for the external to be the specific server we
    # ended up communicating with. This could get overridden multiple
    # times in the context of a single poll_connections_until_stopped()
    # call and so will be set to the last server data was processed for.
    # This thus may not necessarily be correct if commnicating with
    # multiple servers and data from more than one was being handled for
    # some reason. Can't really do much better than this though but will
    # be fine for the expected typical use case of a single server.

    if not tracer.url.startswith('gearman:'):
        return wrapped(*args, **kwargs)

    current_connection = _bind_params(*args, **kwargs)

    tracer.url = 'gearman://%s:%s' % (current_connection.gearman_host,
            current_connection.gearman_port)

    return wrapped(*args, **kwargs)
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:34,代码来源:application_gearman.py

示例11: retrieve_current_transaction

def retrieve_current_transaction():
    # Retrieves the current transaction regardless of whether it has
    # been stopped or ignored. We sometimes want to purge the current
    # transaction from the transaction cache and remove it with the
    # known current transaction that is being called into asynchronously.

    return current_transaction(active_only=False)
开发者ID:bobbyrward,项目名称:newrelic,代码行数:7,代码来源:util.py

示例12: execute

 def execute(self, sql, parameters=DEFAULT):
     transaction = current_transaction()
     if parameters is not DEFAULT:
         with DatabaseTrace(transaction, sql, self._nr_dbapi2_module, self._nr_connect_params, None, parameters):
             return self.__wrapped__.execute(sql, parameters)
     else:
         with DatabaseTrace(transaction, sql, self._nr_dbapi2_module, self._nr_connect_params):
             return self.__wrapped__.execute(sql)
开发者ID:kuangchanglang,项目名称:python-newrelic,代码行数:8,代码来源:database_sqlite.py

示例13: wrapper_AWSAuthConnection_make_request

def wrapper_AWSAuthConnection_make_request(wrapped, instance, args, kwargs):
    transaction = current_transaction()

    if transaction is None:
        return wrapped(*args, **kwargs)

    url = '%s://%s%s' % (instance.protocol, instance.host, instance.path)

    with ExternalTrace(transaction, 'boto', url):
        return wrapped(*args, **kwargs)
开发者ID:simbha,项目名称:dyndns53,代码行数:10,代码来源:instrument.py

示例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)
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:10,代码来源:database_mysqldb.py

示例15: _wrapper

 def _wrapper(*args, **kargs):
     transaction = current_transaction()
     if transaction is None:
         return method(*args, **kargs)
     # name = "{0}:{1}".format(controller_name, action_name)
     # name = callable_name(wrapped)
     # console.debug(name)
     transaction.set_transaction_name(name)
     with FunctionTrace(transaction, name, group="Python"):
         return method(*args, **kargs)
开发者ID:killthrush,项目名称:pybald,代码行数:10,代码来源:pybald_newrelic.py


注:本文中的newrelic.agent.current_transaction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。