コード例 #1
0
    def test_redis_cache_tracing_with_a_wrong_connection(self):
        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            "CACHE_TYPE": "redis",
            "CACHE_REDIS_PORT": 2230,
            "CACHE_REDIS_HOST": "127.0.0.1"
        }
        cache = Cache(app, config=config)

        # use a wrong redis connection
        with pytest.raises(ConnectionError) as ex:
            cache.get(u"á_complex_operation")

        # ensure that the error is not caused by our tracer
        assert "127.0.0.1:2230. Connection refused." in ex.value.args[0]
        spans = self.pop_spans()
        # an error trace must be sent
        assert len(spans) == 1
        span = spans[0]
        assert span.service == self.SERVICE
        assert span.resource == "get"
        assert span.name == "flask_cache.cmd"
        assert span.span_type == "cache"
        assert span.meta[CACHE_BACKEND] == "redis"
        assert span.meta[net.TARGET_HOST] == "127.0.0.1"
        assert span.metrics[net.TARGET_PORT] == 2230
        assert span.error == 1
コード例 #2
0
ファイル: test.py プロジェクト: roverdotcom/dd-trace-py
    def test_simple_cache_add(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        cache.add(u"á_complex_number", 50)
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "add")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 0)

        expected_meta = {
            "flask_cache.key": u"á_complex_number",
            "flask_cache.backend": "simple",
        }

        eq_(span.meta, expected_meta)
コード例 #3
0
    def test_cache_add_without_arguments(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={'CACHE_TYPE': 'simple'})

        # make a wrong call
        with pytest.raises(TypeError) as ex:
            cache.add()

        # ensure that the error is not caused by our tracer
        assert 'add()' in ex.value.args[0]
        assert 'argument' in ex.value.args[0]
        spans = writer.pop()
        # an error trace must be sent
        assert len(spans) == 1
        span = spans[0]
        assert span.service == self.SERVICE
        assert span.resource == 'add'
        assert span.name == 'flask_cache.cmd'
        assert span.span_type == 'cache'
        assert span.error == 1
コード例 #4
0
    def test_memcached_cache_tracing_with_a_wrong_connection(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            'CACHE_TYPE': 'memcached',
            'CACHE_MEMCACHED_SERVERS': ['localhost:2230'],
        }
        cache = Cache(app, config=config)

        # use a wrong memcached connection
        try:
            cache.get(u'á_complex_operation')
        except Exception:
            pass

        # ensure that the error is not caused by our tracer
        spans = writer.pop()
        assert len(spans) == 1
        span = spans[0]
        assert span.service == self.SERVICE
        assert span.resource == 'get'
        assert span.name == 'flask_cache.cmd'
        assert span.span_type == 'cache'
        assert span.meta[CACHE_BACKEND] == 'memcached'
        assert span.meta[net.TARGET_HOST] == 'localhost'
        assert span.metrics[net.TARGET_PORT] == 2230
コード例 #5
0
ファイル: test.py プロジェクト: roverdotcom/dd-trace-py
    def test_simple_cache_delete_many(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        cache.delete_many("complex_operation", "another_complex_op")
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "delete_many")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 0)

        expected_meta = {
            "flask_cache.key": "['complex_operation', 'another_complex_op']",
            "flask_cache.backend": "simple",
        }

        eq_(span.meta, expected_meta)
コード例 #6
0
ファイル: test.py プロジェクト: tebriel/dd-trace-py
    def test_simple_cache_add(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        cache.add(u"á_complex_number", 50)
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "add")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 0)

        expected_meta = {
            "flask_cache.key": u"á_complex_number",
            "flask_cache.backend": "simple",
        }

        assert_dict_issuperset(span.meta, expected_meta)
コード例 #7
0
ファイル: test.py プロジェクト: roverdotcom/dd-trace-py
    def test_simple_cache_set_many(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        cache.set_many({
            'first_complex_op': 10,
            'second_complex_op': 20,
        })
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "set_many")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 0)

        expected_meta = {
            "flask_cache.key": "['first_complex_op', 'second_complex_op']",
            "flask_cache.backend": "simple",
        }

        eq_(span.meta["flask_cache.backend"], "simple")
        ok_("first_complex_op" in span.meta["flask_cache.key"])
        ok_("second_complex_op" in span.meta["flask_cache.key"])
コード例 #8
0
    def test_redis_cache_tracing_with_a_wrong_connection(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            'CACHE_TYPE': 'redis',
            'CACHE_REDIS_PORT': 2230,
            'CACHE_REDIS_HOST': '127.0.0.1'
        }
        cache = Cache(app, config=config)

        # use a wrong redis connection
        with pytest.raises(ConnectionError) as ex:
            cache.get(u'á_complex_operation')

        # ensure that the error is not caused by our tracer
        assert '127.0.0.1:2230. Connection refused.' in ex.value.args[0]
        spans = writer.pop()
        # an error trace must be sent
        assert len(spans) == 1
        span = spans[0]
        assert span.service == self.SERVICE
        assert span.resource == 'get'
        assert span.name == 'flask_cache.cmd'
        assert span.span_type == 'cache'
        assert span.meta[CACHE_BACKEND] == 'redis'
        assert span.meta[net.TARGET_HOST] == '127.0.0.1'
        assert span.metrics[net.TARGET_PORT] == 2230
        assert span.error == 1
コード例 #9
0
    def test_memcached_cache_tracing_with_a_wrong_connection(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            "CACHE_TYPE": "memcached",
            "CACHE_MEMCACHED_SERVERS": ['localhost:2230'],
        }
        cache = Cache(app, config=config)

        # use a wrong memcached connection
        try:
            cache.get(u"á_complex_operation")
        except Exception:
            pass


        # ensure that the error is not caused by our tracer
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "get")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.meta[CACHE_BACKEND], "memcached")
        eq_(span.meta[net.TARGET_HOST], 'localhost')
        eq_(span.meta[net.TARGET_PORT], '2230')
コード例 #10
0
ファイル: test.py プロジェクト: tancnle/dd-trace-py
    def test_simple_cache_get_ot(self):
        """OpenTracing version of test_simple_cache_get."""
        ot_tracer = init_tracer("my_svc", self.tracer)

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        with ot_tracer.start_active_span("ot_span"):
            cache.get(u"á_complex_operation")

        spans = self.get_spans()
        self.assertEqual(len(spans), 2)
        ot_span, dd_span = spans

        # confirm the parenting
        self.assertIsNone(ot_span.parent_id)
        self.assertEqual(dd_span.parent_id, ot_span.span_id)

        self.assertEqual(ot_span.resource, "ot_span")
        self.assertEqual(ot_span.service, "my_svc")

        self.assertEqual(dd_span.service, self.SERVICE)
        self.assertEqual(dd_span.resource, "get")
        self.assertEqual(dd_span.name, "flask_cache.cmd")
        self.assertEqual(dd_span.span_type, "cache")
        self.assertEqual(dd_span.error, 0)

        expected_meta = {
            "flask_cache.key": u"á_complex_operation",
            "flask_cache.backend": "simple",
        }

        assert_dict_issuperset(dd_span.meta, expected_meta)
コード例 #11
0
    def test_memcached_cache_tracing_with_a_wrong_connection(self):
        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            "CACHE_TYPE": "memcached",
            "CACHE_MEMCACHED_SERVERS": ["localhost:2230"],
        }
        cache = Cache(app, config=config)

        # use a wrong memcached connection
        try:
            cache.get(u"á_complex_operation")
        except Exception:
            pass

        # ensure that the error is not caused by our tracer
        spans = self.pop_spans()
        assert len(spans) == 1
        span = spans[0]
        assert span.service == self.SERVICE
        assert span.resource == "get"
        assert span.name == "flask_cache.cmd"
        assert span.span_type == "cache"
        assert span.meta[CACHE_BACKEND] == "memcached"
        assert span.meta[net.TARGET_HOST] == "localhost"
        assert span.metrics[net.TARGET_PORT] == 2230
コード例 #12
0
ファイル: test.py プロジェクト: tnawanna/dd-trace-py
    def test_simple_cache_get_ot(self):
        """OpenTracing version of test_simple_cache_get."""
        ot_tracer = init_tracer('my_svc', self.tracer)

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={'CACHE_TYPE': 'simple'})

        with ot_tracer.start_active_span('ot_span'):
            cache.get(u'á_complex_operation')

        spans = self.get_spans()
        self.assertEqual(len(spans), 2)
        ot_span, dd_span = spans

        # confirm the parenting
        self.assertIsNone(ot_span.parent_id)
        self.assertEqual(dd_span.parent_id, ot_span.span_id)

        self.assertEqual(ot_span.resource, 'ot_span')
        self.assertEqual(ot_span.service, 'my_svc')

        self.assertEqual(dd_span.service, self.SERVICE)
        self.assertEqual(dd_span.resource, 'get')
        self.assertEqual(dd_span.name, 'flask_cache.cmd')
        self.assertEqual(dd_span.span_type, 'cache')
        self.assertEqual(dd_span.error, 0)

        expected_meta = {
            'flask_cache.key': u'á_complex_operation',
            'flask_cache.backend': 'simple',
        }

        assert_dict_issuperset(dd_span.meta, expected_meta)
コード例 #13
0
ファイル: test.py プロジェクト: tebriel/dd-trace-py
    def test_simple_cache_set_many(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        cache.set_many({
            'first_complex_op': 10,
            'second_complex_op': 20,
        })
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "set_many")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 0)

        eq_(span.meta["flask_cache.backend"], "simple")
        ok_("first_complex_op" in span.meta["flask_cache.key"])
        ok_("second_complex_op" in span.meta["flask_cache.key"])
コード例 #14
0
    def test_redis_cache_tracing_with_a_wrong_connection(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            "CACHE_TYPE": "redis",
            "CACHE_REDIS_PORT": 22230,
        }
        cache = Cache(app, config=config)

        # use a wrong redis connection
        with assert_raises(ConnectionError) as ex:
            cache.get(u"á_complex_operation")

        # ensure that the error is not caused by our tracer
        ok_("localhost:22230. Connection refused." in ex.exception.args[0])
        spans = writer.pop()
        # an error trace must be sent
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "get")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.meta[CACHE_BACKEND], "redis")
        eq_(span.meta[net.TARGET_HOST], 'localhost')
        eq_(span.meta[net.TARGET_PORT], '22230')
        eq_(span.error, 1)
コード例 #15
0
ファイル: test.py プロジェクト: tancnle/dd-trace-py
    def setUp(self):
        super(FlaskCacheTest, self).setUp()

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer, service=self.SERVICE)
        app = Flask(__name__)
        self.cache = Cache(app, config={"CACHE_TYPE": "simple"})
コード例 #16
0
ファイル: test.py プロジェクト: yuhonghong7035/dd-trace-py
    def test_simple_cache_set(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        cache.set(u"á_complex_operation", u"with_á_value\nin two lines")
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "set")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 0)

        expected_meta = {
            "flask_cache.key": u"á_complex_operation",
            "flask_cache.backend": "simple",
        }

        assert_dict_issuperset(span.meta, expected_meta)
コード例 #17
0
    def test_memcached_cache_tracing_with_a_wrong_connection(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            "CACHE_TYPE": "memcached",
            "CACHE_MEMCACHED_SERVERS": ['localhost:22230'],
        }
        cache = Cache(app, config=config)

        # use a wrong memcached connection
        try:
            cache.get(u"á_complex_operation")
        except Exception:
            pass

        # ensure that the error is not caused by our tracer
        spans = writer.pop()
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "get")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.meta[CACHE_BACKEND], "memcached")
        eq_(span.meta[net.TARGET_HOST], 'localhost')
        eq_(span.meta[net.TARGET_PORT], '22230')
コード例 #18
0
    def test_cache_add_without_arguments(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        # make a wrong call
        with assert_raises(TypeError) as ex:
            cache.add()

        # ensure that the error is not caused by our tracer
        ok_("add()" in ex.exception.args[0])
        ok_("argument" in ex.exception.args[0])
        spans = writer.pop()
        # an error trace must be sent
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "add")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 1)
コード例 #19
0
    def test_cache_add_without_arguments(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        # make a wrong call
        with assert_raises(TypeError) as ex:
            cache.add()

        # ensure that the error is not caused by our tracer
        ok_("add()" in ex.exception.args[0])
        ok_("argument" in ex.exception.args[0])
        spans = writer.pop()
        # an error trace must be sent
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "add")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.error, 1)
コード例 #20
0
    def setUp(self):
        super(TestFlaskCacheSettings, self).setUp()

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer)
        app = Flask(__name__)
        self.cache = Cache(app, config={"CACHE_TYPE": "simple"})
コード例 #21
0
    def test_redis_cache_tracing_with_a_wrong_connection(self):
        # initialize the dummy writer
        writer = DummyWriter()
        tracer = Tracer()
        tracer.writer = writer

        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(tracer, service=self.SERVICE)
        app = Flask(__name__)
        config = {
            "CACHE_TYPE": "redis",
            "CACHE_REDIS_PORT": 2230,
            "CACHE_REDIS_HOST": "127.0.0.1"
        }
        cache = Cache(app, config=config)

        # use a wrong redis connection
        with assert_raises(ConnectionError) as ex:
            cache.get(u"á_complex_operation")

        print(ex.exception)
        # ensure that the error is not caused by our tracer
        ok_("127.0.0.1:2230. Connection refused." in ex.exception.args[0])
        spans = writer.pop()
        # an error trace must be sent
        eq_(len(spans), 1)
        span = spans[0]
        eq_(span.service, self.SERVICE)
        eq_(span.resource, "get")
        eq_(span.name, "flask_cache.cmd")
        eq_(span.span_type, "cache")
        eq_(span.meta[CACHE_BACKEND], "redis")
        eq_(span.meta[net.TARGET_HOST], '127.0.0.1')
        eq_(span.meta[net.TARGET_PORT], '2230')
        eq_(span.error, 1)
コード例 #22
0
 def test_resource_from_cache_without_prefix(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     traced_cache = Cache(app, config={"CACHE_TYPE": "redis"})
     # expect only the resource name
     expected_resource = "get"
     resource = _resource_from_cache_prefix("GET", traced_cache.config)
     assert resource == expected_resource
コード例 #23
0
ファイル: test.py プロジェクト: tebriel/dd-trace-py
 def test_default_span_tags(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     cache = Cache(app, config={"CACHE_TYPE": "simple"})
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         eq_(span.service, cache._datadog_service)
         eq_(span.span_type, TYPE)
         eq_(span.meta[CACHE_BACKEND], "simple")
         ok_(net.TARGET_HOST not in span.meta)
         ok_(net.TARGET_PORT not in span.meta)
コード例 #24
0
ファイル: test.py プロジェクト: roverdotcom/dd-trace-py
 def test_default_span_tags(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     cache = Cache(app, config={"CACHE_TYPE": "simple"})
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         eq_(span.service, cache._datadog_service)
         eq_(span.span_type, TYPE)
         eq_(span.meta[CACHE_BACKEND], "simple")
         ok_(net.TARGET_HOST not in span.meta)
         ok_(net.TARGET_PORT not in span.meta)
コード例 #25
0
ファイル: test_utils.py プロジェクト: zapier/dd-trace-py
 def test_resource_from_cache_without_prefix(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_REDIS_PORT": REDIS_CONFIG['port'],
         "CACHE_TYPE": "redis",
     }
     traced_cache = Cache(app, config={"CACHE_TYPE": "redis"})
     # expect only the resource name
     expected_resource = "get"
     resource = _resource_from_cache_prefix("GET", traced_cache.config)
     eq_(resource, expected_resource)
コード例 #26
0
ファイル: test_utils.py プロジェクト: tebriel/dd-trace-py
 def test_resource_from_cache_without_prefix(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_REDIS_PORT": REDIS_CONFIG['port'],
         "CACHE_TYPE": "redis",
     }
     traced_cache = Cache(app, config={"CACHE_TYPE": "redis"})
     # expect only the resource name
     expected_resource = "get"
     resource = _resource_from_cache_prefix("GET", traced_cache.config)
     eq_(resource, expected_resource)
コード例 #27
0
ファイル: test_utils.py プロジェクト: tebriel/dd-trace-py
 def test_extract_redis_connection_metadata(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "redis",
         "CACHE_REDIS_PORT": REDIS_CONFIG['port'],
     }
     traced_cache = Cache(app, config=config)
     # extract client data
     meta = _extract_conn_tags(traced_cache.cache._client)
     expected_meta = {'out.host': 'localhost', 'out.port': REDIS_CONFIG['port'], 'out.redis_db': 0}
     eq_(meta, expected_meta)
コード例 #28
0
ファイル: test_utils.py プロジェクト: tebriel/dd-trace-py
 def test_extract_memcached_connection_metadata(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "memcached",
         "CACHE_MEMCACHED_SERVERS": ["127.0.0.1:{}".format(MEMCACHED_CONFIG['port'])],
     }
     traced_cache = Cache(app, config=config)
     # extract client data
     meta = _extract_conn_tags(traced_cache.cache._client)
     expected_meta = {'out.host': '127.0.0.1', 'out.port': MEMCACHED_CONFIG['port']}
     eq_(meta, expected_meta)
コード例 #29
0
 def test_extract_redis_connection_metadata(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "redis",
         "CACHE_REDIS_PORT": REDIS_CONFIG['port'],
     }
     traced_cache = Cache(app, config=config)
     # extract client data
     meta = _extract_conn_tags(traced_cache.cache._client)
     expected_meta = {'out.host': 'localhost', 'out.port': REDIS_CONFIG['port'], 'out.redis_db': 0}
     assert meta == expected_meta
コード例 #30
0
 def test_extract_memcached_connection_metadata(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "memcached",
         "CACHE_MEMCACHED_SERVERS": ["127.0.0.1:{}".format(MEMCACHED_CONFIG['port'])],
     }
     traced_cache = Cache(app, config=config)
     # extract client data
     meta = _extract_conn_tags(traced_cache.cache._client)
     expected_meta = {'out.host': '127.0.0.1', 'out.port': MEMCACHED_CONFIG['port']}
     assert meta == expected_meta
コード例 #31
0
 def test_resource_from_cache_with_empty_prefix(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "redis",
         "CACHE_REDIS_PORT": REDIS_CONFIG['port'],
         "CACHE_KEY_PREFIX": "",
     }
     traced_cache = Cache(app, config=config)
     # expect a resource with a prefix
     expected_resource = "get"
     resource = _resource_from_cache_prefix("GET", traced_cache.cache)
     assert resource == expected_resource
コード例 #32
0
ファイル: test_utils.py プロジェクト: tebriel/dd-trace-py
 def test_resource_from_cache_with_prefix(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "redis",
         "CACHE_REDIS_PORT": REDIS_CONFIG['port'],
         "CACHE_KEY_PREFIX": "users",
     }
     traced_cache = Cache(app, config=config)
     # expect a resource with a prefix
     expected_resource = "get users"
     resource = _resource_from_cache_prefix("GET", traced_cache.cache)
     eq_(resource, expected_resource)
コード例 #33
0
ファイル: test_utils.py プロジェクト: zhammer/dd-trace-py
 def test_resource_from_cache_with_empty_prefix(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         'CACHE_TYPE': 'redis',
         'CACHE_REDIS_PORT': REDIS_CONFIG['port'],
         'CACHE_KEY_PREFIX': '',
     }
     traced_cache = Cache(app, config=config)
     # expect a resource with a prefix
     expected_resource = 'get'
     resource = _resource_from_cache_prefix('GET', traced_cache.cache)
     assert resource == expected_resource
コード例 #34
0
ファイル: test.py プロジェクト: tancnle/dd-trace-py
 def test_default_span_tags_for_redis(self):
     # create the TracedCache instance for a Flask app
     Cache = get_traced_cache(self.tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "redis",
         "CACHE_REDIS_PORT": self.TEST_REDIS_PORT,
     }
     cache = Cache(app, config=config)
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         self.assertEqual(span.service, self.SERVICE)
         self.assertEqual(span.span_type, TYPE)
         self.assertEqual(span.meta[CACHE_BACKEND], "redis")
         self.assertEqual(span.meta[net.TARGET_HOST], 'localhost')
         self.assertEqual(span.meta[net.TARGET_PORT], self.TEST_REDIS_PORT)
コード例 #35
0
 def test_default_span_tags_memcached(self):
     # create the TracedCache instance for a Flask app
     Cache = get_traced_cache(self.tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         'CACHE_TYPE': 'memcached',
         'CACHE_MEMCACHED_SERVERS': ['127.0.0.1:{}'.format(self.TEST_MEMCACHED_PORT)],
     }
     cache = Cache(app, config=config)
     # test tags and attributes
     with cache._TracedCache__trace('flask_cache.cmd') as span:
         self.assertEqual(span.service, self.SERVICE)
         self.assertEqual(span.span_type, 'cache')
         self.assertEqual(span.meta[CACHE_BACKEND], 'memcached')
         self.assertEqual(span.meta[net.TARGET_HOST], '127.0.0.1')
         self.assertEqual(span.metrics[net.TARGET_PORT], self.TEST_MEMCACHED_PORT)
コード例 #36
0
ファイル: test.py プロジェクト: tebriel/dd-trace-py
 def test_default_span_tags_memcached(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "memcached",
         "CACHE_MEMCACHED_SERVERS": ["127.0.0.1:{}".format(self.TEST_MEMCACHED_PORT)],
     }
     cache = Cache(app, config=config)
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         eq_(span.service, cache._datadog_service)
         eq_(span.span_type, TYPE)
         eq_(span.meta[CACHE_BACKEND], "memcached")
         eq_(span.meta[net.TARGET_HOST], "127.0.0.1")
         eq_(span.meta[net.TARGET_PORT], self.TEST_MEMCACHED_PORT)
コード例 #37
0
ファイル: test.py プロジェクト: yuhonghong7035/dd-trace-py
 def test_default_span_tags_memcached(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "memcached",
         "CACHE_MEMCACHED_SERVERS": ["127.0.0.1:{}".format(self.TEST_MEMCACHED_PORT)],
     }
     cache = Cache(app, config=config)
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         eq_(span.service, cache._datadog_service)
         eq_(span.span_type, TYPE)
         eq_(span.meta[CACHE_BACKEND], "memcached")
         eq_(span.meta[net.TARGET_HOST], "127.0.0.1")
         eq_(span.meta[net.TARGET_PORT], self.TEST_MEMCACHED_PORT)
コード例 #38
0
ファイル: test.py プロジェクト: tebriel/dd-trace-py
 def test_default_span_tags_for_redis(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "redis",
         "CACHE_REDIS_PORT": self.TEST_REDIS_PORT,
     }
     cache = Cache(app, config=config)
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         eq_(span.service, cache._datadog_service)
         eq_(span.span_type, TYPE)
         eq_(span.meta[CACHE_BACKEND], "redis")
         eq_(span.meta[net.TARGET_HOST], 'localhost')
         eq_(span.meta[net.TARGET_PORT], self.TEST_REDIS_PORT)
コード例 #39
0
ファイル: test.py プロジェクト: goodspark/dd-trace-py
 def test_default_span_tags_memcached(self):
     # create the TracedCache instance for a Flask app
     Cache = get_traced_cache(self.tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE":
         "memcached",
         "CACHE_MEMCACHED_SERVERS":
         ["127.0.0.1:{}".format(self.TEST_MEMCACHED_PORT)],
     }
     cache = Cache(app, config=config)
     # test tags and attributes
     with cache._TracedCache__trace("flask_cache.cmd") as span:
         self.assertEqual(span.service, self.SERVICE)
         self.assertEqual(span.span_type, "cache")
         self.assertEqual(span.get_tag(CACHE_BACKEND), "memcached")
         self.assertEqual(span.get_tag(net.TARGET_HOST), "127.0.0.1")
         self.assertEqual(span.get_metric(net.TARGET_PORT),
                          self.TEST_MEMCACHED_PORT)
コード例 #40
0
ファイル: test_utils.py プロジェクト: jalaziz/dd-trace-py
 def test_extract_memcached_multiple_connection_metadata(self):
     # create the TracedCache instance for a Flask app
     tracer = Tracer()
     Cache = get_traced_cache(tracer, service=self.SERVICE)
     app = Flask(__name__)
     config = {
         "CACHE_TYPE": "memcached",
         "CACHE_MEMCACHED_SERVERS": [
             "127.0.0.1:{}".format(MEMCACHED_CONFIG["port"]),
             "localhost:{}".format(MEMCACHED_CONFIG["port"]),
         ],
     }
     traced_cache = Cache(app, config=config)
     # extract client data
     meta = _extract_conn_tags(_extract_client(traced_cache.cache))
     expected_meta = {
         "out.host": "127.0.0.1",
         "out.port": MEMCACHED_CONFIG["port"],
     }
     assert meta == expected_meta
コード例 #41
0
    def test_cache_delete_without_arguments(self):
        # create the TracedCache instance for a Flask app
        Cache = get_traced_cache(self.tracer, service=self.SERVICE)
        app = Flask(__name__)
        cache = Cache(app, config={"CACHE_TYPE": "simple"})

        # make a wrong call
        with pytest.raises(TypeError) as ex:
            cache.delete()

        # ensure that the error is not caused by our tracer
        assert "delete()" in ex.value.args[0]
        assert "argument" in ex.value.args[0]
        spans = self.pop_spans()
        # an error trace must be sent
        assert len(spans) == 1
        span = spans[0]
        assert span.service == self.SERVICE
        assert span.resource == "delete"
        assert span.name == "flask_cache.cmd"
        assert span.span_type == "cache"
        assert span.error == 1