@@ -16,7 +16,7 @@ use std::time::SystemTime;
16
16
17
17
/// Single operation within a trace.
18
18
#[ derive( Debug ) ]
19
- pub struct Span {
19
+ pub struct Span <> {
20
20
span_context : SpanContext ,
21
21
data : Option < SpanData > ,
22
22
tracer : crate :: trace:: SdkTracer ,
@@ -74,12 +74,12 @@ impl Span {
74
74
/// Convert information in this span into `exporter::trace::SpanData`.
75
75
/// This function copies all data from the current span, which will create a
76
76
/// 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 > > {
78
78
let ( span_context, tracer) = ( self . span_context . clone ( ) , & self . tracer ) ;
79
79
80
80
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) )
83
83
}
84
84
}
85
85
@@ -199,7 +199,7 @@ impl opentelemetry::trace::Span for Span {
199
199
impl Span {
200
200
fn ensure_ended_and_exported ( & mut self , timestamp : Option < SystemTime > ) {
201
201
// skip if data has already been exported
202
- let mut data = match self . data . take ( ) {
202
+ let data = & mut match self . data . take ( ) {
203
203
Some ( data) => data,
204
204
None => return ,
205
205
} ;
@@ -220,19 +220,11 @@ impl Span {
220
220
match provider. span_processors ( ) {
221
221
[ ] => { }
222
222
[ processor] => {
223
- processor. on_end ( build_export_data (
224
- data,
225
- self . span_context . clone ( ) ,
226
- & self . tracer ,
227
- ) ) ;
223
+ processor. on_end ( ) ;
228
224
}
229
225
processors => {
230
226
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 ( ) ;
236
228
}
237
229
}
238
230
}
@@ -246,23 +238,23 @@ impl Drop for Span {
246
238
}
247
239
}
248
240
249
- fn build_export_data (
250
- data : SpanData ,
241
+ fn build_export_data < ' a > (
242
+ data : & ' a mut SpanData ,
251
243
span_context : SpanContext ,
252
- tracer : & crate :: trace:: SdkTracer ,
253
- ) -> crate :: trace:: SpanData {
244
+ tracer : & ' a crate :: trace:: SdkTracer ,
245
+ ) -> crate :: trace:: SpanData < ' a > {
254
246
crate :: trace:: SpanData {
255
247
span_context,
256
248
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 ,
259
251
start_time : data. start_time ,
260
252
end_time : data. end_time ,
261
- attributes : data. attributes ,
253
+ attributes : & data. attributes ,
262
254
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 ,
266
258
instrumentation_scope : tracer. instrumentation_scope ( ) . clone ( ) ,
267
259
}
268
260
}
@@ -721,7 +713,7 @@ mod tests {
721
713
let res = provider. shutdown ( ) ;
722
714
println ! ( "{:?}" , res) ;
723
715
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" ) ;
725
717
// return none if the provider has already been dropped
726
718
assert ! ( dropped_span. exported_data( ) . is_none( ) ) ;
727
719
}
0 commit comments