def _translate_status(self, sdk_span: ReadableSpan) -> None: # pylint: disable=no-member if sdk_span.status is not None: self._collector_kwargs["status"] = Status( code=sdk_span.status.status_code.value, message=sdk_span.status.description, )
def _translate_status(self, sdk_span: SDKSpan) -> None: if sdk_span.status is not None: # TODO: Update this when the proto definitions are updated to include UNSET and ERROR proto_status_code = Status.STATUS_CODE_OK if sdk_span.status.status_code is StatusCode.ERROR: proto_status_code = Status.STATUS_CODE_UNKNOWN_ERROR self._collector_span_kwargs["status"] = Status( code=proto_status_code, message=sdk_span.status.description, )
def _translate_status(self, sdk_span: ReadableSpan) -> None: # pylint: disable=no-member if sdk_span.status is not None: deprecated_code = Status.DEPRECATED_STATUS_CODE_OK if sdk_span.status.status_code == StatusCode.ERROR: deprecated_code = Status.DEPRECATED_STATUS_CODE_UNKNOWN_ERROR self._collector_span_kwargs["status"] = Status( deprecated_code=deprecated_code, code=sdk_span.status.status_code.value, message=sdk_span.status.description, )
def test_translate_spans(self): expected = ExportTraceServiceRequest( resource_spans=[ ResourceSpans( resource=CollectorResource( attributes=[ AttributeKeyValue(key="a", int_value=1), AttributeKeyValue(key="b", bool_value=False), ] ), instrumentation_library_spans=[ InstrumentationLibrarySpans( spans=[ CollectorSpan( # pylint: disable=no-member name="a", start_time_unix_nano=self.span.start_time, end_time_unix_nano=self.span.end_time, trace_state="a=b,c=d", span_id=int.to_bytes( 10217189687419569865, 8, "big" ), trace_id=int.to_bytes( 67545097771067222548457157018666467027, 16, "big", ), parent_span_id=( b"\000\000\000\000\000\00009" ), kind=CollectorSpan.SpanKind.INTERNAL, attributes=[ AttributeKeyValue( key="a", int_value=1 ), AttributeKeyValue( key="b", bool_value=True ), ], events=[ CollectorSpan.Event( name="a", time_unix_nano=1591240820506462784, attributes=[ AttributeKeyValue( key="a", int_value=1 ), AttributeKeyValue( key="b", int_value=False ), ], ) ], status=Status(code=0, message=""), links=[ CollectorSpan.Link( trace_id=int.to_bytes( 1, 16, "big" ), span_id=int.to_bytes(2, 8, "big"), attributes=[ AttributeKeyValue( key="a", int_value=1 ), AttributeKeyValue( key="b", bool_value=False ), ], ) ], ) ] ) ], ), ] ) # pylint: disable=protected-access self.assertEqual(expected, self.exporter._translate_spans([self.span]))
def _translate_status(self, sdk_span): if sdk_span.status is not None: self._collector_span_kwargs["status"] = Status( code=sdk_span.status.canonical_code.value, message=sdk_span.status.description, )
def test_translate_spans_multi(self): expected = ExportTraceServiceRequest( resource_spans=[ ResourceSpans( resource=OTLPResource( attributes=[ KeyValue(key="a", value=AnyValue(int_value=1)), KeyValue( key="b", value=AnyValue(bool_value=False) ), ] ), instrumentation_library_spans=[ InstrumentationLibrarySpans( instrumentation_library=InstrumentationLibrary( name="name", version="version" ), spans=[ OTLPSpan( # pylint: disable=no-member name="a", start_time_unix_nano=self.span.start_time, end_time_unix_nano=self.span.end_time, trace_state="a=b,c=d", span_id=int.to_bytes( 10217189687419569865, 8, "big" ), trace_id=int.to_bytes( 67545097771067222548457157018666467027, 16, "big", ), parent_span_id=( b"\000\000\000\000\000\00009" ), kind=( OTLPSpan.SpanKind.SPAN_KIND_INTERNAL ), attributes=[ KeyValue( key="a", value=AnyValue(int_value=1), ), KeyValue( key="b", value=AnyValue(bool_value=True), ), ], events=[ OTLPSpan.Event( name="a", time_unix_nano=1591240820506462784, attributes=[ KeyValue( key="a", value=AnyValue( int_value=1 ), ), KeyValue( key="b", value=AnyValue( bool_value=False ), ), ], ) ], status=Status(code=0, message=""), links=[ OTLPSpan.Link( trace_id=int.to_bytes( 1, 16, "big" ), span_id=int.to_bytes(2, 8, "big"), attributes=[ KeyValue( key="a", value=AnyValue( int_value=1 ), ), KeyValue( key="b", value=AnyValue( bool_value=False ), ), ], ) ], ) ], ), InstrumentationLibrarySpans( instrumentation_library=InstrumentationLibrary( name="name2", version="version2" ), spans=[ OTLPSpan( # pylint: disable=no-member name="c", start_time_unix_nano=self.span3.start_time, end_time_unix_nano=self.span3.end_time, trace_state="a=b,c=d", span_id=int.to_bytes( 10217189687419569865, 8, "big" ), trace_id=int.to_bytes( 67545097771067222548457157018666467027, 16, "big", ), parent_span_id=( b"\000\000\000\000\000\00009" ), kind=( OTLPSpan.SpanKind.SPAN_KIND_INTERNAL ), status=Status(code=0, message=""), ) ], ), ], ), ResourceSpans( resource=OTLPResource( attributes=[ KeyValue(key="a", value=AnyValue(int_value=2)), KeyValue( key="b", value=AnyValue(bool_value=False) ), ] ), instrumentation_library_spans=[ InstrumentationLibrarySpans( instrumentation_library=InstrumentationLibrary( name="name", version="version" ), spans=[ OTLPSpan( # pylint: disable=no-member name="b", start_time_unix_nano=self.span2.start_time, end_time_unix_nano=self.span2.end_time, trace_state="a=b,c=d", span_id=int.to_bytes( 10217189687419569865, 8, "big" ), trace_id=int.to_bytes( 67545097771067222548457157018666467027, 16, "big", ), parent_span_id=( b"\000\000\000\000\000\00009" ), kind=( OTLPSpan.SpanKind.SPAN_KIND_INTERNAL ), status=Status(code=0, message=""), ) ], ) ], ), ] ) # pylint: disable=protected-access self.assertEqual( expected, self.exporter._translate_data([self.span, self.span2, self.span3]), )