示例#1
0
    def test_context(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span._register(mock_observer)

        with span:
            self.assertEqual(mock_observer.on_start.call_count, 1)
        self.assertEqual(mock_observer.on_stop.call_count, 1)
示例#2
0
 def test_should_sample_utilizes_force_sampling(self):
     client = make_client("test-service", sample_rate=0)
     baseplate_observer = TraceBaseplateObserver(client)
     span_with_forced = Span('test-id', 'test-parent', 'test-span-id',
                             False, 1, "test", self.mock_context)
     span_without_forced = Span('test-id', 'test-parent', 'test-span-id',
                                False, 0, "test", self.mock_context)
     self.assertTrue(baseplate_observer.should_sample(span_with_forced))
     self.assertFalse(baseplate_observer.should_sample(span_without_forced))
示例#3
0
    def test_context(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span.register(mock_observer)

        with span:
            self.assertEqual(mock_observer.on_start.call_count, 1)
        self.assertEqual(mock_observer.on_finish.call_count, 1)
示例#4
0
 def test_should_sample_utilizes_force_sampling(self):
     baseplate_observer = TraceBaseplateObserver('test-service',
                                                 sample_rate=0)
     span_with_forced = Span('test-id', 'test-parent', 'test-span-id',
                             False, 1, "test")
     span_without_forced = Span('test-id', 'test-parent', 'test-span-id',
                                False, 0, "test")
     self.assertTrue(baseplate_observer.should_sample(span_with_forced))
     self.assertFalse(baseplate_observer.should_sample(span_without_forced))
示例#5
0
 def test_force_sampling(self):
     span_with_debug_flag = Span('test-id', 'test-parent', 'test-span-id',
                                 True, 1, "test")
     span_without_debug_flag = Span('test-id', 'test-parent',
                                    'test-span-id', True, 0, "test")
     self.assertTrue(
         TraceBaseplateObserver.force_sampling(span_with_debug_flag))
     self.assertFalse(
         TraceBaseplateObserver.force_sampling(span_without_debug_flag))
示例#6
0
 def test_force_sampling(self):
     span_with_debug_flag = Span("test-id", "test-parent", "test-span-id",
                                 True, 1, "test", self.mock_context)
     span_without_debug_flag = Span("test-id", "test-parent",
                                    "test-span-id", True, 0, "test",
                                    self.mock_context)
     self.assertTrue(
         TraceBaseplateObserver.force_sampling(span_with_debug_flag))
     self.assertFalse(
         TraceBaseplateObserver.force_sampling(span_without_debug_flag))
示例#7
0
    def test_events(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span.register(mock_observer)

        span.start()
        self.assertEqual(mock_observer.on_start.call_count, 1)

        span.annotate("key", "value")
        mock_observer.on_annotate("key", "value")

        span.stop()
        mock_observer.on_stop(error=None)
示例#8
0
    def test_context_with_exception(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span.register(mock_observer)

        class TestException(Exception):
            pass

        exc = TestException()
        with self.assertRaises(TestException):
            with span:
                raise exc
        self.assertEqual(mock_observer.on_stop.call_count, 1)
        self.assertEqual(mock_observer.on_stop.call_args, mock.call(error=exc))
示例#9
0
    def test_context_with_exception(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span._register(mock_observer)

        class TestException(Exception):
            pass

        exc = TestException()
        with self.assertRaises(TestException):
            with span:
                raise exc
        self.assertEqual(mock_observer.on_stop.call_count, 1)
        self.assertEqual(mock_observer.on_stop.call_args, mock.call(error=exc))
示例#10
0
 def setUp(self):
     self.recorder = NullRecorder()
     self.span = Span('test-id', 'test-parent-id', 'test-span-id', None, 0,
                      'test')
     self.test_span_observer = TraceSpanObserver('test-service',
                                                 'test-hostname', self.span,
                                                 self.recorder)
示例#11
0
 def test_should_sample_utilizes_sample_rate(self):
     baseplate_observer = TraceBaseplateObserver('test-service',
                                                 sample_rate=1)
     span = Span('test-id', 'test-parent', 'test-span-id', None, 0, "test")
     self.assertTrue(baseplate_observer.should_sample(span))
     baseplate_observer.sample_rate = 0
     self.assertFalse(baseplate_observer.should_sample(span))
示例#12
0
 def test_should_sample_utilizes_sampled_setting(self):
     baseplate_observer = TraceBaseplateObserver('test-service',
                                                 sample_rate=0)
     span_with_sampled_flag = Span('test-id', 'test-parent', 'test-span-id',
                                   True, 0, "test")
     self.assertTrue(
         baseplate_observer.should_sample(span_with_sampled_flag))
示例#13
0
    def test_context_with_exception(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, None, 0, "name")
        span.register(mock_observer)

        class TestException(Exception):
            pass

        exc = TestException()
        with self.assertRaises(TestException):
            with span:
                raise exc
        self.assertEqual(mock_observer.on_finish.call_count, 1)
        _, captured_exc, _ = mock_observer.on_finish.call_args[0][0]
        self.assertEqual(captured_exc, exc)
示例#14
0
def make_test_span(context=None, local=False):
    if not context:
        context = mock.Mock()
    span = Span(1, 2, 3, None, 0, "name", context)
    if local:
        span = LocalSpan(1, 2, 3, None, 0, "name", context)
    return span
示例#15
0
 def test_should_sample_utilizes_sampled_setting(self):
     client = make_client("test-service", sample_rate=0)
     baseplate_observer = TraceBaseplateObserver(client)
     span_with_sampled_flag = Span('test-id', 'test-parent', 'test-span-id',
                                   True, 0, "test", self.mock_context)
     self.assertTrue(
         baseplate_observer.should_sample(span_with_sampled_flag))
示例#16
0
    def test_context_with_exception(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span.register(mock_observer)

        class TestException(Exception):
            pass

        exc = TestException()
        with self.assertRaises(TestException):
            with span:
                raise exc
        self.assertEqual(mock_observer.on_finish.call_count, 1)
        _, captured_exc, _ = mock_observer.on_finish.call_args[0][0]
        self.assertEqual(captured_exc, exc)
示例#17
0
 def test_should_sample_utilizes_sample_rate(self):
     client = make_client("test-service", sample_rate=1)
     baseplate_observer = TraceBaseplateObserver(client)
     span = Span('test-id', 'test-parent', 'test-span-id', None, 0, "test",
                 self.mock_context)
     self.assertTrue(baseplate_observer.should_sample(span))
     baseplate_observer.sample_rate = 0
     self.assertFalse(baseplate_observer.should_sample(span))
示例#18
0
 def test_on_child_span_created(self):
     child_span = Span("child-id", "test-parent-id", "test-span-id", None,
                       0, "test-child", self.mock_context)
     self.test_server_span_observer.on_child_span_created(child_span)
     # Make sure new trace observer is added in the child span
     #  and the trace observer's span is that child span
     self.assertEqual(len(child_span.observers), 1)
     self.assertEqual(child_span.observers[0].span, child_span)
示例#19
0
    def test_events(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span._register(mock_observer)

        span.start()
        self.assertEqual(mock_observer.on_start.call_count, 1)

        span.annotate("key", "value")
        mock_observer.on_annotate("key", "value")

        span.stop()
        mock_observer.on_stop(error=None)
示例#20
0
 def test_null_recorder_flush(self):
     span = Span('test-id',
                 'test-parent-id',
                 'test-span-id',
                 None,
                 0,
                 'test',
                 self.mock_context)
     self.recorder.flush_func([span])
示例#21
0
    def setUp(self):
        super(TraceSpanObserverTests, self).setUp()
        self.recorder = NullRecorder()
        self.mock_context = mock.Mock()

        self.span = Span("test-id", "test-parent-id", "test-span-id", None, 0,
                         "test", self.mock_context)
        self.test_span_observer = TraceSpanObserver("test-service",
                                                    "test-hostname", self.span,
                                                    self.recorder)
示例#22
0
    def test_events(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, "name")
        span.register(mock_observer)

        span.start()
        self.assertEqual(mock_observer.on_start.call_count, 1)

        span.set_tag("key", "value")
        mock_observer.on_set_tag("key", "value")

        span.log("name", "payload")
        mock_observer.on_log("name", "payload")

        span.finish()
        mock_observer.on_finish(exc_info=None)
示例#23
0
 def test_null_recorder_flush(self):
     span = Span("test-id", "test-parent-id", "test-span-id", None, 0,
                 "test", self.mock_context)
     self.recorder.flush_func([span])
示例#24
0
    def test_events(self):
        mock_observer = mock.Mock(spec=SpanObserver)

        span = Span(1, 2, 3, None, 0, "name")
        span.register(mock_observer)

        span.start()
        self.assertEqual(mock_observer.on_start.call_count, 1)

        span.set_tag("key", "value")
        mock_observer.on_set_tag("key", "value")

        span.log("name", "payload")
        mock_observer.on_log("name", "payload")

        span.finish()
        mock_observer.on_finish(exc_info=None)