Skip to content

Commit

Permalink
Make GetSpan return a statically allocated invalid span
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvanstraten committed Oct 7, 2024
1 parent b890969 commit 61bea77
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/include/opentelemetry/trace/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ inline nostd::shared_ptr<Span> GetSpan(const context::Context &context) noexcept
{
return nostd::get<nostd::shared_ptr<Span>>(span);
}
return nostd::shared_ptr<Span>(new DefaultSpan(SpanContext::GetInvalid()));

static thread_local nostd::shared_ptr<Span> invalid_span =
nostd::shared_ptr<Span>(new DefaultSpan(SpanContext::GetInvalid()));
return invalid_span;
}

inline bool IsRootSpan(const context::Context &context) noexcept
Expand Down

0 comments on commit 61bea77

Please sign in to comment.