Example #1
0
class TraceServerSpanObserverTests(unittest.TestCase):
    def setUp(self):
        self.recorder = NullRecorder()
        self.span = ServerSpan("test-id", "test-parent-id", "test-span-id", None, 0, "test")
        self.test_server_span_observer = TraceServerSpanObserver(
            "test-service", "test-hostname", self.span, self.recorder
        )

    def test_server_span_observer_inherits_span_observer(self):
        # in case of future refactoring
        self.assertTrue(isinstance(self.test_server_span_observer, TraceSpanObserver))
        self.assertTrue(issubclass(TraceServerSpanObserver, TraceSpanObserver))

    def test_serialize_uses_span_info(self):
        serialized_span = self.test_server_span_observer._serialize()
        self.assertEqual(serialized_span["traceId"], self.span.trace_id)
        self.assertEqual(serialized_span["name"], self.span.name)
        self.assertEqual(serialized_span["id"], self.span.id)

    def test_serialize_adds_ss(self):
        serialized_span = self.test_server_span_observer._serialize()
        ss_in_annotation = False
        for annotation in serialized_span["annotations"]:
            if annotation["value"] == "ss":
                ss_in_annotation = True
        self.assertTrue(ss_in_annotation)

    def test_serialize_adds_sr(self):
        serialized_span = self.test_server_span_observer._serialize()
        sr_in_annotation = False
        for annotation in serialized_span["annotations"]:
            if annotation["value"] == "sr":
                sr_in_annotation = True
        self.assertTrue(sr_in_annotation)

    def test_on_child_span_created(self):
        child_span = Span("child-id", "test-parent-id", "test-span-id", None, 0, "test-child")
        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)
Example #2
0
 def setUp(self):
     self.recorder = NullRecorder()
     self.mock_context = mock.Mock()
     self.span = ServerSpan('test-id',
                            'test-parent-id',
                            'test-span-id',
                            None,
                            0,
                            'test',
                            self.mock_context)
     self.test_server_span_observer = TraceServerSpanObserver(
         'test-service',
         'test-hostname',
         self.span,
         self.recorder,
     )
Example #3
0
 def setUp(self):
     self.recorder = NullRecorder()
     self.span = ServerSpan("test-id", "test-parent-id", "test-span-id", None, 0, "test")
     self.test_server_span_observer = TraceServerSpanObserver(
         "test-service", "test-hostname", self.span, self.recorder
     )
Example #4
0
class TraceServerSpanObserverTests(unittest.TestCase):
    def setUp(self):
        self.recorder = NullRecorder()
        self.mock_context = mock.Mock()
        self.span = ServerSpan('test-id',
                               'test-parent-id',
                               'test-span-id',
                               None,
                               0,
                               'test',
                               self.mock_context)
        self.test_server_span_observer = TraceServerSpanObserver(
            'test-service',
            'test-hostname',
            self.span,
            self.recorder,
        )

    def test_server_span_observer_inherits_span_observer(self):
        # in case of future refactoring
        self.assertTrue(isinstance(self.test_server_span_observer,
                                   TraceSpanObserver))
        self.assertTrue(issubclass(TraceServerSpanObserver,
                                   TraceSpanObserver))

    def test_serialize_uses_span_info(self):
        serialized_span = self.test_server_span_observer._serialize()
        self.assertEqual(serialized_span['traceId'], self.span.trace_id)
        self.assertEqual(serialized_span['name'], self.span.name)
        self.assertEqual(serialized_span['id'], self.span.id)

    def test_serialize_adds_ss(self):
        serialized_span = self.test_server_span_observer._serialize()
        ss_in_annotation = False
        for annotation in serialized_span['annotations']:
            if annotation['value'] == 'ss':
                ss_in_annotation = True
        self.assertTrue(ss_in_annotation)

    def test_serialize_adds_sr(self):
        serialized_span = self.test_server_span_observer._serialize()
        sr_in_annotation = False
        for annotation in serialized_span['annotations']:
            if annotation['value'] == 'sr':
                sr_in_annotation = True
        self.assertTrue(sr_in_annotation)

    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)