]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/api/include/opentelemetry/plugin/tracer.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / api / include / opentelemetry / plugin / tracer.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5
6 #include <memory>
7
8 #include "opentelemetry/common/key_value_iterable.h"
9 #include "opentelemetry/plugin/detail/dynamic_library_handle.h"
10 #include "opentelemetry/plugin/detail/tracer_handle.h"
11 #include "opentelemetry/trace/tracer.h"
12 #include "opentelemetry/version.h"
13
14 OPENTELEMETRY_BEGIN_NAMESPACE
15 namespace plugin
16 {
17 class Span final : public trace::Span
18 {
19 public:
20 Span(std::shared_ptr<trace::Tracer> &&tracer, nostd::shared_ptr<trace::Span> span) noexcept
21 : tracer_{std::move(tracer)}, span_{span}
22 {}
23
24 // trace::Span
25 void SetAttribute(nostd::string_view name, const common::AttributeValue &value) noexcept override
26 {
27 span_->SetAttribute(name, value);
28 }
29
30 void AddEvent(nostd::string_view name) noexcept override { span_->AddEvent(name); }
31
32 void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept override
33 {
34 span_->AddEvent(name, timestamp);
35 }
36
37 void AddEvent(nostd::string_view name,
38 common::SystemTimestamp timestamp,
39 const common::KeyValueIterable &attributes) noexcept override
40 {
41 span_->AddEvent(name, timestamp, attributes);
42 }
43
44 void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override
45 {
46 span_->SetStatus(code, description);
47 }
48
49 void UpdateName(nostd::string_view name) noexcept override { span_->UpdateName(name); }
50
51 void End(const trace::EndSpanOptions &options = {}) noexcept override { span_->End(options); }
52
53 bool IsRecording() const noexcept override { return span_->IsRecording(); }
54
55 trace::SpanContext GetContext() const noexcept override { return span_->GetContext(); }
56
57 private:
58 std::shared_ptr<trace::Tracer> tracer_;
59 nostd::shared_ptr<trace::Span> span_;
60 };
61
62 class Tracer final : public trace::Tracer, public std::enable_shared_from_this<Tracer>
63 {
64 public:
65 Tracer(std::shared_ptr<DynamicLibraryHandle> library_handle,
66 std::unique_ptr<TracerHandle> &&tracer_handle) noexcept
67 : library_handle_{std::move(library_handle)}, tracer_handle_{std::move(tracer_handle)}
68 {}
69
70 // trace::Tracer
71 nostd::shared_ptr<trace::Span> StartSpan(
72 nostd::string_view name,
73 const common::KeyValueIterable &attributes,
74 const trace::SpanContextKeyValueIterable &links,
75 const trace::StartSpanOptions &options = {}) noexcept override
76 {
77 auto span = tracer_handle_->tracer().StartSpan(name, attributes, links, options);
78 if (span == nullptr)
79 {
80 return nostd::shared_ptr<trace::Span>(nullptr);
81 }
82 return nostd::shared_ptr<trace::Span>{new (std::nothrow) Span{this->shared_from_this(), span}};
83 }
84
85 void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override
86 {
87 tracer_handle_->tracer().ForceFlushWithMicroseconds(timeout);
88 }
89
90 void CloseWithMicroseconds(uint64_t timeout) noexcept override
91 {
92 tracer_handle_->tracer().CloseWithMicroseconds(timeout);
93 }
94
95 private:
96 // Note: The order is important here.
97 //
98 // It's undefined behavior to close the library while a loaded tracer is still active.
99 std::shared_ptr<DynamicLibraryHandle> library_handle_;
100 std::unique_ptr<TracerHandle> tracer_handle_;
101 };
102 } // namespace plugin
103 OPENTELEMETRY_END_NAMESPACE