• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python agent.callable_name函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了callable_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:bobbyrward,项目名称:newrelic,代码行数:33,代码来源:web.py


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


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


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


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


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


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


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


示例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)')
开发者ID:bobbyrward,项目名称:newrelic,代码行数:7,代码来源:gen.py


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


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


示例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)
开发者ID:bobbyrward,项目名称:newrelic,代码行数:9,代码来源:web.py


示例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')
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:44,代码来源:stack_context.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: __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)
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:12,代码来源:database_mysqldb.py


示例16: close

    def close(self): 
        try: 
            with FunctionTrace(self.transaction, name='Finalize', 
                    group='Python/WSGI'): 
                if hasattr(self.generator, 'close'): 
                    name = callable_name(self.generator.close) 
                    with FunctionTrace(self.transaction, name): 
                        self.generator.close() 

        except: # Catch all 
            self.transaction.record_exception() 
            raise
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:12,代码来源:wsgi.py


示例17: _nr_wrapper_Flask_before_request_wrapped_

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

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

    name = callable_name(wrapped)

    transaction.set_transaction_name(name)

    with FunctionTrace(transaction, name):
        return wrapped(*args, **kwargs)
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:12,代码来源:framework_flask.py


示例18: __exit__

 def __exit__(self, exc, value, tb):
     transaction = current_transaction()
     name = callable_name(self.__wrapped__.__exit__)
     with FunctionTrace(transaction, name):
         if exc is None and value is None and tb is None:
             with DatabaseTrace(transaction, 'COMMIT',
                     self._nr_dbapi2_module, self._nr_connect_params):
                 return self.__wrapped__.__exit__(exc, value, tb)
         else:
             with DatabaseTrace(transaction, 'ROLLBACK',
                     self._nr_dbapi2_module, self._nr_connect_params):
                 return self.__wrapped__.__exit__(exc, value, tb)
开发者ID:edmorley,项目名称:newrelic-python-agent,代码行数:12,代码来源:database_sqlite.py


示例19: wrapper_Resource_method

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

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

    name = callable_name(wrapped)

    transaction.set_transaction_name(name)
    
    with FunctionTrace(transaction, name):
        return wrapped(*args, **kwargs)
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:12,代码来源:component_cornice.py


示例20: _nr_wrapper_HTTPServerRequest__init__

def _nr_wrapper_HTTPServerRequest__init__(wrapped, instance, args, kwargs):
    # This is the first point of entry into our instrumentation. It gets called
    # after header but before the request body is read in one of 3 possible
    # places:
    #   web.py: The normal case when the application passed to the HTTPServer
    #     is an Tornado 4 Application object.
    #   httpserver.py: A strange case where the application passed to the
    #     HTTPServer is not a Tornado 4 Application object (so the
    #     HTTPServerAdapter has no delegate).
    #   wsgi.py: Needs more exploration.
    #
    # After this is called the request body may be streamed or not depending on
    # the application configuration (see tornado.web.stream_request_body).

    assert instance is not None

    result = wrapped(*args, **kwargs)

    # instance is now an initiated HTTPServerRequest object. Since instance was
    # just created there can not be a previously associated transaction.

    request = instance

    if is_websocket(request):
        transaction = None
    else:
        transaction = initiate_request_monitoring(request)

    # Transaction can still be None at this point, if it wasn't enabled during
    # WebTransaction.__init__().

    if transaction:

        # Name transaction initially after the wrapped function so that if
        # the connection is dropped before all the request content is read,
        # then we don't get metric grouping issues with it being named after
        # the URL.

        name = callable_name(wrapped)
        transaction.set_transaction_name(name)

        # Use HTTPServerRequest start time as transaction start time.

        transaction.start_time = request._start_time

    # Even if transaction is `None`, we still attach it to the request, so we
    # can distinguish between a missing _nr_transaction attribute (error) from
    # the case where _nr_transaction is None (ok).

    request._nr_transaction = transaction

    return result
开发者ID:bobbyrward,项目名称:newrelic,代码行数:52,代码来源:httputil.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python agent.current_transaction函数代码示例发布时间:2022-05-27
下一篇:
Python models.UserManager类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap