-
Notifications
You must be signed in to change notification settings - Fork 423
/
tracer_provider.cc
93 lines (79 loc) · 2.97 KB
/
tracer_provider.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/sdk_config.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
namespace resource = opentelemetry::sdk::resource;
namespace trace_api = opentelemetry::trace;
TracerProvider::TracerProvider(std::shared_ptr<sdk::trace::TracerContext> context) noexcept
: context_{context}
{}
TracerProvider::TracerProvider(std::unique_ptr<SpanProcessor> processor,
resource::Resource resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator) noexcept
{
std::vector<std::unique_ptr<SpanProcessor>> processors;
processors.push_back(std::move(processor));
context_ = std::make_shared<TracerContext>(std::move(processors), resource, std::move(sampler),
std::move(id_generator));
}
TracerProvider::TracerProvider(std::vector<std::unique_ptr<SpanProcessor>> &&processors,
resource::Resource resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator) noexcept
{
context_ = std::make_shared<TracerContext>(std::move(processors), resource, std::move(sampler),
std::move(id_generator));
}
nostd::shared_ptr<trace_api::Tracer> TracerProvider::GetTracer(
nostd::string_view library_name,
nostd::string_view library_version,
nostd::string_view schema_url) noexcept
{
if (library_name.data() == nullptr)
{
OTEL_INTERNAL_LOG_ERROR("[TracerProvider::GetTracer] Library name is null.");
library_name = "";
}
else if (library_name == "")
{
OTEL_INTERNAL_LOG_ERROR("[TracerProvider::GetTracer] Library name is empty.");
}
const std::lock_guard<std::mutex> guard(lock_);
for (auto &tracer : tracers_)
{
auto &tracer_lib = tracer->GetInstrumentationLibrary();
if (tracer_lib.equal(library_name, library_version, schema_url))
{
return nostd::shared_ptr<trace_api::Tracer>{tracer};
}
}
auto lib = InstrumentationLibrary::Create(library_name, library_version, schema_url);
tracers_.push_back(std::shared_ptr<opentelemetry::sdk::trace::Tracer>(
new sdk::trace::Tracer(context_, std::move(lib))));
return nostd::shared_ptr<trace_api::Tracer>{tracers_.back()};
}
void TracerProvider::AddProcessor(std::unique_ptr<SpanProcessor> processor) noexcept
{
context_->AddProcessor(std::move(processor));
}
const resource::Resource &TracerProvider::GetResource() const noexcept
{
return context_->GetResource();
}
bool TracerProvider::Shutdown() noexcept
{
return context_->Shutdown();
}
bool TracerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept
{
return context_->ForceFlush(timeout);
}
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE