Esempio n. 1
0
def patch():
    """Enables Context Propagation between threads"""
    if getattr(futures, "__datadog_patch", False):
        return
    setattr(futures, "__datadog_patch", True)

    _w("concurrent.futures", "ThreadPoolExecutor.submit", _wrap_submit)
Esempio n. 2
0
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 Template system
    _w('tornado.template', 'Template.generate', template.generate)

    # patch Python Futures if available when an Executor pool is used
    compat.wrap_futures()

    # configure the global tracer
    ddtrace.tracer.configure(
        context_provider=context_provider,
        wrap_executor=decorators.wrap_executor,
    )
Esempio n. 3
0
def patch():
    """Enable tracing for all urllib3 requests"""
    if getattr(urllib3, "__datadog_patch", False):
        return
    setattr(urllib3, "__datadog_patch", True)

    _w("urllib3", "connectionpool.HTTPConnectionPool.urlopen", _wrap_urlopen)
Esempio n. 4
0
def patch():
    """Patch the instrumented methods.
    """
    if getattr(sanic, "__datadog_patch", False):
        return
    setattr(sanic, "__datadog_patch", True)
    _w("sanic", "Sanic.handle_request", patch_handle_request)
Esempio n. 5
0
def patch():
    if getattr(starlette, "_datadog_patch", False):
        return

    setattr(starlette, "_datadog_patch", True)

    _w("starlette.applications", "Starlette.__init__", traced_init)
Esempio n. 6
0
def _patch(elasticsearch):
    if getattr(elasticsearch, "_datadog_patch", False):
        return
    setattr(elasticsearch, "_datadog_patch", True)
    _w(elasticsearch.transport, "Transport.perform_request",
       _get_perform_request(elasticsearch))
    Pin().onto(elasticsearch.transport.Transport)
Esempio n. 7
0
def patch():
    """Enables Context Propagation between threads"""
    if getattr(futures, '__datadog_patch', False):
        return
    setattr(futures, '__datadog_patch', True)

    _w('concurrent.futures', 'ThreadPoolExecutor.submit', _wrap_submit)
Esempio n. 8
0
def _patch(elasticsearch):
    if getattr(elasticsearch, "_datadog_patch", False):
        return
    setattr(elasticsearch, "_datadog_patch", True)
    _w(elasticsearch.transport, "Transport.perform_request",
       _get_perform_request(elasticsearch))
    Pin(service=metadata.SERVICE,
        app=metadata.APP).onto(elasticsearch.transport.Transport)
Esempio n. 9
0
def _patch(elasticsearch):
    if getattr(elasticsearch, '_datadog_patch', False):
        return
    setattr(elasticsearch, '_datadog_patch', True)
    _w(elasticsearch.transport, 'Transport.perform_request',
       _get_perform_request(elasticsearch))
    Pin(service=metadata.SERVICE, app=metadata.APP,
        app_type=AppTypes.db).onto(elasticsearch.transport.Transport)
Esempio n. 10
0
def patch():
    if getattr(fastapi, "_datadog_patch", False):
        return

    setattr(fastapi, "_datadog_patch", True)
    Pin().onto(fastapi)
    _w("fastapi.applications", "FastAPI.__init__", traced_init)
    _w("fastapi.routing", "serialize_response", traced_serialize_response)
Esempio n. 11
0
def patch():
    if getattr(sqlalchemy.engine, "__datadog_patch", False):
        return
    setattr(sqlalchemy.engine, "__datadog_patch", True)

    # patch the engine creation function
    _w("sqlalchemy", "create_engine", _wrap_create_engine)
    _w("sqlalchemy.engine", "create_engine", _wrap_create_engine)
Esempio n. 12
0
def patch():
    """Activate http calls tracing"""
    if getattr(requests, "__datadog_patch", False):
        return
    setattr(requests, "__datadog_patch", True)

    _w("requests", "Session.send", _wrap_send)
    Pin(_config=config.requests).onto(requests.Session)
Esempio n. 13
0
def _patch_server():
    if getattr(constants.GRPC_PIN_MODULE_SERVER, '__datadog_patch', False):
        return
    setattr(constants.GRPC_PIN_MODULE_SERVER, '__datadog_patch', True)

    Pin(service=config.grpc_server.service_name).onto(constants.GRPC_PIN_MODULE_SERVER)

    _w('grpc', 'server', _server_constructor_interceptor)
Esempio n. 14
0
def patch():
    if getattr(sqlalchemy.engine, '__datadog_patch', False):
        return
    setattr(sqlalchemy.engine, '__datadog_patch', True)

    # patch the engine creation function
    _w('sqlalchemy', 'create_engine', _wrap_create_engine)
    _w('sqlalchemy.engine', 'create_engine', _wrap_create_engine)
Esempio n. 15
0
def _patch_server():
    if getattr(constants.GRPC_PIN_MODULE_SERVER, "__datadog_patch", False):
        return
    setattr(constants.GRPC_PIN_MODULE_SERVER, "__datadog_patch", True)

    Pin().onto(constants.GRPC_PIN_MODULE_SERVER)

    _w("grpc", "server", _server_constructor_interceptor)
Esempio n. 16
0
def _patch_client():
    if getattr(constants.GRPC_PIN_MODULE_CLIENT, '__datadog_patch', False):
        return
    setattr(constants.GRPC_PIN_MODULE_CLIENT, '__datadog_patch', True)

    Pin(service=config.grpc.service_name).onto(
        constants.GRPC_PIN_MODULE_CLIENT)

    _w('grpc', 'insecure_channel', _client_channel_interceptor)
    _w('grpc', 'secure_channel', _client_channel_interceptor)
Esempio n. 17
0
def patch():
    if getattr(consul, '__datadog_patch', False):
        return
    setattr(consul, '__datadog_patch', True)

    pin = Pin(service='consul', app='consul', app_type=AppTypes.cache)
    pin.onto(consul.Consul.KV)

    for f_name in _KV_FUNCS:
        _w('consul', f_name, wrap_function(f_name))
Esempio n. 18
0
def patch():
    """Patches current loop `create_task()` method to enable spawned tasks to
    parent to the base task context.
    """
    if getattr(asyncio, '_datadog_patch', False):
        return
    setattr(asyncio, '_datadog_patch', True)

    loop = asyncio.get_event_loop()
    _w(loop, 'create_task', _wrapped_create_task)
Esempio n. 19
0
def patch_pymongo_module():
    if getattr(pymongo, "_datadog_patch", False):
        return
    setattr(pymongo, "_datadog_patch", True)
    Pin(app=mongox.SERVICE).onto(pymongo.server.Server)

    # Whenever a pymongo command is invoked, the lib either:
    # - Creates a new socket & performs a TCP handshake
    # - Grabs a socket already initialized before
    _w("pymongo.server", "Server.get_socket", traced_get_socket)
Esempio n. 20
0
def patch():
    if getattr(consul, "__datadog_patch", False):
        return
    setattr(consul, "__datadog_patch", True)

    pin = Pin(service=consulx.SERVICE)
    pin.onto(consul.Consul.KV)

    for f_name in _KV_FUNCS:
        _w("consul", "Consul.KV.%s" % f_name, wrap_function(f_name))
Esempio n. 21
0
def patch():
    if getattr(consul, '__datadog_patch', False):
        return
    setattr(consul, '__datadog_patch', True)

    pin = Pin(service=consulx.SERVICE, app=consulx.APP)
    pin.onto(consul.Consul.KV)

    for f_name in _KV_FUNCS:
        _w('consul', 'Consul.KV.%s' % f_name, wrap_function(f_name))
Esempio n. 22
0
def patch():
    # type: () -> None
    if getattr(httpx, "_datadog_patch", False):
        return

    setattr(httpx, "_datadog_patch", True)

    _w(httpx.AsyncClient, "send", _wrapped_async_send)
    _w(httpx.Client, "send", _wrapped_sync_send)

    pin = Pin()
    pin.onto(httpx.AsyncClient)
    pin.onto(httpx.Client)
Esempio n. 23
0
def patch():
    """Patches current loop `create_task()` method to enable spawned tasks to
    parent to the base task context.
    """
    if getattr(asyncio, '_datadog_patch', False):
        return
    setattr(asyncio, '_datadog_patch', True)

    loop = asyncio.get_event_loop()
    if CONTEXTVARS_IS_AVAILABLE:
        _w(loop, 'create_task', wrapped_create_task_contextvars)
    else:
        _w(loop, 'create_task', wrapped_create_task)
Esempio n. 24
0
def patch():
    """Patch the instrumented methods"""
    if getattr(molten, "_datadog_patch", False):
        return
    setattr(molten, "_datadog_patch", True)

    pin = Pin(app=config.molten["app"])

    # add pin to module since many classes use __slots__
    pin.onto(molten)

    _w(molten.BaseApp, "__init__", patch_app_init)
    _w(molten.App, "__call__", patch_app_call)
Esempio n. 25
0
def patch():
    """Patch the instrumented methods
    """
    if getattr(molten, '_datadog_patch', False):
        return
    setattr(molten, '_datadog_patch', True)

    pin = Pin(service=config.molten['service_name'], app=config.molten['app'])

    # add pin to module since many classes use __slots__
    pin.onto(molten)

    _w(molten.BaseApp, '__init__', patch_app_init)
    _w(molten.App, '__call__', patch_app_call)
Esempio n. 26
0
def patch():
    """Activate http calls tracing"""
    if getattr(requests, "__datadog_patch", False):
        return
    setattr(requests, "__datadog_patch", True)

    _w("requests", "Session.send", _wrap_send)
    Pin(app="requests", _config=config.requests).onto(requests.Session)

    # [Backward compatibility]: `session.distributed_tracing` should point and
    # update the `Pin` configuration instead. This block adds a property so that
    # old implementations work as expected
    fn = property(_distributed_tracing)
    fn = fn.setter(_distributed_tracing_setter)
    requests.Session.distributed_tracing = fn
Esempio n. 27
0
def patch():
    """Patches current loop `create_task()` method to enable spawned tasks to
    parent to the base task context.
    """
    if getattr(asyncio, "_datadog_patch", False):
        return
    setattr(asyncio, "_datadog_patch", True)

    if sys.version_info < (3, 7, 0):
        _w(asyncio.BaseEventLoop, "create_task", wrapped_create_task)

        # also patch event loop if not inheriting the wrapped create_task from BaseEventLoop
        loop = asyncio.get_event_loop()
        if not isinstance(loop.create_task, ObjectProxy):
            _w(loop, "create_task", wrapped_create_task)
Esempio n. 28
0
def patch():
    """Patches current loop `create_task()` method to enable spawned tasks to
    parent to the base task context.
    """
    if getattr(asyncio, "_datadog_patch", False):
        return
    setattr(asyncio, "_datadog_patch", True)

    wrapper = wrapped_create_task_contextvars if CONTEXTVARS_IS_AVAILABLE else wrapped_create_task

    _w(asyncio.BaseEventLoop, "create_task", wrapper)

    # also patch event loop if not inheriting the wrapped create_task from BaseEventLoop
    loop = asyncio.get_event_loop()
    if not isinstance(loop.create_task, ObjectProxy):
        _w(loop, "create_task", wrapper)
Esempio n. 29
0
def trace_rendering():
    """Patch all Pylons renderers. It supports multiple versions
    of Pylons and multiple renderers.
    """
    # patch only once
    if getattr(pylons.templating, "__datadog_patch", False):
        return
    setattr(pylons.templating, "__datadog_patch", True)

    if legacy_pylons:
        # Pylons <= 0.9.7
        _w("pylons.templating", "render", _traced_renderer)
    else:
        # Pylons > 0.9.7
        _w("pylons.templating", "render_mako", _traced_renderer)
        _w("pylons.templating", "render_mako_def", _traced_renderer)
        _w("pylons.templating", "render_genshi", _traced_renderer)
        _w("pylons.templating", "render_jinja2", _traced_renderer)
Esempio n. 30
0
def trace_rendering():
    """Patch all Pylons renderers. It supports multiple versions
    of Pylons and multiple renderers.
    """
    # patch only once
    if getattr(pylons.templating, '__datadog_patch', False):
        return
    setattr(pylons.templating, '__datadog_patch', True)

    if legacy_pylons:
        # Pylons <= 0.9.7
        _w('pylons.templating', 'render', _traced_renderer)
    else:
        # Pylons > 0.9.7
        _w('pylons.templating', 'render_mako', _traced_renderer)
        _w('pylons.templating', 'render_mako_def', _traced_renderer)
        _w('pylons.templating', 'render_genshi', _traced_renderer)
        _w('pylons.templating', 'render_jinja2', _traced_renderer)