def get_exhaustive_test_spans( self, ) -> Tuple[List[SDKSpan], PB2ExportTraceServiceRequest]: otel_spans = self.get_exhaustive_otel_span_list() trace_id = _encode_trace_id(otel_spans[0].context.trace_id) span_kind = _SPAN_KIND_MAP[SDKSpanKind.INTERNAL] pb2_service_request = PB2ExportTraceServiceRequest(resource_spans=[ PB2ResourceSpans( resource=PB2Resource(), instrumentation_library_spans=[ PB2InstrumentationLibrarySpans( instrumentation_library=PB2InstrumentationLibrary(), spans=[ PB2SPan( trace_id=trace_id, span_id=_encode_span_id( otel_spans[0].context.span_id), trace_state=None, parent_span_id=_encode_span_id( otel_spans[0].parent.span_id), name=otel_spans[0].name, kind=span_kind, start_time_unix_nano=otel_spans[0].start_time, end_time_unix_nano=otel_spans[0].end_time, attributes=[ PB2KeyValue( key="key_bool", value=PB2AnyValue(bool_value=False), ), PB2KeyValue( key="key_string", value=PB2AnyValue( string_value="hello_world"), ), PB2KeyValue( key="key_float", value=PB2AnyValue(double_value=111.22), ), ], events=[ PB2SPan.Event( name="event0", time_unix_nano=otel_spans[0].events[0]. timestamp, attributes=[ PB2KeyValue( key="annotation_bool", value=PB2AnyValue( bool_value=True), ), PB2KeyValue( key="annotation_string", value=PB2AnyValue( string_value= "annotation_test"), ), PB2KeyValue( key="key_float", value=PB2AnyValue( double_value=0.3), ), ], ) ], links=[ PB2SPan.Link( trace_id=_encode_trace_id( otel_spans[0].links[0].context. trace_id), span_id=_encode_span_id( otel_spans[0].links[0].context. span_id), attributes=[ PB2KeyValue( key="key_bool", value=PB2AnyValue( bool_value=True), ), ], ) ], status=PB2Status( deprecated_code=PB2Status. DEPRECATED_STATUS_CODE_UNKNOWN_ERROR, # pylint: disable=no-member code=SDKStatusCode.ERROR.value, message="Example description", ), ) ], ), PB2InstrumentationLibrarySpans( instrumentation_library=PB2InstrumentationLibrary( name="name", version="version", ), spans=[ PB2SPan( trace_id=trace_id, span_id=_encode_span_id( otel_spans[3].context.span_id), trace_state=None, parent_span_id=None, name=otel_spans[3].name, kind=span_kind, start_time_unix_nano=otel_spans[3].start_time, end_time_unix_nano=otel_spans[3].end_time, attributes=None, events=None, links=None, status={}, ) ], ), ], ), PB2ResourceSpans( resource=PB2Resource(attributes=[ PB2KeyValue( key="key_resource", value=PB2AnyValue(string_value="some_resource"), ) ]), instrumentation_library_spans=[ PB2InstrumentationLibrarySpans( instrumentation_library=PB2InstrumentationLibrary(), spans=[ PB2SPan( trace_id=trace_id, span_id=_encode_span_id( otel_spans[1].context.span_id), trace_state=None, parent_span_id=None, name=otel_spans[1].name, kind=span_kind, start_time_unix_nano=otel_spans[1].start_time, end_time_unix_nano=otel_spans[1].end_time, attributes=None, events=None, links=None, status={}, ), PB2SPan( trace_id=trace_id, span_id=_encode_span_id( otel_spans[2].context.span_id), trace_state=None, parent_span_id=None, name=otel_spans[2].name, kind=span_kind, start_time_unix_nano=otel_spans[2].start_time, end_time_unix_nano=otel_spans[2].end_time, attributes=[ PB2KeyValue( key="key_string", value=PB2AnyValue( string_value="hello_world"), ), ], events=None, links=None, status={}, ), ], ) ], ), ]) return otel_spans, pb2_service_request
def test_translate_spans(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), ), ], ) ], ) ], ) ], ), ]) # pylint: disable=protected-access self.assertEqual(expected, self.exporter._translate_data([self.span]))