Beispiel #1
0
 def setUp(self):
     # use a dummy tracer
     self.tracer = get_dummy_tracer()
     self._original_tracer = ddtrace.tracer
     ddtrace.tracer = self.tracer
     # trace gevent
     patch()
 def make_client(self, mock_socket_values, **kwargs):
     tracer = get_dummy_tracer()
     Pin.override(pymemcache, tracer=tracer)
     self.client = pymemcache.client.base.Client((TEST_HOST, TEST_PORT),
                                                 **kwargs)
     self.client.sock = MockSocket(list(mock_socket_values))
     return self.client
Beispiel #3
0
    def get_tracer_and_connect(self):
        tracer = get_dummy_tracer()
        Pin.get_from(mongoengine.connect).clone(tracer=tracer).onto(
            mongoengine.connect)
        mongoengine.connect(port=MONGO_CONFIG["port"])

        return tracer
Beispiel #4
0
 def setUp(self):
     super(TestCassandraConfig, self).setUp()
     patch()
     self.tracer = get_dummy_tracer()
     self.cluster = Cluster(port=CASSANDRA_CONFIG["port"])
     Pin.get_from(self.cluster).clone(tracer=self.tracer).onto(self.cluster)
     self.session = self.cluster.connect(self.TEST_KEYSPACE)
Beispiel #5
0
    def test_patch_unpatch(self):
        tracer = get_dummy_tracer()
        writer = tracer.writer

        # Test patch idempotence
        patch()
        patch()

        r = self._get_test_client()
        Pin.get_from(r).clone(tracer=tracer).onto(r)
        r.get('key')

        spans = writer.pop()
        assert spans, spans
        assert len(spans) == 1

        # Test unpatch
        unpatch()

        r = self._get_test_client()
        r.get('key')

        spans = writer.pop()
        assert not spans, spans

        # Test patch again
        patch()

        r = self._get_test_client()
        Pin.get_from(r).clone(tracer=tracer).onto(r)
        r.get('key')

        spans = writer.pop()
        assert spans, spans
        assert len(spans) == 1
Beispiel #6
0
def test_pre_v4():
    tracer = get_dummy_tracer()
    MySQL = get_traced_mysql_connection(tracer, service="my-mysql-server")
    conn = MySQL(**config.MYSQL_CONFIG)
    cursor = conn.cursor()
    cursor.execute("SELECT 1")
    assert cursor.fetchone()[0] == 1
    def test_configuration_routine(self):
        """Ensure that the integration routines can be configured."""
        routine_config = dict(patch={
            'vertica_python.vertica.connection.Connection':
            dict(routines=dict(cursor=dict(
                operation_name='get_cursor',
                trace_enabled=True,
            ), ), ),
        }, )

        # Make a copy of the vertica config first before we merge our settings over
        # DEV: First argument gets merged into the second
        copy = _deepmerge(config.vertica, dict())
        overrides = _deepmerge(routine_config, copy)
        with self.override_config('vertica', overrides):
            patch()
            import vertica_python

            test_tracer = get_dummy_tracer()

            conn = vertica_python.connect(**VERTICA_CONFIG)
            Pin.override(conn, service='mycustomservice', tracer=test_tracer)
            conn.cursor()  # should be traced now
            conn.close()
        spans = test_tracer.writer.pop()
        assert len(spans) == 1
        assert spans[0].name == 'get_cursor'
        assert spans[0].service == 'mycustomservice'
Beispiel #8
0
 def setUp(self):
     patch()
     # prevent cache effects when using Template('code...')
     jinja2.environment._spontaneous_environments.clear()
     # provide a dummy tracer
     self.tracer = get_dummy_tracer()
     Pin.override(jinja2.environment.Environment, tracer=self.tracer)
Beispiel #9
0
def nop_tracer():
    from ddtrace.opentracer import Tracer

    tracer = Tracer(service_name="mysvc", config={})
    # use the same test tracer used by the primary tests
    tracer._tracer = get_dummy_tracer()
    return tracer
Beispiel #10
0
 def get_tracer_and_client(self):
     tracer = get_dummy_tracer()
     client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
     Pin(service=self.TEST_SERVICE, tracer=tracer).onto(client)
     # We do not wish to trace tcp spans here
     Pin.get_from(pymongo.server.Server).remove_from(pymongo.server.Server)
     return tracer, client
Beispiel #11
0
 def get_tracer_and_client(self):
     tracer = get_dummy_tracer()
     original_client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
     client = trace_mongo_client(original_client,
                                 tracer,
                                 service=self.TEST_SERVICE)
     return tracer, client
Beispiel #12
0
    def test_patch_unpatch(self):
        tracer = get_dummy_tracer()
        writer = tracer.writer

        # Test patch idempotence
        patch()
        patch()

        client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
        Pin.get_from(client).clone(tracer=tracer).onto(client)
        client['testdb'].drop_collection('whatever')

        spans = writer.pop()
        assert spans, spans
        assert len(spans) == 1

        # Test unpatch
        unpatch()

        client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
        client['testdb'].drop_collection('whatever')

        spans = writer.pop()
        assert not spans, spans

        # Test patch again
        patch()

        client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
        Pin.get_from(client).clone(tracer=tracer).onto(client)
        client['testdb'].drop_collection('whatever')

        spans = writer.pop()
        assert spans, spans
        assert len(spans) == 1
Beispiel #13
0
    def test_patch_unpatch(self):
        tracer = get_dummy_tracer()
        writer = tracer.writer

        # Test patch idempotence
        patch()
        patch()

        r = redis.Redis(port=REDIS_CONFIG["port"])
        Pin.get_from(r).clone(tracer=tracer).onto(r)
        r.get("key")

        spans = writer.pop()
        assert spans, spans
        assert len(spans) == 1

        # Test unpatch
        unpatch()

        r = redis.Redis(port=REDIS_CONFIG["port"])
        r.get("key")

        spans = writer.pop()
        assert not spans, spans

        # Test patch again
        patch()

        r = redis.Redis(port=REDIS_CONFIG["port"])
        Pin.get_from(r).clone(tracer=tracer).onto(r)
        r.get("key")

        spans = writer.pop()
        assert spans, spans
        assert len(spans) == 1
 def setUp(self):
     # provide a dummy tracer
     self.tracer = get_dummy_tracer()
     self._original_tracer = ddtrace.tracer
     ddtrace.tracer = self.tracer
     # provide a Bottle app
     self.app = bottle.Bottle()
Beispiel #15
0
    def _traced_session(self):
        tracer = get_dummy_tracer()
        # pin the global Cluster to test if they will conflict
        Pin(service=self.TEST_SERVICE, tracer=tracer).onto(Cluster)
        self.cluster = Cluster(port=CASSANDRA_CONFIG['port'])

        return self.cluster.connect(self.TEST_KEYSPACE), tracer
 def setUp(self):
     super(DistributedTracingTestCase, self).setUp()
     self._service = "falcon"
     self.tracer = get_dummy_tracer()
     self.api = get_app(tracer=self.tracer)
     self.version = falcon.__version__
     if self.version[0] != "1":
         self.client = testing.TestClient(self.api)
Beispiel #17
0
def tracer():
    tracer = get_dummy_tracer()
    if sys.version_info < (3, 7):
        # enable legacy asyncio support
        from ddtrace.contrib.asyncio.provider import AsyncioContextProvider

        tracer.configure(context_provider=AsyncioContextProvider())
    yield tracer
 def setUp(self):
     self.tracer = get_dummy_tracer()
     self.traced_app = TraceMiddleware(
         cherrypy,
         self.tracer,
         service="test.cherrypy.service",
         distributed_tracing=True,
     )
Beispiel #19
0
    def get_tracer_and_connect(self):
        tracer = get_dummy_tracer()
        # Set a connect-level service, to check that we properly override it
        Pin(service="not-%s" % self.TEST_SERVICE).onto(mongoengine.connect)
        client = mongoengine.connect(port=MONGO_CONFIG["port"])
        Pin(service=self.TEST_SERVICE, tracer=tracer).onto(client)

        return tracer
Beispiel #20
0
def test_redis_legacy():
    # ensure the old interface isn't broken, but doesn't trace
    tracer = get_dummy_tracer()
    TracedRedisCache = get_traced_redis(tracer, "foo")
    r = TracedRedisCache(port=REDIS_CONFIG["port"])
    r.set("a", "b")
    got = r.get("a")
    assert compat.to_unicode(got) == "b"
    assert not tracer.writer.pop()
Beispiel #21
0
 def get_tracer_and_client(self):
     tracer = get_dummy_tracer()
     original_client = pymongo.MongoClient(port=MONGO_CONFIG['port'])
     client = trace_mongo_client(original_client,
                                 tracer,
                                 service=self.TEST_SERVICE)
     # No need to disable tcp spans tracer here as trace_mongo_client does not call
     # patch()
     return tracer, client
Beispiel #22
0
    def setUp(self, get_container_info):
        """
        Create a tracer without workers, while spying the ``send()`` method
        """
        # Mock the container id we use for making requests
        get_container_info.return_value = CGroupInfo(
            container_id="test-container-id")

        # create a new API object to test the transport using synchronous calls
        self.tracer = get_dummy_tracer()
        self.api_json = API("localhost", 8126, encoder=JSONEncoder())
        self.api_msgpack = API("localhost", 8126, encoder=MsgpackEncoder())
Beispiel #23
0
 def setUp(self):
     patch()
     self.tracer = get_dummy_tracer()
     # Override server pin's tracer with our dummy tracer
     Pin.override(pymongo.server.Server, tracer=self.tracer)
     # maxPoolSize controls the number of sockets that the client can instanciate
     # and choose from to perform classic operations. For the sake of our tests,
     # let's limit this number to 1
     self.client = pymongo.MongoClient(port=MONGO_CONFIG['port'],
                                       maxPoolSize=1)
     # Override TracedMongoClient's pin's tracer with our dummy tracer
     Pin.override(self.client, tracer=self.tracer)
Beispiel #24
0
    def make_ot_tracer(service_name="my_svc", config=None, scope_manager=None, context_provider=None):
        config = config or {}
        tracer = Tracer(service_name=service_name, config=config, scope_manager=scope_manager)

        # similar to how we test the ddtracer, use a dummy tracer
        dd_tracer = get_dummy_tracer()
        if context_provider:
            dd_tracer.configure(context_provider=context_provider)

        # attach the dummy tracer to the opentracer
        tracer._dd_tracer = dd_tracer
        return tracer
Beispiel #25
0
def test_less_than_v04():
    # interface from < v0.4
    from ddtrace.contrib.mongoengine import trace_mongoengine
    tracer = get_dummy_tracer()

    connect = trace_mongoengine(tracer, service='my-mongo-db', patch=False)
    connect(port=config.MONGO_CONFIG['port'])

    lc = Singer()
    lc.first_name = 'leonard'
    lc.last_name = 'cohen'
    lc.save()
Beispiel #26
0
def tracer():
    original_tracer = ddtrace.tracer
    tracer = get_dummy_tracer()
    if sys.version_info < (3, 7):
        # enable legacy asyncio support
        from ddtrace.contrib.asyncio.provider import AsyncioContextProvider

        tracer.configure(context_provider=AsyncioContextProvider())
    setattr(ddtrace, "tracer", tracer)
    patch()
    yield tracer
    setattr(ddtrace, "tracer", original_tracer)
    unpatch()
    def setUp(self):
        self.tracer = get_dummy_tracer()
        self.app = create_app()
        self.traced_app = TraceMiddleware(
            self.app,
            self.tracer,
            service="test.flask.service",
            distributed_tracing=True,
        )

        # make the app testable
        self.app.config["TESTING"] = True
        self.client = self.app.test_client()
Beispiel #28
0
    def test_connect_factory(self):
        tracer = get_dummy_tracer()

        services = ['db', 'another']
        for service in services:
            conn, _ = yield from self._get_conn_and_tracer()
            Pin.get_from(conn).clone(service=service, tracer=tracer).onto(conn)
            yield from self.assert_conn_is_traced(tracer, conn, service)
            conn.close()

        # ensure we have the service types
        service_meta = tracer.writer.pop_services()
        expected = {}
        assert service_meta == expected
Beispiel #29
0
 def setUp(self):
     """
     Create a tracer without workers, while spying the ``send()`` method
     """
     # create a new API object to test the transport using synchronous calls
     self.tracer = get_dummy_tracer()
     self.api_json = API("localhost",
                         8126,
                         encoder=JSONEncoder(),
                         priority_sampling=True)
     self.api_msgpack = API("localhost",
                            8126,
                            encoder=MsgpackEncoder(),
                            priority_sampling=True)
Beispiel #30
0
    def test_inject(self):
        tracer = get_dummy_tracer()

        ctx = Context(trace_id=1234, sampling_priority=2, dd_origin="synthetics")
        tracer.context_provider.activate(ctx)
        with tracer.trace("global_root_span") as span:
            headers = {}
            propagator = HTTPPropagator()
            propagator.inject(span.context, headers)

            assert int(headers[HTTP_HEADER_TRACE_ID]) == span.trace_id
            assert int(headers[HTTP_HEADER_PARENT_ID]) == span.span_id
            assert int(headers[HTTP_HEADER_SAMPLING_PRIORITY]) == span.context.sampling_priority
            assert headers[HTTP_HEADER_ORIGIN] == span.context.dd_origin