Esempio n. 1
0
from ddtrace import Pin
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.contrib.botocore.patch import patch
from ddtrace.contrib.botocore.patch import unpatch
from ddtrace.internal.compat import stringify
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
from ddtrace.propagation.http import HTTP_HEADER_TRACE_ID
from ddtrace.utils.version import parse_version
from tests.opentracer.utils import init_tracer
from tests.utils import TracerTestCase
from tests.utils import assert_is_measured
from tests.utils import assert_span_http_status_code

# Parse botocore.__version_ from "1.9.0" to (1, 9, 0)
BOTOCORE_VERSION = parse_version(botocore.__version__)


def get_zip_lambda():
    code = """
def lambda_handler(event, context):
    return event
"""
    zip_output = io.BytesIO()
    zip_file = zipfile.ZipFile(zip_output, "w", zipfile.ZIP_DEFLATED)
    zip_file.writestr("lambda_function.py", code)
    zip_file.close()
    zip_output.seek(0)
    return zip_output.read()

Esempio n. 2
0
import aiohttp
import aiohttp_jinja2
import pytest

from ddtrace.contrib.aiohttp.middlewares import trace_app
from ddtrace.contrib.aiohttp.patch import patch
from ddtrace.pin import Pin
from ddtrace.utils import version

from .app.web import setup_app

if version.parse_version(aiohttp.__version__) < (3, 0, 0):

    @pytest.fixture
    def aiohttp_client(test_client):
        return test_client

    @pytest.fixture
    def app_tracer(tracer, loop):
        app = setup_app()
        trace_app(app, tracer)
        return app, tracer

    @pytest.fixture
    def patched_app_tracer(app_tracer):
        patch()
        app, tracer = app_tracer
        Pin.override(aiohttp_jinja2, tracer=tracer)
        return app, tracer
        # When Python 3.5 is dropped, rather do:
        # yield app, tracer
Esempio n. 3
0
def test_parse_version(version_str, expected):
    # type: (str, typing.Tuple[int, int, int]) -> None
    """Ensure parse_version helper properly parses versions"""
    assert parse_version(version_str) == expected
Esempio n. 4
0
import asyncio

from aiopg import __version__
from aiopg.utils import _ContextManager

from ddtrace import config
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.constants import SPAN_MEASURED_KEY
from ddtrace.contrib import dbapi
from ddtrace.ext import SpanTypes
from ddtrace.ext import sql
from ddtrace.pin import Pin
from ddtrace.utils.version import parse_version
from ddtrace.vendor import wrapt

AIOPG_VERSION = parse_version(__version__)


class AIOTracedCursor(wrapt.ObjectProxy):
    """TracedCursor wraps a psql cursor and traces its queries."""
    def __init__(self, cursor, pin):
        super(AIOTracedCursor, self).__init__(cursor)
        pin.onto(self)
        name = pin.app or "sql"
        self._datadog_name = "%s.query" % name

    @asyncio.coroutine
    def _trace_method(self, method, resource, extra_tags, *args, **kwargs):
        pin = Pin.get_from(self)
        if not pin or not pin.enabled():
            result = yield from method(*args, **kwargs)