-
Notifications
You must be signed in to change notification settings - Fork 417
/
tracer_provider.h
102 lines (90 loc) · 3.76 KB
/
tracer_provider.h
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
94
95
96
97
98
99
100
101
102
#pragma once
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/samplers/always_on.h"
#include "opentelemetry/sdk/trace/tracer.h"
#include "opentelemetry/sdk/trace/tracer_context.h"
#include "opentelemetry/trace/tracer_provider.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
class TracerProvider final : public opentelemetry::trace::TracerProvider
{
public:
/**
* Initialize a new tracer provider with a specified sampler
* @param processor The span processor for this tracer provider. This must
* not be a nullptr.
* @param resource The resources for this tracer provider.
* @param sampler The sampler for this tracer provider. This must
* not be a nullptr.
* @param id_generator The custom id generator for this tracer provider. This must
* not be a nullptr
*/
explicit TracerProvider(
std::unique_ptr<SpanProcessor> processor,
opentelemetry::sdk::resource::Resource resource =
opentelemetry::sdk::resource::Resource::Create({}),
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<opentelemetry::sdk::trace::IdGenerator> id_generator =
std::unique_ptr<opentelemetry::sdk::trace::IdGenerator>(
new RandomIdGenerator())) noexcept;
explicit TracerProvider(
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
opentelemetry::sdk::resource::Resource resource =
opentelemetry::sdk::resource::Resource::Create({}),
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<opentelemetry::sdk::trace::IdGenerator> id_generator =
std::unique_ptr<opentelemetry::sdk::trace::IdGenerator>(
new RandomIdGenerator())) noexcept;
/**
* Initialize a new tracer provider with a specified context
* @param context The shared tracer configuration/pipeline for this provider.
*/
explicit TracerProvider(std::shared_ptr<sdk::trace::TracerContext> context) noexcept;
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer(
nostd::string_view library_name,
nostd::string_view library_version = "") noexcept override;
/**
* Attaches a span processor to list of configured processors for this tracer provider.
* @param processor The new span processor for this tracer provider. This
* must not be a nullptr.
*
* Note: This process may not receive any in-flight spans, but will get newly created spans.
* Note: This method is not thread safe, and should ideally be called from main thread.
*/
void AddProcessor(std::unique_ptr<SpanProcessor> processor) noexcept;
/**
* Obtain the resource associated with this tracer provider.
* @return The resource for this tracer provider.
*/
const opentelemetry::sdk::resource::Resource &GetResource() const noexcept;
/**
* Obtain the span processor associated with this tracer provider.
* @return The span processor for this tracer provider.
*/
std::shared_ptr<SpanProcessor> GetProcessor() const noexcept;
/**
* Shutdown the span processor associated with this tracer provider.
*/
bool Shutdown() noexcept;
/**
* Force flush the span processor associated with this tracer provider.
*/
bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;
private:
std::shared_ptr<sdk::trace::TracerContext> context_;
std::vector<std::shared_ptr<opentelemetry::sdk::trace::Tracer>> tracers_;
std::mutex lock_;
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE