Exemplo n.º 1
0
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.ext import SpanTypes
from ddtrace.ext import http
from ddtrace.propagation.http import HTTPPropagator
from ddtrace.settings import config

from .. import trace_utils
from ...compat import reraise
from ...internal.logger import get_logger
from .utils import guarantee_single_callable

log = get_logger(__name__)

config._add(
    "asgi",
    dict(service_name=config._get_service(default="asgi"),
         request_span_name="asgi.request",
         distributed_tracing=True),
)

ASGI_VERSION = "asgi.version"
ASGI_SPEC_VERSION = "asgi.spec_version"


def bytes_to_str(str_or_bytes):
    return str_or_bytes.decode() if isinstance(str_or_bytes,
                                               bytes) else str_or_bytes


def _extract_versions_from_scope(scope, integration_config):
    tags = {}
Exemplo n.º 2
0
from ddtrace.utils.wrappers import unwrap as _u
from ddtrace.vendor.wrapt import wrap_function_wrapper as _w

DD_PATCH_ATTR = '_datadog_patch'

SERVICE_NAME = 'algoliasearch'
APP_NAME = 'algoliasearch'

try:
    import algoliasearch
    from algoliasearch.version import VERSION
    algoliasearch_version = tuple([int(i) for i in VERSION.split('.')])

    # Default configuration
    config._add('algoliasearch', dict(
        service_name=config.service or SERVICE_NAME,
        collect_query_text=False
    ))
except ImportError:
    algoliasearch_version = (0, 0)


def patch():
    if algoliasearch_version == (0, 0):
        return

    if getattr(algoliasearch, DD_PATCH_ATTR, False):
        return

    setattr(algoliasearch, '_datadog_patch', True)

    pin = Pin(
Exemplo n.º 3
0
from .. import trace_utils

DD_PATCH_ATTR = "_datadog_patch"

SERVICE_NAME = "algoliasearch"
APP_NAME = "algoliasearch"

try:
    import algoliasearch
    from algoliasearch.version import VERSION

    algoliasearch_version = tuple([int(i) for i in VERSION.split(".")])

    # Default configuration
    config._add("algoliasearch",
                dict(_default_service=SERVICE_NAME, collect_query_text=False))
except ImportError:
    algoliasearch_version = (0, 0)


def patch():
    if algoliasearch_version == (0, 0):
        return

    if getattr(algoliasearch, DD_PATCH_ATTR, False):
        return

    setattr(algoliasearch, "_datadog_patch", True)

    pin = Pin(app=APP_NAME)
Exemplo n.º 4
0
from ddtrace import tracer as global_tracer
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.ext import SpanTypes, http
from ddtrace.http import store_request_headers, store_response_headers
from ddtrace.propagation.http import HTTPPropagator
from ddtrace.settings import config

from ...compat import reraise
from ...internal.logger import get_logger
from .utils import guarantee_single_callable

log = get_logger(__name__)

config._add(
    "asgi",
    dict(service_name=config._get_service(default="asgi"),
         distributed_tracing=True))

ASGI_VERSION = "asgi.version"
ASGI_SPEC_VERSION = "asgi.spec_version"


def bytes_to_str(str_or_bytes):
    return str_or_bytes.decode() if isinstance(str_or_bytes,
                                               bytes) else str_or_bytes


def _extract_tags_from_scope(scope):
    tags = {}

    http_method = scope.get("method")
Exemplo n.º 5
0
Generic dbapi tracing code.
"""

import logging

import wrapt

from ddtrace import Pin
from ddtrace.ext import AppTypes, sql
from ddtrace.settings import config
from ddtrace.utils.formats import asbool, get_env

log = logging.getLogger(__name__)

config._add(
    'dbapi2',
    dict(trace_fetch_methods=asbool(
        get_env('dbapi2', 'trace_fetch_methods', 'false')), ))


class TracedCursor(wrapt.ObjectProxy):
    """ TracedCursor wraps a psql cursor and traces it's queries. """
    def __init__(self, cursor, pin):
        super(TracedCursor, self).__init__(cursor)
        pin.onto(self)
        name = pin.app or 'sql'
        self._self_datadog_name = '{}.query'.format(name)
        self._self_last_execute_operation = None

    def _trace_method(self, method, name, resource, extra_tags, *args,
                      **kwargs):
        """
Exemplo n.º 6
0
from ddtrace.utils.wrappers import unwrap as _u
from ddtrace.vendor.wrapt import wrap_function_wrapper as _w

DD_PATCH_ATTR = '_datadog_patch'

SERVICE_NAME = 'algoliasearch'
APP_NAME = 'algoliasearch'

try:
    import algoliasearch
    from algoliasearch.version import VERSION
    algoliasearch_version = tuple([int(i) for i in VERSION.split('.')])

    # Default configuration
    config._add(
        'algoliasearch',
        dict(service_name=config.get_service(default=SERVICE_NAME),
             collect_query_text=False))
except ImportError:
    algoliasearch_version = (0, 0)


def patch():
    if algoliasearch_version == (0, 0):
        return

    if getattr(algoliasearch, DD_PATCH_ATTR, False):
        return

    setattr(algoliasearch, '_datadog_patch', True)

    pin = Pin(service=config.algoliasearch.service_name, app=APP_NAME)