Skip to content

Commit 2dd7ccf

Browse files
committed
nit: add comment explaining why we grab the data from the span mutably
1 parent 86fd3da commit 2dd7ccf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

opentelemetry-sdk/src/trace/span.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,9 @@ impl Span {
223223
..
224224
} = self;
225225

226-
// skip if data has already been exported
227-
let data = match data.take() {
228-
Some(data) => data,
229-
None => return,
230-
};
226+
// Grab the span data from the span and leave it empty
227+
// This way we don't have to clone the data
228+
let Some(data) = data.take() else { return };
231229
let span_context: SpanContext =
232230
std::mem::replace(span_context, SpanContext::empty_context());
233231

@@ -245,6 +243,7 @@ impl Drop for Span {
245243
/// Report span on inner drop
246244
fn drop(&mut self) {
247245
if let Some(ref mut data) = self.data {
246+
// if the span has not been ended, set the end time to now
248247
if data.end_time == data.start_time {
249248
data.end_time = opentelemetry::time::now();
250249
}
@@ -1152,6 +1151,7 @@ mod tests {
11521151
}
11531152

11541153
let provider = crate::trace::SdkTracerProvider::builder()
1154+
.with_span_processor(TestSpanProcessor)
11551155
.with_span_processor(TestSpanProcessor)
11561156
.build();
11571157
drop(make_test_span(

0 commit comments

Comments
 (0)