def _translate_span(self, span: ReadableSpan) -> TCollector.Span: ctx = span.get_span_context() trace_id = ctx.trace_id span_id = ctx.span_id start_time_us = _nsec_to_usec_round(span.start_time) duration_us = _nsec_to_usec_round(span.end_time - span.start_time) parent_id = span.parent.span_id if span.parent else 0 tags = self._extract_tags(span) refs = self._extract_refs(span) logs = self._extract_logs(span) flags = int(ctx.trace_flags) jaeger_span = TCollector.Span( traceIdHigh=_get_trace_id_high(trace_id), traceIdLow=_get_trace_id_low(trace_id), spanId=_convert_int_to_i64(span_id), operationName=span.name, startTime=start_time_us, duration=duration_us, tags=tags, logs=logs, references=refs, flags=flags, parentSpanId=_convert_int_to_i64(parent_id), ) return jaeger_span
def _extract_logs( self, span: ReadableSpan) -> Optional[Sequence[TCollector.Log]]: """Returns jaeger logs if events exists, otherwise None. Args: span: span to extract logs """ if not span.events: return None logs = [] for event in span.events: fields = [] for key, value in event.attributes.items(): tag = _translate_attribute(key, value) if tag: fields.append(tag) fields.append( TCollector.Tag( key="message", vType=TCollector.TagType.STRING, vStr=event.name, )) event_timestamp_us = _nsec_to_usec_round(event.timestamp) logs.append( TCollector.Log(timestamp=int(event_timestamp_us), fields=fields)) return logs