Skip to content

Commit 1560773

Browse files
remove dropped_attribute_counts from API
1 parent 8882c31 commit 1560773

File tree

5 files changed

+105
-77
lines changed

5 files changed

+105
-77
lines changed

opentelemetry-proto/src/transform/trace.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod tonic {
77
tonic::{Attributes, ResourceAttributesWithSchema},
88
};
99
use opentelemetry::trace;
10-
use opentelemetry::trace::{Link, SpanId, SpanKind};
10+
use opentelemetry::trace::{SpanId, SpanKind};
1111
use opentelemetry_sdk::trace::SpanData;
1212
use std::collections::HashMap;
1313

@@ -33,18 +33,6 @@ pub mod tonic {
3333
}
3434
}
3535

36-
impl From<Link> for span::Link {
37-
fn from(link: Link) -> Self {
38-
span::Link {
39-
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
40-
span_id: link.span_context.span_id().to_bytes().to_vec(),
41-
trace_state: link.span_context.trace_state().header(),
42-
attributes: Attributes::from(link.attributes).0,
43-
dropped_attributes_count: link.dropped_attributes_count,
44-
flags: link.span_context.trace_flags().to_u8() as u32,
45-
}
46-
}
47-
}
4836
impl From<opentelemetry_sdk::trace::SpanData> for Span {
4937
fn from(source_span: opentelemetry_sdk::trace::SpanData) -> Self {
5038
let span_kind: span::SpanKind = source_span.span_kind.into();
@@ -74,11 +62,22 @@ pub mod tonic {
7462
time_unix_nano: to_nanos(event.timestamp),
7563
name: event.name.into(),
7664
attributes: Attributes::from(event.attributes).0,
77-
dropped_attributes_count: event.dropped_attributes_count,
65+
dropped_attributes_count: source_span.dropped_attributes_count,
7866
})
7967
.collect(),
8068
dropped_links_count: source_span.links.dropped_count,
81-
links: source_span.links.into_iter().map(Into::into).collect(),
69+
links: source_span
70+
.links
71+
.into_iter()
72+
.map(|link| span::Link {
73+
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
74+
span_id: link.span_context.span_id().to_bytes().to_vec(),
75+
trace_state: link.span_context.trace_state().header(),
76+
attributes: Attributes::from(link.attributes).0,
77+
dropped_attributes_count: source_span.dropped_attributes_count,
78+
flags: link.span_context.trace_flags().to_u8() as u32,
79+
})
80+
.collect(),
8281
status: Some(Status {
8382
code: status::StatusCode::from(&source_span.status).into(),
8483
message: match source_span.status {
@@ -133,11 +132,22 @@ pub mod tonic {
133132
time_unix_nano: to_nanos(event.timestamp),
134133
name: event.name.into(),
135134
attributes: Attributes::from(event.attributes).0,
136-
dropped_attributes_count: event.dropped_attributes_count,
135+
dropped_attributes_count: source_span.dropped_attributes_count,
137136
})
138137
.collect(),
139138
dropped_links_count: source_span.links.dropped_count,
140-
links: source_span.links.into_iter().map(Into::into).collect(),
139+
links: source_span
140+
.links
141+
.into_iter()
142+
.map(|link| span::Link {
143+
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
144+
span_id: link.span_context.span_id().to_bytes().to_vec(),
145+
trace_state: link.span_context.trace_state().header(),
146+
attributes: Attributes::from(link.attributes).0,
147+
dropped_attributes_count: source_span.dropped_attributes_count,
148+
flags: link.span_context.trace_flags().to_u8() as u32,
149+
})
150+
.collect(),
141151
status: Some(Status {
142152
code: status::StatusCode::from(&source_span.status).into(),
143153
message: match source_span.status {

opentelemetry-proto/src/transform/tracez.rs

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#[cfg(all(feature = "gen-tonic-messages", feature = "zpages"))]
22
mod tonic {
3-
use opentelemetry::trace::{Event, Status};
3+
use opentelemetry::trace::Status;
44
use opentelemetry_sdk::trace::SpanData;
55

66
use crate::proto::tonic::{
7-
trace::v1::{span::Event as SpanEvent, Status as SpanStatus},
7+
trace::v1::{span, span::Event as SpanEvent, Status as SpanStatus},
88
tracez::v1::{ErrorData, LatencyData, RunningData},
99
};
1010
use crate::transform::common::{to_nanos, tonic::Attributes};
@@ -18,8 +18,30 @@ mod tonic {
1818
starttime: to_nanos(span_data.start_time),
1919
endtime: to_nanos(span_data.end_time),
2020
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(),
21+
events: span_data
22+
.events
23+
.events
24+
.into_iter()
25+
.map(|e| SpanEvent {
26+
time_unix_nano: to_nanos(e.timestamp),
27+
name: e.name.to_string(),
28+
attributes: Attributes::from(e.attributes).0,
29+
dropped_attributes_count: span_data.dropped_attributes_count,
30+
})
31+
.collect(),
32+
links: span_data
33+
.links
34+
.iter()
35+
.cloned()
36+
.map(|link| span::Link {
37+
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
38+
span_id: link.span_context.span_id().to_bytes().to_vec(),
39+
trace_state: link.span_context.trace_state().header(),
40+
attributes: Attributes::from(link.attributes).0,
41+
dropped_attributes_count: span_data.dropped_attributes_count,
42+
flags: link.span_context.trace_flags().to_u8() as u32,
43+
})
44+
.collect(),
2345
}
2446
}
2547
}
@@ -32,8 +54,30 @@ mod tonic {
3254
parentid: span_data.parent_span_id.to_bytes().to_vec(),
3355
starttime: to_nanos(span_data.start_time),
3456
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(),
57+
events: span_data
58+
.events
59+
.events
60+
.into_iter()
61+
.map(|e| SpanEvent {
62+
time_unix_nano: to_nanos(e.timestamp),
63+
name: e.name.to_string(),
64+
attributes: Attributes::from(e.attributes).0,
65+
dropped_attributes_count: span_data.dropped_attributes_count,
66+
})
67+
.collect(),
68+
links: span_data
69+
.links
70+
.iter()
71+
.cloned()
72+
.map(|link| span::Link {
73+
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
74+
span_id: link.span_context.span_id().to_bytes().to_vec(),
75+
trace_state: link.span_context.trace_state().header(),
76+
attributes: Attributes::from(link.attributes).0,
77+
dropped_attributes_count: span_data.dropped_attributes_count,
78+
flags: link.span_context.trace_flags().to_u8() as u32,
79+
})
80+
.collect(),
3781
status: match span_data.status {
3882
Status::Error { description } => Some(SpanStatus {
3983
message: description.to_string(),
@@ -53,19 +97,30 @@ mod tonic {
5397
parentid: span_data.parent_span_id.to_bytes().to_vec(),
5498
starttime: to_nanos(span_data.start_time),
5599
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,
100+
events: span_data
101+
.events
102+
.events
103+
.into_iter()
104+
.map(|e| SpanEvent {
105+
time_unix_nano: to_nanos(e.timestamp),
106+
name: e.name.to_string(),
107+
attributes: Attributes::from(e.attributes).0,
108+
dropped_attributes_count: span_data.dropped_attributes_count,
109+
})
110+
.collect(),
111+
links: span_data
112+
.links
113+
.iter()
114+
.cloned()
115+
.map(|link| span::Link {
116+
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
117+
span_id: link.span_context.span_id().to_bytes().to_vec(),
118+
trace_state: link.span_context.trace_state().header(),
119+
attributes: Attributes::from(link.attributes).0,
120+
dropped_attributes_count: span_data.links.dropped_count,
121+
flags: link.span_context.trace_flags().to_u8() as u32,
122+
})
123+
.collect(),
69124
}
70125
}
71126
}

opentelemetry-sdk/src/trace/span.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,10 @@ impl opentelemetry::trace::Span for Span {
101101
let event_attributes_limit = self.span_limits.max_attributes_per_event as usize;
102102
self.with_data(|data| {
103103
if data.events.len() < span_events_limit {
104-
let dropped_attributes_count =
105-
attributes.len().saturating_sub(event_attributes_limit);
106104
attributes.truncate(event_attributes_limit);
107105

108-
data.events.add_event(Event::new(
109-
name,
110-
timestamp,
111-
attributes,
112-
dropped_attributes_count as u32,
113-
));
106+
data.events
107+
.add_event(Event::new(name, timestamp, attributes));
114108
} else {
115109
data.events.dropped_count += 1;
116110
}
@@ -175,15 +169,9 @@ impl opentelemetry::trace::Span for Span {
175169
let link_attributes_limit = self.span_limits.max_attributes_per_link as usize;
176170
self.with_data(|data| {
177171
if data.links.links.len() < span_links_limit {
178-
let dropped_attributes_count =
179-
attributes.len().saturating_sub(link_attributes_limit);
180172
let mut attributes = attributes;
181173
attributes.truncate(link_attributes_limit);
182-
data.links.add_link(Link::new(
183-
span_context,
184-
attributes,
185-
dropped_attributes_count as u32,
186-
));
174+
data.links.add_link(Link::new(span_context, attributes));
187175
} else {
188176
data.links.dropped_count += 1;
189177
}

opentelemetry-sdk/src/trace/tracer.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ impl SdkTracer {
8686
links.truncate(spans_links_limit);
8787
let link_attributes_limit = span_limits.max_attributes_per_link as usize;
8888
for link in links.iter_mut() {
89-
let dropped_attributes_count =
90-
link.attributes.len().saturating_sub(link_attributes_limit);
9189
link.attributes.truncate(link_attributes_limit);
92-
link.dropped_attributes_count = dropped_attributes_count as u32;
9390
}
9491
SpanLinks {
9592
links,
@@ -116,12 +113,7 @@ impl SdkTracer {
116113
events.truncate(spans_events_limit);
117114
let event_attributes_limit = span_limits.max_attributes_per_event as usize;
118115
for event in events.iter_mut() {
119-
let dropped_attributes_count = event
120-
.attributes
121-
.len()
122-
.saturating_sub(event_attributes_limit);
123116
event.attributes.truncate(event_attributes_limit);
124-
event.dropped_attributes_count = dropped_attributes_count as u32;
125117
}
126118
SpanEvents {
127119
events,

opentelemetry/src/trace/mod.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ pub struct Event {
199199

200200
/// Attributes that describe this event.
201201
pub attributes: Vec<KeyValue>,
202-
203-
/// The number of attributes that were above the configured limit, and thus
204-
/// dropped.
205-
pub dropped_attributes_count: u32,
206202
}
207203

208204
impl Event {
@@ -211,13 +207,11 @@ impl Event {
211207
name: T,
212208
timestamp: time::SystemTime,
213209
attributes: Vec<KeyValue>,
214-
dropped_attributes_count: u32,
215210
) -> Self {
216211
Event {
217212
name: name.into(),
218213
timestamp,
219214
attributes,
220-
dropped_attributes_count,
221215
}
222216
}
223217

@@ -227,7 +221,6 @@ impl Event {
227221
name: name.into(),
228222
timestamp: crate::time::now(),
229223
attributes: Vec::new(),
230-
dropped_attributes_count: 0,
231224
}
232225
}
233226
}
@@ -243,23 +236,14 @@ pub struct Link {
243236

244237
/// Attributes that describe this link.
245238
pub attributes: Vec<KeyValue>,
246-
247-
/// The number of attributes that were above the configured limit, and thus
248-
/// dropped.
249-
pub dropped_attributes_count: u32,
250239
}
251240

252241
impl Link {
253242
/// Create new `Link`
254-
pub fn new(
255-
span_context: SpanContext,
256-
attributes: Vec<KeyValue>,
257-
dropped_attributes_count: u32,
258-
) -> Self {
243+
pub fn new(span_context: SpanContext, attributes: Vec<KeyValue>) -> Self {
259244
Link {
260245
span_context,
261246
attributes,
262-
dropped_attributes_count,
263247
}
264248
}
265249

@@ -268,7 +252,6 @@ impl Link {
268252
Link {
269253
span_context,
270254
attributes: Vec::new(),
271-
dropped_attributes_count: 0,
272255
}
273256
}
274257
}

0 commit comments

Comments
 (0)