Skip to content

Commit 61bea77

Browse files
Make GetSpan return a statically allocated invalid span
1 parent b890969 commit 61bea77

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

api/include/opentelemetry/trace/context.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ inline nostd::shared_ptr<Span> GetSpan(const context::Context &context) noexcept
2020
{
2121
return nostd::get<nostd::shared_ptr<Span>>(span);
2222
}
23-
return nostd::shared_ptr<Span>(new DefaultSpan(SpanContext::GetInvalid()));
23+
24+
static thread_local nostd::shared_ptr<Span> invalid_span =
25+
nostd::shared_ptr<Span>(new DefaultSpan(SpanContext::GetInvalid()));
26+
return invalid_span;
2427
}
2528

2629
inline bool IsRootSpan(const context::Context &context) noexcept

0 commit comments

Comments
 (0)