def setUpClass(cls):
     cls.project_id = "PROJECT"
     cls.attributes_variety_pack = {
         "str_key": "str_value",
         "bool_key": False,
         "double_key": 1.421,
         "int_key": 123,
     }
     cls.extracted_attributes_variety_pack = ProtoSpan.Attributes(
         attribute_map={
             "str_key":
             AttributeValue(string_value=TruncatableString(
                 value="str_value", truncated_byte_count=0)),
             "bool_key":
             AttributeValue(bool_value=False),
             "double_key":
             AttributeValue(string_value=TruncatableString(
                 value="1.4210", truncated_byte_count=0)),
             "int_key":
             AttributeValue(int_value=123),
         })
     cls.agent_code = _format_attribute_value(
         "opentelemetry-python {}; google-cloud-trace-exporter {}".format(
             _strip_characters(
                 pkg_resources.get_distribution(
                     "opentelemetry-sdk").version),
             _strip_characters(google_ext_version),
         ))
     cls.example_trace_id = "6e0c63257de34c92bf9efcd03927272e"
     cls.example_span_id = "95bb5edabd45950f"
     cls.example_time_in_ns = 1589919268850900051
     cls.example_time_stamp = _get_time_from_ns(cls.example_time_in_ns)
     cls.str_300 = "a" * 300
     cls.str_256 = "a" * 256
     cls.str_128 = "a" * 128
Пример #2
0
 def test_extract_multiple_events(self):
     event1 = Event(
         name="event1",
         attributes=self.attributes_variety_pack,
         timestamp=self.example_time_in_ns,
     )
     event2_nanos = 1589919438550020326
     event2 = Event(
         name="event2",
         attributes={"illegal_attr_value": dict()},
         timestamp=event2_nanos,
     )
     self.assertEqual(
         _extract_events([event1, event2]),
         ProtoSpan.TimeEvents(
             time_event=[
                 {
                     "time": self.example_time_stamp,
                     "annotation": {
                         "description": TruncatableString(
                             value="event1", truncated_byte_count=0
                         ),
                         "attributes": self.extracted_attributes_variety_pack,
                     },
                 },
                 {
                     "time": _get_time_from_ns(event2_nanos),
                     "annotation": {
                         "description": TruncatableString(
                             value="event2", truncated_byte_count=0
                         ),
                         "attributes": ProtoSpan.Attributes(
                             attribute_map={}, dropped_attributes_count=1
                         ),
                     },
                 },
             ]
         ),
     )