Skip to content

Commit 4f9b012

Browse files
committed
nit: use None rather than empty string when no recording
1 parent e2edadb commit 4f9b012

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

opentelemetry-sdk/src/trace/span.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ impl ReadableSpan for FinishedSpan {
341341
self.span_data_ref().span_kind.clone()
342342
}
343343

344-
fn name(&self) -> &str {
345-
self.span_data_ref().name.as_ref()
344+
fn name(&self) -> Option<&str> {
345+
Some(&self.span.as_ref()?.name)
346346
}
347347
fn start_time(&self) -> Option<SystemTime> {
348348
Some(self.span_data_ref().start_time)
@@ -400,8 +400,8 @@ pub trait ReadableSpan {
400400

401401
/// Returns the name of the span.
402402
///
403-
/// Returns an empty string if the span is not recording.
404-
fn name(&self) -> &str;
403+
/// Returns `None` if the span is not recording.
404+
fn name(&self) -> Option<&str>;
405405

406406
/// Returns the start time of the span.
407407
///
@@ -464,11 +464,11 @@ impl ReadableSpan for Span {
464464
.unwrap_or(SpanKind::Internal)
465465
}
466466

467-
fn name(&self) -> &str {
468-
self.data
469-
.as_ref()
470-
.map(|data| data.name.as_ref())
471-
.unwrap_or("")
467+
/// Returns the name of the span.
468+
///
469+
/// Returns `None` if the span is not recording.
470+
fn name(&self) -> Option<&str> {
471+
Some(&self.data.as_ref()?.name)
472472
}
473473

474474
fn start_time(&self) -> Option<SystemTime> {
@@ -1021,7 +1021,7 @@ mod tests {
10211021
let parent_id = span.parent_span_id();
10221022
let name = span.name();
10231023

1024-
assert_eq!(name, "test_span");
1024+
assert_eq!(name, Some("test_span"));
10251025
assert_eq!(parent_id, SpanId::INVALID);
10261026
let _ = span.consume();
10271027
}

0 commit comments

Comments
 (0)