Skip to content

refactor: remove dropped_attribute_counts from API #3005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions opentelemetry-proto/src/transform/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tonic::{Attributes, ResourceAttributesWithSchema},
};
use opentelemetry::trace;
use opentelemetry::trace::{Link, SpanId, SpanKind};
use opentelemetry::trace::{SpanId, SpanKind};
use opentelemetry_sdk::trace::SpanData;
use std::collections::HashMap;

Expand All @@ -33,18 +33,6 @@
}
}

impl From<Link> for span::Link {
fn from(link: Link) -> Self {
span::Link {
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
span_id: link.span_context.span_id().to_bytes().to_vec(),
trace_state: link.span_context.trace_state().header(),
attributes: Attributes::from(link.attributes).0,
dropped_attributes_count: link.dropped_attributes_count,
flags: link.span_context.trace_flags().to_u8() as u32,
}
}
}
impl From<opentelemetry_sdk::trace::SpanData> for Span {
fn from(source_span: opentelemetry_sdk::trace::SpanData) -> Self {
let span_kind: span::SpanKind = source_span.span_kind.into();
Expand Down Expand Up @@ -74,11 +62,22 @@
time_unix_nano: to_nanos(event.timestamp),
name: event.name.into(),
attributes: Attributes::from(event.attributes).0,
dropped_attributes_count: event.dropped_attributes_count,
dropped_attributes_count: source_span.dropped_attributes_count,

Check warning on line 65 in opentelemetry-proto/src/transform/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/trace.rs#L65

Added line #L65 was not covered by tests
})
.collect(),
dropped_links_count: source_span.links.dropped_count,
links: source_span.links.into_iter().map(Into::into).collect(),
links: source_span
.links
.into_iter()
.map(|link| span::Link {
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
span_id: link.span_context.span_id().to_bytes().to_vec(),
trace_state: link.span_context.trace_state().header(),
attributes: Attributes::from(link.attributes).0,
dropped_attributes_count: source_span.dropped_attributes_count,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really correct? The dropped_attributes_count on the source span is for the span, and not this link, right?

flags: link.span_context.trace_flags().to_u8() as u32,

Check warning on line 78 in opentelemetry-proto/src/transform/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/trace.rs#L73-L78

Added lines #L73 - L78 were not covered by tests
})
.collect(),
status: Some(Status {
code: status::StatusCode::from(&source_span.status).into(),
message: match source_span.status {
Expand Down Expand Up @@ -133,11 +132,22 @@
time_unix_nano: to_nanos(event.timestamp),
name: event.name.into(),
attributes: Attributes::from(event.attributes).0,
dropped_attributes_count: event.dropped_attributes_count,
dropped_attributes_count: source_span.dropped_attributes_count,

Check warning on line 135 in opentelemetry-proto/src/transform/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/trace.rs#L135

Added line #L135 was not covered by tests
})
.collect(),
dropped_links_count: source_span.links.dropped_count,
links: source_span.links.into_iter().map(Into::into).collect(),
links: source_span
.links
.into_iter()
.map(|link| span::Link {
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
span_id: link.span_context.span_id().to_bytes().to_vec(),
trace_state: link.span_context.trace_state().header(),
attributes: Attributes::from(link.attributes).0,
dropped_attributes_count: source_span.dropped_attributes_count,
flags: link.span_context.trace_flags().to_u8() as u32,
})
.collect(),

Check warning on line 150 in opentelemetry-proto/src/transform/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/trace.rs#L139-L150

Added lines #L139 - L150 were not covered by tests
status: Some(Status {
code: status::StatusCode::from(&source_span.status).into(),
message: match source_span.status {
Expand Down
93 changes: 74 additions & 19 deletions opentelemetry-proto/src/transform/tracez.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[cfg(all(feature = "gen-tonic-messages", feature = "zpages"))]
mod tonic {
use opentelemetry::trace::{Event, Status};
use opentelemetry::trace::Status;
use opentelemetry_sdk::trace::SpanData;

use crate::proto::tonic::{
trace::v1::{span::Event as SpanEvent, Status as SpanStatus},
trace::v1::{span, span::Event as SpanEvent, Status as SpanStatus},
tracez::v1::{ErrorData, LatencyData, RunningData},
};
use crate::transform::common::{to_nanos, tonic::Attributes};
Expand All @@ -18,8 +18,30 @@
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.links.iter().cloned().map(Into::into).collect(),
events: span_data
.events
.events
.into_iter()
.map(|e| SpanEvent {
time_unix_nano: to_nanos(e.timestamp),
name: e.name.to_string(),
attributes: Attributes::from(e.attributes).0,
dropped_attributes_count: span_data.dropped_attributes_count,
})
.collect(),
links: span_data
.links
.iter()
.cloned()
.map(|link| span::Link {
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
span_id: link.span_context.span_id().to_bytes().to_vec(),
trace_state: link.span_context.trace_state().header(),
attributes: Attributes::from(link.attributes).0,
dropped_attributes_count: span_data.dropped_attributes_count,
flags: link.span_context.trace_flags().to_u8() as u32,
})
.collect(),

Check warning on line 44 in opentelemetry-proto/src/transform/tracez.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/tracez.rs#L21-L44

Added lines #L21 - L44 were not covered by tests
}
}
}
Expand All @@ -32,8 +54,30 @@
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.links.iter().cloned().map(Into::into).collect(),
events: span_data
.events
.events
.into_iter()
.map(|e| SpanEvent {
time_unix_nano: to_nanos(e.timestamp),
name: e.name.to_string(),
attributes: Attributes::from(e.attributes).0,
dropped_attributes_count: span_data.dropped_attributes_count,
})
.collect(),
links: span_data
.links
.iter()
.cloned()
.map(|link| span::Link {
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
span_id: link.span_context.span_id().to_bytes().to_vec(),
trace_state: link.span_context.trace_state().header(),
attributes: Attributes::from(link.attributes).0,
dropped_attributes_count: span_data.dropped_attributes_count,
flags: link.span_context.trace_flags().to_u8() as u32,
})
.collect(),

Check warning on line 80 in opentelemetry-proto/src/transform/tracez.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/tracez.rs#L57-L80

Added lines #L57 - L80 were not covered by tests
status: match span_data.status {
Status::Error { description } => Some(SpanStatus {
message: description.to_string(),
Expand All @@ -53,19 +97,30 @@
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.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,
events: span_data
.events
.events
.into_iter()
.map(|e| SpanEvent {
time_unix_nano: to_nanos(e.timestamp),
name: e.name.to_string(),
attributes: Attributes::from(e.attributes).0,
dropped_attributes_count: span_data.dropped_attributes_count,
})
.collect(),
links: span_data
.links
.iter()
.cloned()
.map(|link| span::Link {
trace_id: link.span_context.trace_id().to_bytes().to_vec(),
span_id: link.span_context.span_id().to_bytes().to_vec(),
trace_state: link.span_context.trace_state().header(),
attributes: Attributes::from(link.attributes).0,
dropped_attributes_count: span_data.links.dropped_count,
flags: link.span_context.trace_flags().to_u8() as u32,
})
.collect(),

Check warning on line 123 in opentelemetry-proto/src/transform/tracez.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-proto/src/transform/tracez.rs#L100-L123

Added lines #L100 - L123 were not covered by tests
}
}
}
Expand Down
18 changes: 3 additions & 15 deletions opentelemetry-sdk/src/trace/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,10 @@ impl opentelemetry::trace::Span for Span {
let event_attributes_limit = self.span_limits.max_attributes_per_event as usize;
self.with_data(|data| {
if data.events.len() < span_events_limit {
let dropped_attributes_count =
attributes.len().saturating_sub(event_attributes_limit);
attributes.truncate(event_attributes_limit);

data.events.add_event(Event::new(
name,
timestamp,
attributes,
dropped_attributes_count as u32,
));
data.events
.add_event(Event::new(name, timestamp, attributes));
} else {
data.events.dropped_count += 1;
}
Expand Down Expand Up @@ -175,15 +169,9 @@ impl opentelemetry::trace::Span for Span {
let link_attributes_limit = self.span_limits.max_attributes_per_link as usize;
self.with_data(|data| {
if data.links.links.len() < span_links_limit {
let dropped_attributes_count =
attributes.len().saturating_sub(link_attributes_limit);
let mut attributes = attributes;
attributes.truncate(link_attributes_limit);
data.links.add_link(Link::new(
span_context,
attributes,
dropped_attributes_count as u32,
));
data.links.add_link(Link::new(span_context, attributes));
} else {
data.links.dropped_count += 1;
}
Expand Down
8 changes: 0 additions & 8 deletions opentelemetry-sdk/src/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ impl SdkTracer {
links.truncate(spans_links_limit);
let link_attributes_limit = span_limits.max_attributes_per_link as usize;
for link in links.iter_mut() {
let dropped_attributes_count =
link.attributes.len().saturating_sub(link_attributes_limit);
link.attributes.truncate(link_attributes_limit);
link.dropped_attributes_count = dropped_attributes_count as u32;
}
SpanLinks {
links,
Expand All @@ -116,12 +113,7 @@ impl SdkTracer {
events.truncate(spans_events_limit);
let event_attributes_limit = span_limits.max_attributes_per_event as usize;
for event in events.iter_mut() {
let dropped_attributes_count = event
.attributes
.len()
.saturating_sub(event_attributes_limit);
event.attributes.truncate(event_attributes_limit);
event.dropped_attributes_count = dropped_attributes_count as u32;
}
SpanEvents {
events,
Expand Down
19 changes: 1 addition & 18 deletions opentelemetry/src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ pub struct Event {

/// Attributes that describe this event.
pub attributes: Vec<KeyValue>,

/// The number of attributes that were above the configured limit, and thus
/// dropped.
pub dropped_attributes_count: u32,
}

impl Event {
Expand All @@ -211,13 +207,11 @@ impl Event {
name: T,
timestamp: time::SystemTime,
attributes: Vec<KeyValue>,
dropped_attributes_count: u32,
) -> Self {
Event {
name: name.into(),
timestamp,
attributes,
dropped_attributes_count,
}
}

Expand All @@ -227,7 +221,6 @@ impl Event {
name: name.into(),
timestamp: crate::time::now(),
attributes: Vec::new(),
dropped_attributes_count: 0,
}
}
}
Expand All @@ -243,23 +236,14 @@ pub struct Link {

/// Attributes that describe this link.
pub attributes: Vec<KeyValue>,

/// The number of attributes that were above the configured limit, and thus
/// dropped.
pub dropped_attributes_count: u32,
}

impl Link {
/// Create new `Link`
pub fn new(
span_context: SpanContext,
attributes: Vec<KeyValue>,
dropped_attributes_count: u32,
) -> Self {
pub fn new(span_context: SpanContext, attributes: Vec<KeyValue>) -> Self {
Link {
span_context,
attributes,
dropped_attributes_count,
}
}

Expand All @@ -268,7 +252,6 @@ impl Link {
Link {
span_context,
attributes: Vec::new(),
dropped_attributes_count: 0,
}
}
}
Loading