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 _translate_to_jaeger(spans: Span): """Translate the spans to Jaeger format. Args: spans: Tuple of spans to convert """ jaeger_spans = [] for span in spans: ctx = span.get_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) status = span.status parent_id = span.parent.span_id if span.parent else 0 tags = _extract_tags(span.attributes) tags.extend(_extract_tags(span.resource.attributes)) tags.extend( [ _get_long_tag("status.code", status.canonical_code.value), _get_string_tag("status.message", status.description), _get_string_tag("span.kind", span.kind.name), ] ) # Ensure that if Status.Code is not OK, that we set the "error" tag on the Jaeger span. if status.canonical_code is not StatusCanonicalCode.OK: tags.append(_get_bool_tag("error", True)) refs = _extract_refs_from_span(span) logs = _extract_logs_from_span(span) flags = int(ctx.trace_flags) jaeger_span = jaeger.Span( traceIdHigh=_get_trace_id_high(trace_id), traceIdLow=_get_trace_id_low(trace_id), # generated code expects i64 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), ) jaeger_spans.append(jaeger_span) return jaeger_spans