]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/sdk/include/opentelemetry/sdk/trace/tracer_context.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / sdk / include / opentelemetry / sdk / trace / tracer_context.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5
6 #include "opentelemetry/sdk/common/atomic_unique_ptr.h"
7 #include "opentelemetry/sdk/resource/resource.h"
8 #include "opentelemetry/sdk/trace/processor.h"
9 #include "opentelemetry/sdk/trace/random_id_generator.h"
10 #include "opentelemetry/sdk/trace/samplers/always_on.h"
11 #include "opentelemetry/version.h"
12
13 OPENTELEMETRY_BEGIN_NAMESPACE
14 namespace sdk
15 {
16 namespace trace
17 {
18
19 /**
20 * A class which stores the TracerProvider context.
21 *
22 * This class meets the following design criteria:
23 * - A shared reference between TracerProvider and Tracers instantiated.
24 * - A thread-safe class that allows updating/altering processor/exporter pipelines
25 * and sampling config.
26 * - The owner/destroyer of Processors/Exporters. These will remain active until
27 * this class is destroyed. I.e. Sampling, Exporting, flushing, Custom Iterator etc. are all ok
28 * if this object is alive, and they will work together. If this object is destroyed, then no shared
29 * references to Processor, Exporter, Recordable, Custom Iterator etc. should exist, and all
30 * associated pipelines will have been flushed.
31 */
32 class TracerContext
33 {
34 public:
35 explicit TracerContext(
36 std::vector<std::unique_ptr<SpanProcessor>> &&processor,
37 opentelemetry::sdk::resource::Resource resource =
38 opentelemetry::sdk::resource::Resource::Create({}),
39 std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
40 std::unique_ptr<IdGenerator> id_generator =
41 std::unique_ptr<IdGenerator>(new RandomIdGenerator())) noexcept;
42
43 /**
44 * Attaches a span processor to list of configured processors to this tracer context.
45 * Processor once attached can't be removed.
46 * @param processor The new span processor for this tracer. This must not be
47 * a nullptr. Ownership is given to the `TracerContext`.
48 *
49 * Note: This method is not thread safe.
50 */
51 void AddProcessor(std::unique_ptr<SpanProcessor> processor) noexcept;
52
53 /**
54 * Obtain the sampler associated with this tracer.
55 * @return The sampler for this tracer.
56 */
57 Sampler &GetSampler() const noexcept;
58
59 /**
60 * Obtain the configured (composite) processor.
61 *
62 * Note: When more than one processor is active, this will
63 * return an "aggregate" processor
64 */
65 SpanProcessor &GetProcessor() const noexcept;
66
67 /**
68 * Obtain the resource associated with this tracer context.
69 * @return The resource for this tracer context.
70 */
71 const opentelemetry::sdk::resource::Resource &GetResource() const noexcept;
72
73 /**
74 * Obtain the Id Generator associated with this tracer context.
75 * @return The ID Generator for this tracer context.
76 */
77 opentelemetry::sdk::trace::IdGenerator &GetIdGenerator() const noexcept;
78
79 /**
80 * Force all active SpanProcessors to flush any buffered spans
81 * within the given timeout.
82 */
83 bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;
84
85 /**
86 * Shutdown the span processor associated with this tracer provider.
87 */
88 bool Shutdown() noexcept;
89
90 private:
91 // order of declaration is important here - resource object should be destroyed after processor.
92 opentelemetry::sdk::resource::Resource resource_;
93 std::unique_ptr<Sampler> sampler_;
94 std::unique_ptr<IdGenerator> id_generator_;
95 std::unique_ptr<SpanProcessor> processor_;
96 };
97
98 } // namespace trace
99 } // namespace sdk
100 OPENTELEMETRY_END_NAMESPACE