patch.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:dd-trace-py 作者: DataDog 项目源码 文件源码
def patch():
    """
    Tracing function that patches the Tornado web application so that it will be
    traced using the given ``tracer``.
    """
    # patch only once
    if getattr(tornado, '__datadog_patch', False):
        return
    setattr(tornado, '__datadog_patch', True)

    # patch Application to initialize properly our settings and tracer
    _w('tornado.web', 'Application.__init__', application.tracer_config)

    # patch RequestHandler to trace all Tornado handlers
    _w('tornado.web', 'RequestHandler._execute', handlers.execute)
    _w('tornado.web', 'RequestHandler.on_finish', handlers.on_finish)
    _w('tornado.web', 'RequestHandler.log_exception', handlers.log_exception)

    # patch Tornado decorators
    _w('tornado.concurrent', 'run_on_executor', decorators._run_on_executor)

    # patch Template system
    _w('tornado.template', 'Template.generate', template.generate)

    # configure the global tracer
    ddtrace.tracer.configure(
        context_provider=TracerStackContext,
        wrap_executor=decorators.wrap_executor,
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号