コード例 #1
0
    def test_set_annotation_with_attributes(self):
        pb_span = trace_pb2.Span()
        pb_event = pb_span.time_events.time_event.add()

        annotation = time_event_module.Annotation(
            description="hi there",
            attributes=attributes_module.Attributes(
                attributes={
                    'test_str_key': 'test_str_value',
                    'test_int_key': 1,
                    'test_bool_key': False,
                    'test_double_key': 567.89
                }))

        utils.set_proto_annotation(pb_event.annotation, annotation)

        self.assertEqual(pb_event.annotation.description.value, "hi there")
        self.assertEqual(len(pb_event.annotation.attributes.attribute_map), 3)
        self.assertEqual(
            pb_event.annotation.attributes.attribute_map['test_str_key'],
            trace_pb2.AttributeValue(string_value=trace_pb2.TruncatableString(
                value='test_str_value')))
        self.assertEqual(
            pb_event.annotation.attributes.attribute_map['test_int_key'],
            trace_pb2.AttributeValue(int_value=1))
        self.assertEqual(
            pb_event.annotation.attributes.attribute_map['test_bool_key'],
            trace_pb2.AttributeValue(bool_value=False))
        self.assertEqual(
            pb_event.annotation.attributes.attribute_map['test_double_key'],
            trace_pb2.AttributeValue(double_value=567.89))
コード例 #2
0
    def test_set_annotation_without_attributes(self):
        pb_span = trace_pb2.Span()
        pb_event0 = pb_span.time_events.time_event.add()
        pb_event1 = pb_span.time_events.time_event.add()

        annotation0 = time_event_module.Annotation(description="hi there0")
        annotation1 = time_event_module.Annotation(
            description="hi there1", attributes=attributes_module.Attributes())

        utils.set_proto_annotation(pb_event0.annotation, annotation0)
        utils.set_proto_annotation(pb_event1.annotation, annotation1)

        self.assertEqual(pb_event0.annotation.description.value, "hi there0")
        self.assertEqual(pb_event1.annotation.description.value, "hi there1")
        self.assertEqual(len(pb_event0.annotation.attributes.attribute_map), 0)
        self.assertEqual(len(pb_event1.annotation.attributes.attribute_map), 0)