class TraceSpanObserverTests(unittest.TestCase): def setUp(self): 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) def test_serialize_uses_span_info(self): serialized_span = self.test_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_cs(self): serialized_span = self.test_span_observer._serialize() cs_in_annotation = False for annotation in serialized_span['annotations']: if annotation['value'] == 'cs': cs_in_annotation = True self.assertTrue(cs_in_annotation) def test_serialize_adds_cr(self): serialized_span = self.test_span_observer._serialize() cr_in_annotation = False for annotation in serialized_span['annotations']: if annotation['value'] == 'cr': cr_in_annotation = True self.assertTrue(cr_in_annotation) def test_serialize_adds_binary_annotations(self): self.test_span_observer.on_set_tag('test-key', 'test-value') serialized_span = self.test_span_observer._serialize() self.assertEqual(len(serialized_span['binaryAnnotations']), 1) annotation = serialized_span['binaryAnnotations'][0] self.assertEqual(annotation['key'], 'test-key') self.assertEqual(annotation['value'], 'test-value') def test_on_start_sets_start_timestamp(self): # on-start should set start time self.assertIsNone(self.test_span_observer.start) self.test_span_observer.on_start() self.assertIsNotNone(self.test_span_observer.start) def test_on_finish_sets_end_timestamp_and_duration(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_on_finish_records(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_create_binary_annotation(self): annotation = self.test_span_observer._create_binary_annotation( 'test-key', 'test-value') self.assertEquals(annotation['key'], 'test-key') self.assertEquals(annotation['value'], 'test-value') self.assertTrue(annotation['endpoint']) def test_create_binary_annotation_coerces_string(self): annotation = self.test_span_observer._create_binary_annotation( 'test-key', 1) self.assertEquals(annotation['key'], 'test-key') self.assertEquals(annotation['value'], '1') self.assertTrue(annotation['endpoint']) def test_on_set_tag_adds_binary_annotation(self): self.assertFalse(self.test_span_observer.binary_annotations) self.test_span_observer.on_set_tag('test-key', 'test-value') self.assertTrue(self.test_span_observer.binary_annotations) annotation = self.test_span_observer.binary_annotations[0] self.assertEquals(annotation['key'], 'test-key') self.assertEquals(annotation['value'], 'test-value') def test_to_span_obj_sets_parent_id(self): span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj['parentId'], self.span.parent_id) def test_to_span_obj_sets_default_parent_id(self): self.span.parent_id = None span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj['parentId'], 0)
class TraceSpanObserverTests(TraceTestBase): 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) def test_serialize_uses_span_info(self): serialized_span = self.test_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_cs(self): serialized_span = self.test_span_observer._serialize() cs_in_annotation = False for annotation in serialized_span["annotations"]: if annotation["value"] == "cs": cs_in_annotation = True self.assertTrue(cs_in_annotation) def test_serialize_adds_cr(self): serialized_span = self.test_span_observer._serialize() cr_in_annotation = False for annotation in serialized_span["annotations"]: if annotation["value"] == "cr": cr_in_annotation = True self.assertTrue(cr_in_annotation) def test_serialize_adds_binary_annotations(self): self.test_span_observer.on_set_tag("test-key", "test-value") serialized_span = self.test_span_observer._serialize() self.assertEqual(len(serialized_span["binaryAnnotations"]), 1) annotation = serialized_span["binaryAnnotations"][0] self.assertEqual(annotation["key"], "test-key") self.assertEqual(annotation["value"], "test-value") def test_on_start_sets_start_timestamp(self): # on-start should set start time self.assertIsNone(self.test_span_observer.start) self.test_span_observer.on_start() self.assertIsNotNone(self.test_span_observer.start) def test_on_finish_sets_end_timestamp_and_duration(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_on_finish_records(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_create_binary_annotation(self): annotation = self.test_span_observer._create_binary_annotation( "test-key", "test-value") self.assertEquals(annotation["key"], "test-key") self.assertEquals(annotation["value"], "test-value") self.assertTrue(annotation["endpoint"]) def test_create_binary_annotation_coerces_string(self): annotation = self.test_span_observer._create_binary_annotation( "test-key", 1) self.assertEquals(annotation["key"], "test-key") self.assertEquals(annotation["value"], "1") self.assertTrue(annotation["endpoint"]) def test_on_set_tag_adds_binary_annotation(self): self.assertFalse(self.test_span_observer.binary_annotations) self.test_span_observer.on_set_tag("test-key", "test-value") self.assertTrue(self.test_span_observer.binary_annotations) annotation = self.test_span_observer.binary_annotations[0] self.assertEquals(annotation["key"], "test-key") self.assertEquals(annotation["value"], "test-value") def test_to_span_obj_sets_parent_id(self): span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj["parentId"], self.span.parent_id) def test_to_span_obj_sets_default_parent_id(self): self.span.parent_id = None span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj["parentId"], 0)
class TraceSpanObserverTests(unittest.TestCase): 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) def test_serialize_uses_span_info(self): serialized_span = self.test_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_cs(self): serialized_span = self.test_span_observer._serialize() cs_in_annotation = False for annotation in serialized_span["annotations"]: if annotation["value"] == "cs": cs_in_annotation = True self.assertTrue(cs_in_annotation) def test_serialize_adds_cr(self): serialized_span = self.test_span_observer._serialize() cr_in_annotation = False for annotation in serialized_span["annotations"]: if annotation["value"] == "cr": cr_in_annotation = True self.assertTrue(cr_in_annotation) def test_serialize_adds_binary_annotations(self): serialized_span = self.test_span_observer._serialize() self.assertFalse(serialized_span["binary_annotations"]) def test_on_start_sets_start_timestamp(self): # on-start should set start time self.assertIsNone(self.test_span_observer.start) self.test_span_observer.on_start() self.assertIsNotNone(self.test_span_observer.start) def test_on_finish_sets_end_timestamp_and_duration(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_on_finish_records(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_create_binary_annotation(self): annotation = self.test_span_observer._create_binary_annotation("test-key", "test-value") self.assertEquals(annotation["key"], "test-key") self.assertEquals(annotation["value"], "test-value") self.assertTrue(annotation["endpoint"]) def test_on_set_tag_adds_binary_annotation(self): self.assertFalse(self.test_span_observer.binary_annotations) self.test_span_observer.on_set_tag("test-key", "test-value") self.assertTrue(self.test_span_observer.binary_annotations) annotation = self.test_span_observer.binary_annotations[0] self.assertEquals(annotation["key"], "test-key") self.assertEquals(annotation["value"], "test-value") def test_to_span_obj_sets_parent_id(self): span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj["parentId"], self.span.parent_id) def test_to_span_obj_sets_default_parent_id(self): self.span.parent_id = None span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj["parentId"], 0)
class TraceSpanObserverTests(unittest.TestCase): def setUp(self): 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) def test_serialize_uses_span_info(self): serialized_span = self.test_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_cs(self): serialized_span = self.test_span_observer._serialize() cs_in_annotation = False for annotation in serialized_span['annotations']: if annotation['value'] == 'cs': cs_in_annotation = True self.assertTrue(cs_in_annotation) def test_serialize_adds_cr(self): serialized_span = self.test_span_observer._serialize() cr_in_annotation = False for annotation in serialized_span['annotations']: if annotation['value'] == 'cr': cr_in_annotation = True self.assertTrue(cr_in_annotation) def test_serialize_adds_binary_annotations(self): self.test_span_observer.on_set_tag('test-key', 'test-value') serialized_span = self.test_span_observer._serialize() self.assertEqual(len(serialized_span['binaryAnnotations']), 1) annotation = serialized_span['binaryAnnotations'][0] self.assertEqual(annotation['key'], 'test-key') self.assertEqual(annotation['value'], 'test-value') def test_on_start_sets_start_timestamp(self): # on-start should set start time self.assertIsNone(self.test_span_observer.start) self.test_span_observer.on_start() self.assertIsNotNone(self.test_span_observer.start) def test_on_finish_sets_end_timestamp_and_duration(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_on_finish_records(self): self.assertIsNone(self.test_span_observer.end) self.test_span_observer.on_start() self.test_span_observer.on_finish(None) self.assertIsNotNone(self.test_span_observer.end) def test_create_binary_annotation(self): annotation = self.test_span_observer._create_binary_annotation( 'test-key', 'test-value' ) self.assertEquals(annotation['key'], 'test-key') self.assertEquals(annotation['value'], 'test-value') self.assertTrue(annotation['endpoint']) def test_create_binary_annotation_coerces_string(self): annotation = self.test_span_observer._create_binary_annotation( 'test-key', 1 ) self.assertEquals(annotation['key'], 'test-key') self.assertEquals(annotation['value'], '1') self.assertTrue(annotation['endpoint']) def test_on_set_tag_adds_binary_annotation(self): self.assertFalse(self.test_span_observer.binary_annotations) self.test_span_observer.on_set_tag('test-key', 'test-value') self.assertTrue(self.test_span_observer.binary_annotations) annotation = self.test_span_observer.binary_annotations[0] self.assertEquals(annotation['key'], 'test-key') self.assertEquals(annotation['value'], 'test-value') def test_to_span_obj_sets_parent_id(self): span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj['parentId'], self.span.parent_id) def test_to_span_obj_sets_default_parent_id(self): self.span.parent_id = None span_obj = self.test_span_observer._to_span_obj([], []) self.assertEqual(span_obj['parentId'], 0)