Beispiel #1
0
    def setUp(self):
        self._tracer = tracer
        self._writer = DummyWriter()
        self._tracer.writer = self._writer
        self._service = "my-falcon"

        self.api = falcon.API()

        resources = [
            Resource200,
            Resource500,
            ResourceExc,
        ]
        for r in resources:
            self.api.add_route(r.ROUTE, r())
Beispiel #2
0
def _get_test_app(service=None):
    """ return a webtest'able version of our test app. """
    from tests.test_tracer import DummyWriter
    ddtrace.tracer.writer = DummyWriter()

    app = _get_app(service=service, tracer=ddtrace.tracer)
    return webtest.TestApp(app), ddtrace.tracer
Beispiel #3
0
    def setUp(self):
        self._service = 'my-falcon'
        self.tracer = tracer
        self.tracer.writer = DummyWriter()

        # build a test app without adding a tracer middleware;
        # reconfigure the global tracer since the autopatch mode
        # uses it
        self.api = get_app(tracer=None)
"""

import redis

from ddtrace import Pin
from tests.contrib.config import REDIS_CONFIG
from tests.test_tracer import DummyWriter

if __name__ == '__main__':
    r = redis.Redis(port=REDIS_CONFIG['port'])
    pin = Pin.get_from(r)
    assert pin
    assert pin.app == 'redis'
    assert pin.service == 'redis'

    pin.tracer.writer = DummyWriter()
    r.flushall()
    spans = pin.tracer.writer.pop()

    assert len(spans) == 1
    assert spans[0].service == 'redis'
    assert spans[0].resource == 'FLUSHALL'

    long_cmd = 'mget %s' % ' '.join(map(str, range(1000)))
    us = r.execute_command(long_cmd)

    spans = pin.tracer.writer.pop()
    assert len(spans) == 1
    span = spans[0]
    assert span.service == 'redis'
    assert span.name == 'redis.command'
Beispiel #5
0
class TestMiddleware(falcon.testing.TestCase):
    def setUp(self):
        self._tracer = tracer
        self._writer = DummyWriter()
        self._tracer.writer = self._writer
        self._service = "my-falcon"

        self.api = falcon.API()

        resources = [
            Resource200,
            Resource500,
            ResourceExc,
        ]
        for r in resources:
            self.api.add_route(r.ROUTE, r())

    def test_autopatched(self):
        ok_(falcon._datadog_patch)

    @attr('404')
    def test_404(self):
        out = self.simulate_get('/404')
        eq_(out.status_code, 404)

        spans = self._writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self._service)
        eq_(span.resource, "GET 404")
        eq_(span.get_tag(httpx.STATUS_CODE), '404')
        eq_(span.name, "falcon.request")

    def test_exception(self):
        try:
            self.simulate_get(ResourceExc.ROUTE)
        except Exception:
            pass
        else:
            assert 0

        spans = self._writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self._service)
        eq_(span.resource,
            "GET tests.contrib.falcon.test_autopatch.ResourceExc")
        eq_(span.get_tag(httpx.STATUS_CODE), '500')
        eq_(span.name, "falcon.request")

    def test_200(self):
        out = self.simulate_get(Resource200.ROUTE)
        eq_(out.status_code, 200)
        eq_(out.content.decode('utf-8'), Resource200.BODY)

        spans = self._writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self._service)
        eq_(span.resource,
            "GET tests.contrib.falcon.test_autopatch.Resource200")
        eq_(span.get_tag(httpx.STATUS_CODE), '200')
        eq_(span.name, "falcon.request")

    def test_500(self):
        out = self.simulate_get(Resource500.ROUTE)
        eq_(out.status_code, 500)
        eq_(out.content.decode('utf-8'), Resource500.BODY)

        spans = self._writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self._service)
        eq_(span.resource,
            "GET tests.contrib.falcon.test_autopatch.Resource500")
        eq_(span.get_tag(httpx.STATUS_CODE), '500')
        eq_(span.name, "falcon.request")