blob: 963c18717748cdb453890a64ecce5664eb0d5c00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/context/context.h"
#include "opentelemetry/trace/default_span.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
// Get Span from explicit context
inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &context) noexcept
{
context::ContextValue span = context.GetValue(kSpanKey);
if (nostd::holds_alternative<nostd::shared_ptr<Span>>(span))
{
return nostd::get<nostd::shared_ptr<Span>>(span);
}
return nostd::shared_ptr<Span>(new DefaultSpan(SpanContext::GetInvalid()));
}
// Set Span into explicit context
inline context::Context SetSpan(opentelemetry::context::Context &context,
nostd::shared_ptr<Span> span) noexcept
{
return context.SetValue(kSpanKey, span);
}
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
|