-
Notifications
You must be signed in to change notification settings - Fork 417
/
tracer.cc
69 lines (60 loc) · 2.13 KB
/
tracer.cc
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "opentelemetry/sdk/trace/tracer.h"
#include "opentelemetry/context/runtime_context.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/common/atomic_shared_ptr.h"
#include "opentelemetry/version.h"
#include "src/trace/span.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
Tracer::Tracer(std::shared_ptr<sdk::trace::TracerContext> context,
std::unique_ptr<InstrumentationLibrary> instrumentation_library) noexcept
: context_{context}, instrumentation_library_{std::move(instrumentation_library)}
{}
nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(
nostd::string_view name,
const opentelemetry::common::KeyValueIterable &attributes,
const trace_api::SpanContextKeyValueIterable &links,
const trace_api::StartSpanOptions &options) noexcept
{
trace_api::SpanContext parent =
options.parent.IsValid() ? options.parent : GetCurrentSpan()->GetContext();
auto sampling_result = context_->GetSampler().ShouldSample(parent, parent.trace_id(), name,
options.kind, attributes, links);
if (sampling_result.decision == Decision::DROP)
{
// Don't allocate a no-op span for every DROP decision, but use a static
// singleton for this case.
static nostd::shared_ptr<trace_api::Span> noop_span(
new trace_api::NoopSpan{this->shared_from_this()});
return noop_span;
}
else
{
auto span = nostd::shared_ptr<trace_api::Span>{
new (std::nothrow) Span{this->shared_from_this(), name, attributes, links, options, parent,
sampling_result.trace_state, true}};
// if the attributes is not nullptr, add attributes to the span.
if (sampling_result.attributes)
{
for (auto &kv : *sampling_result.attributes)
{
span->SetAttribute(kv.first, kv.second);
}
}
return span;
}
}
void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept
{
(void)timeout;
}
void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept
{
(void)timeout;
}
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE