forked from open-telemetry/opentelemetry-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracez.rs
90 lines (85 loc) · 3.46 KB
/
tracez.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#[cfg(all(feature = "gen-tonic-messages", feature = "zpages"))]
mod grpcio {
use opentelemetry::trace::{Event, Status};
use opentelemetry_sdk::export::trace::SpanData;
use crate::proto::tonic::{
trace::v1::{span::Event as SpanEvent, Status as SpanStatus},
tracez::v1::{ErrorData, LatencyData, RunningData},
};
use crate::transform::common::{to_nanos, tonic::Attributes};
impl From<SpanData> for LatencyData {
fn from(span_data: SpanData) -> Self {
LatencyData {
traceid: span_data.span_context.trace_id().to_bytes().to_vec(),
spanid: span_data.span_context.span_id().to_bytes().to_vec(),
parentid: span_data.parent_span_id.to_bytes().to_vec(),
starttime: to_nanos(span_data.start_time),
endtime: to_nanos(span_data.end_time),
attributes: Attributes::from(span_data.attributes).0,
events: span_data.events.iter().cloned().map(Into::into).collect(),
links: span_data
.span_links
.links
.iter()
.cloned()
.map(Into::into)
.collect(),
}
}
}
impl From<SpanData> for ErrorData {
fn from(span_data: SpanData) -> Self {
ErrorData {
traceid: span_data.span_context.trace_id().to_bytes().to_vec(),
spanid: span_data.span_context.span_id().to_bytes().to_vec(),
parentid: span_data.parent_span_id.to_bytes().to_vec(),
starttime: to_nanos(span_data.start_time),
attributes: Attributes::from(span_data.attributes).0,
events: span_data.events.iter().cloned().map(Into::into).collect(),
links: span_data
.span_links
.links
.iter()
.cloned()
.map(Into::into)
.collect(),
status: match span_data.status {
Status::Error { description } => Some(SpanStatus {
message: description.to_string(),
code: 2,
}),
_ => None,
},
}
}
}
impl From<SpanData> for RunningData {
fn from(span_data: SpanData) -> Self {
RunningData {
traceid: span_data.span_context.trace_id().to_bytes().to_vec(),
spanid: span_data.span_context.span_id().to_bytes().to_vec(),
parentid: span_data.parent_span_id.to_bytes().to_vec(),
starttime: to_nanos(span_data.start_time),
attributes: Attributes::from(span_data.attributes).0,
events: span_data.events.iter().cloned().map(Into::into).collect(),
links: span_data
.span_links
.links
.iter()
.cloned()
.map(Into::into)
.collect(),
}
}
}
impl From<Event> for SpanEvent {
fn from(event: Event) -> Self {
SpanEvent {
time_unix_nano: to_nanos(event.timestamp),
name: event.name.to_string(),
attributes: Attributes::from(event.attributes).0,
dropped_attributes_count: event.dropped_attributes_count,
}
}
}
}