Ejemplo n.º 1
0
 def test_get_span(self):
     tracer = PyramidTracer(DummyTracer())
     req = DummyRequest()
     tracer._apply_tracing(req, [])
     self.assertIsNotNone(tracer.get_span(req), '#B0')
     self.assertIsNone(tracer.get_span(DummyRequest()), '#B1')
     self.assertEqual(1, len(tracer._current_spans), '#B2')
Ejemplo n.º 2
0
    def test_apply_tracing_child(self):
        tracer = PyramidTracer(DummyTracer(returnContext=True))
        span = tracer._apply_tracing(DummyRequest(), [])
        self.assertIsNotNone(span.child_of, '#A0')

        tracer = PyramidTracer(DummyTracer(returnContext=False))
        span = tracer._apply_tracing(DummyRequest(), [])
        self.assertIsNone(span.child_of, '#B0')
Ejemplo n.º 3
0
    def test_apply_tracing_operation_name(self):
        tracer = PyramidTracer(DummyTracer())
        req = DummyRequest()
        req.matched_route = DummyRoute('testing_foo')

        span = tracer._apply_tracing(req, [])
        tracer._finish_tracing(req)
        self.assertEqual('/', span.operation_name)
Ejemplo n.º 4
0
    def test_finish(self):
        tracer = PyramidTracer(DummyTracer())
        req = DummyRequest()
        req.matched_route = DummyRoute()

        span = tracer._apply_tracing(req, [])
        tracer._finish_tracing(req)
        self.assertTrue(span._is_finished)
Ejemplo n.º 5
0
    def test_apply_tracing_matched_route(self):
        tracer = PyramidTracer(DummyTracer())
        req = DummyRequest()
        req.matched_route = DummyRoute('foo')

        span = tracer._apply_tracing(req, [])
        tracer._finish_tracing(req)
        self.assertEqual({
            'component': 'pyramid',
            'pyramid.route': 'foo',
        }, span._tags, '#A0')
Ejemplo n.º 6
0
    def test_apply_tracing_attrs(self):
        tracer = PyramidTracer(DummyTracer())
        req = DummyRequest()

        # Make sure component is available since the start.
        span = tracer._apply_tracing(req, [])
        self.assertEqual({'component': 'pyramid'}, span._tags, 'A#0')
        tracer._finish_tracing(req)
        self.assertEqual({'component': 'pyramid'}, span._tags, '#A1')

        span = tracer._apply_tracing(req, ['dont', 'exist'])
        tracer._finish_tracing(req)
        self.assertEqual({'component': 'pyramid'}, span._tags, '#B0')

        span = tracer._apply_tracing(req, ['host', 'path'])
        tracer._finish_tracing(req)
        self.assertEqual({
            'component': 'pyramid',
            'host': 'example.com:80',
            'path': '/'
        }, span._tags, '#C0')
Ejemplo n.º 7
0
    def test_apply_tracing_operation_name_func(self):
        def test_func(request):
            self.assertIsNotNone(request)
            return 'testing_name'

        tracer = PyramidTracer(DummyTracer(), operation_name_func=test_func)
        req = DummyRequest()
        req.matched_route = DummyRoute('testing_foo')

        span = tracer._apply_tracing(req, [])
        tracer._finish_tracing(req)
        self.assertEqual('testing_name', span.operation_name)
Ejemplo n.º 8
0
 def test_apply_tracing_corrupted(self):
     tracer = PyramidTracer(
         DummyTracer(opentracing.SpanContextCorruptedException()))
     tracer._apply_tracing(DummyRequest(), [])
Ejemplo n.º 9
0
 def test_apply_tracing_invalid(self):
     tracer = PyramidTracer(
         DummyTracer(opentracing.InvalidCarrierException()))
     tracer._apply_tracing(DummyRequest(), [])