Skip to content

Commit

Permalink
resolving Null issue of span
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianlin-Zhao committed Aug 20, 2020
1 parent 017e470 commit 9bb3984
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions api/include/opentelemetry/trace/propagation/http_trace_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ class HttpTraceContext : public HTTPTextFormat<T>

void Inject(Setter setter, T &carrier, const context::Context &context) noexcept override
{
SpanContext span_context = GetCurrentSpan(context)->GetContext();
if (!span_context.IsValid())
{
return;
}
SpanContext span_context = SpanContext();
GetCurrentSpan(context, span_context) if (!span_context.IsValid()) { return; }
InjectImpl(setter, carrier, span_context);
}

Expand All @@ -81,12 +78,16 @@ class HttpTraceContext : public HTTPTextFormat<T>
return context.SetValue(span_key, sp);
}

static Span *GetCurrentSpan(const context::Context &context)
static void GetCurrentSpan(const context::Context &context, SpanContext &span_context)
{
const nostd::string_view span_key = "current-span";
context::Context ctx(context);
nostd::shared_ptr<Span> span = nostd::get<nostd::shared_ptr<Span>>(ctx.GetValue(span_key));
return (span.get());
context::ContextValue span = ctx.GetValue(span_key);
if ((int)span == 0)
{
return;
}
span_context = ((Span)span).GetContext();
}

static TraceId GenerateTraceIdFromString(nostd::string_view trace_id)
Expand Down

0 comments on commit 9bb3984

Please sign in to comment.