Пример #1
0
 def _translate_attributes(self, log_data: LogData) -> None:
     if log_data.log_record.attributes:
         self._collector_log_kwargs["attributes"] = []
         for key, value in log_data.log_record.attributes.items():
             try:
                 self._collector_log_kwargs["attributes"].append(
                     _translate_key_values(key, value))
             except Exception:  # pylint: disable=broad-except
                 pass
Пример #2
0
    def _translate_attributes(self, sdk_span: ReadableSpan) -> None:
        if sdk_span.attributes:

            self._collector_span_kwargs["attributes"] = []

            for key, value in sdk_span.attributes.items():

                try:
                    self._collector_span_kwargs["attributes"].append(
                        _translate_key_values(key, value))
                except Exception as error:  # pylint: disable=broad-except
                    logger.exception(error)
Пример #3
0
    def test_translate_key_values(self):
        bool_value = _translate_key_values("bool_type", False)
        self.assertTrue(isinstance(bool_value, KeyValue))
        self.assertEqual(bool_value.key, "bool_type")
        self.assertTrue(isinstance(bool_value.value, AnyValue))
        self.assertFalse(bool_value.value.bool_value)

        str_value = _translate_key_values("str_type", "str")
        self.assertTrue(isinstance(str_value, KeyValue))
        self.assertEqual(str_value.key, "str_type")
        self.assertTrue(isinstance(str_value.value, AnyValue))
        self.assertEqual(str_value.value.string_value, "str")

        int_value = _translate_key_values("int_type", 2)
        self.assertTrue(isinstance(int_value, KeyValue))
        self.assertEqual(int_value.key, "int_type")
        self.assertTrue(isinstance(int_value.value, AnyValue))
        self.assertEqual(int_value.value.int_value, 2)

        double_value = _translate_key_values("double_type", 3.2)
        self.assertTrue(isinstance(double_value, KeyValue))
        self.assertEqual(double_value.key, "double_type")
        self.assertTrue(isinstance(double_value.value, AnyValue))
        self.assertEqual(double_value.value.double_value, 3.2)

        seq_value = _translate_key_values("seq_type", ["asd", "123"])
        self.assertTrue(isinstance(seq_value, KeyValue))
        self.assertEqual(seq_value.key, "seq_type")
        self.assertTrue(isinstance(seq_value.value, AnyValue))
        self.assertTrue(isinstance(seq_value.value.array_value, ArrayValue))

        arr_value = seq_value.value.array_value
        self.assertTrue(isinstance(arr_value.values[0], AnyValue))
        self.assertEqual(arr_value.values[0].string_value, "asd")
        self.assertTrue(isinstance(arr_value.values[1], AnyValue))
        self.assertEqual(arr_value.values[1].string_value, "123")
Пример #4
0
    def _translate_events(self, sdk_span: ReadableSpan) -> None:
        if sdk_span.events:
            self._collector_kwargs["events"] = []

            for sdk_span_event in sdk_span.events:

                collector_span_event = CollectorSpan.Event(
                    name=sdk_span_event.name,
                    time_unix_nano=sdk_span_event.timestamp,
                    dropped_attributes_count=sdk_span_event.attributes.dropped,
                )

                for key, value in sdk_span_event.attributes.items():
                    try:
                        collector_span_event.attributes.append(
                            _translate_key_values(key, value))
                    # pylint: disable=broad-except
                    except Exception as error:
                        logger.exception(error)

                self._collector_kwargs["events"].append(collector_span_event)
Пример #5
0
    def _translate_links(self, sdk_span: ReadableSpan) -> None:
        if sdk_span.links:
            self._collector_kwargs["links"] = []

            for sdk_span_link in sdk_span.links:

                collector_span_link = CollectorSpan.Link(
                    trace_id=(sdk_span_link.context.trace_id.to_bytes(
                        16, "big")),
                    span_id=(sdk_span_link.context.span_id.to_bytes(8, "big")),
                    dropped_attributes_count=sdk_span_link.attributes.dropped,
                )

                for key, value in sdk_span_link.attributes.items():
                    try:
                        collector_span_link.attributes.append(
                            _translate_key_values(key, value))
                    # pylint: disable=broad-except
                    except Exception as error:
                        logger.exception(error)

                self._collector_kwargs["links"].append(collector_span_link)