Skip to content

Commit 7d82c3e

Browse files
committed
Breaking changes, initial implementation for replacing clone() with refs
1 parent fa170f3 commit 7d82c3e

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

opentelemetry-sdk/src/trace/export.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,30 @@ pub trait SpanExporter: Send + Sync + Debug {
7373
/// `SpanData` contains all the information collected by a `Span` and can be used
7474
/// by exporters as a standard input.
7575
#[derive(Clone, Debug, PartialEq)]
76-
pub struct SpanData {
76+
pub struct SpanData<'a> {
7777
/// Exportable `SpanContext`
7878
pub span_context: SpanContext,
7979
/// Span parent id
8080
pub parent_span_id: SpanId,
8181
/// Span kind
82-
pub span_kind: SpanKind,
82+
pub span_kind: &'a SpanKind,
8383
/// Span name
84-
pub name: Cow<'static, str>,
84+
pub name: &'a Cow<'static, str>,
8585
/// Span start time
8686
pub start_time: SystemTime,
8787
/// Span end time
8888
pub end_time: SystemTime,
8989
/// Span attributes
90-
pub attributes: Vec<KeyValue>,
90+
pub attributes: &'a Vec<KeyValue>,
9191
/// The number of attributes that were above the configured limit, and thus
9292
/// dropped.
9393
pub dropped_attributes_count: u32,
9494
/// Span events
95-
pub events: crate::trace::SpanEvents,
95+
pub events: &'a crate::trace::SpanEvents,
9696
/// Span Links
97-
pub links: crate::trace::SpanLinks,
97+
pub links: &'a crate::trace::SpanLinks,
9898
/// Span status
99-
pub status: Status,
99+
pub status: &'a Status,
100100
/// Instrumentation scope that produced this span
101101
pub instrumentation_scope: InstrumentationScope,
102102
}

opentelemetry-sdk/src/trace/span.rs

+18-26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::time::SystemTime;
1616

1717
/// Single operation within a trace.
1818
#[derive(Debug)]
19-
pub struct Span {
19+
pub struct Span<> {
2020
span_context: SpanContext,
2121
data: Option<SpanData>,
2222
tracer: crate::trace::SdkTracer,
@@ -74,12 +74,12 @@ impl Span {
7474
/// Convert information in this span into `exporter::trace::SpanData`.
7575
/// This function copies all data from the current span, which will create a
7676
/// overhead.
77-
pub fn exported_data(&self) -> Option<crate::trace::SpanData> {
77+
pub fn exported_data<'a>(&'a mut self) -> Option<crate::trace::SpanData<'a>> {
7878
let (span_context, tracer) = (self.span_context.clone(), &self.tracer);
7979

8080
self.data
81-
.as_ref()
82-
.map(|data| build_export_data(data.clone(), span_context, tracer))
81+
.as_mut()
82+
.map(|data| build_export_data(data, span_context, tracer))
8383
}
8484
}
8585

@@ -199,7 +199,7 @@ impl opentelemetry::trace::Span for Span {
199199
impl Span {
200200
fn ensure_ended_and_exported(&mut self, timestamp: Option<SystemTime>) {
201201
// skip if data has already been exported
202-
let mut data = match self.data.take() {
202+
let data = &mut match self.data.take() {
203203
Some(data) => data,
204204
None => return,
205205
};
@@ -220,19 +220,11 @@ impl Span {
220220
match provider.span_processors() {
221221
[] => {}
222222
[processor] => {
223-
processor.on_end(build_export_data(
224-
data,
225-
self.span_context.clone(),
226-
&self.tracer,
227-
));
223+
processor.on_end();
228224
}
229225
processors => {
230226
for processor in processors {
231-
processor.on_end(build_export_data(
232-
data.clone(),
233-
self.span_context.clone(),
234-
&self.tracer,
235-
));
227+
processor.on_end();
236228
}
237229
}
238230
}
@@ -246,23 +238,23 @@ impl Drop for Span {
246238
}
247239
}
248240

249-
fn build_export_data(
250-
data: SpanData,
241+
fn build_export_data<'a>(
242+
data: &'a mut SpanData,
251243
span_context: SpanContext,
252-
tracer: &crate::trace::SdkTracer,
253-
) -> crate::trace::SpanData {
244+
tracer: &'a crate::trace::SdkTracer,
245+
) -> crate::trace::SpanData<'a> {
254246
crate::trace::SpanData {
255247
span_context,
256248
parent_span_id: data.parent_span_id,
257-
span_kind: data.span_kind,
258-
name: data.name,
249+
span_kind: &data.span_kind,
250+
name: &data.name,
259251
start_time: data.start_time,
260252
end_time: data.end_time,
261-
attributes: data.attributes,
253+
attributes: &data.attributes,
262254
dropped_attributes_count: data.dropped_attributes_count,
263-
events: data.events,
264-
links: data.links,
265-
status: data.status,
255+
events: &data.events,
256+
links: &data.links,
257+
status: &data.status,
266258
instrumentation_scope: tracer.instrumentation_scope().clone(),
267259
}
268260
}
@@ -721,7 +713,7 @@ mod tests {
721713
let res = provider.shutdown();
722714
println!("{:?}", res);
723715
assert!(res.is_ok());
724-
let dropped_span = tracer.start("span_with_dropped_provider");
716+
let mut dropped_span = tracer.start("span_with_dropped_provider");
725717
// return none if the provider has already been dropped
726718
assert!(dropped_span.exported_data().is_none());
727719
}

0 commit comments

Comments
 (0)