opentelemetry_proto/transform/
tracez.rs1#[cfg(all(feature = "gen-tonic-messages", feature = "zpages"))]
2mod tonic {
3 use opentelemetry::trace::{Event, Status};
4 use opentelemetry_sdk::trace::SpanData;
5
6 use crate::proto::tonic::{
7 trace::v1::{span::Event as SpanEvent, Status as SpanStatus},
8 tracez::v1::{ErrorData, LatencyData, RunningData},
9 };
10 use crate::transform::common::{to_nanos, tonic::Attributes};
11
12 impl From<SpanData> for LatencyData {
13 fn from(span_data: SpanData) -> Self {
14 LatencyData {
15 traceid: span_data.span_context.trace_id().to_bytes().to_vec(),
16 spanid: span_data.span_context.span_id().to_bytes().to_vec(),
17 parentid: span_data.parent_span_id.to_bytes().to_vec(),
18 starttime: to_nanos(span_data.start_time),
19 endtime: to_nanos(span_data.end_time),
20 attributes: Attributes::from(span_data.attributes).0,
21 events: span_data.events.iter().cloned().map(Into::into).collect(),
22 links: span_data.links.iter().cloned().map(Into::into).collect(),
23 }
24 }
25 }
26
27 impl From<SpanData> for ErrorData {
28 fn from(span_data: SpanData) -> Self {
29 ErrorData {
30 traceid: span_data.span_context.trace_id().to_bytes().to_vec(),
31 spanid: span_data.span_context.span_id().to_bytes().to_vec(),
32 parentid: span_data.parent_span_id.to_bytes().to_vec(),
33 starttime: to_nanos(span_data.start_time),
34 attributes: Attributes::from(span_data.attributes).0,
35 events: span_data.events.iter().cloned().map(Into::into).collect(),
36 links: span_data.links.iter().cloned().map(Into::into).collect(),
37 status: match span_data.status {
38 Status::Error { description } => Some(SpanStatus {
39 message: description.to_string(),
40 code: 2,
41 }),
42 _ => None,
43 },
44 }
45 }
46 }
47
48 impl From<SpanData> for RunningData {
49 fn from(span_data: SpanData) -> Self {
50 RunningData {
51 traceid: span_data.span_context.trace_id().to_bytes().to_vec(),
52 spanid: span_data.span_context.span_id().to_bytes().to_vec(),
53 parentid: span_data.parent_span_id.to_bytes().to_vec(),
54 starttime: to_nanos(span_data.start_time),
55 attributes: Attributes::from(span_data.attributes).0,
56 events: span_data.events.iter().cloned().map(Into::into).collect(),
57 links: span_data.links.iter().cloned().map(Into::into).collect(),
58 }
59 }
60 }
61
62 impl From<Event> for SpanEvent {
63 fn from(event: Event) -> Self {
64 SpanEvent {
65 time_unix_nano: to_nanos(event.timestamp),
66 name: event.name.to_string(),
67 attributes: Attributes::from(event.attributes).0,
68 dropped_attributes_count: event.dropped_attributes_count,
69 }
70 }
71 }
72}