]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
20effc67 | 4 | #pragma once |
f67539c2 | 5 | |
20effc67 TL |
6 | #include "acconfig.h" |
7 | #include "include/buffer.h" | |
f67539c2 | 8 | |
20effc67 | 9 | #ifdef HAVE_JAEGER |
f67539c2 | 10 | |
20effc67 TL |
11 | #include "opentelemetry/trace/provider.h" |
12 | #include "opentelemetry/exporters/jaeger/jaeger_exporter.h" | |
13 | #include "opentelemetry/sdk/trace/simple_processor.h" | |
14 | #include "opentelemetry/sdk/trace/tracer_provider.h" | |
f67539c2 | 15 | |
20effc67 TL |
16 | using jspan = opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span>; |
17 | using jspan_context = opentelemetry::trace::SpanContext; | |
f67539c2 | 18 | |
20effc67 | 19 | namespace tracing { |
f67539c2 | 20 | |
20effc67 TL |
21 | class Tracer { |
22 | private: | |
23 | const static opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> noop_tracer; | |
24 | opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer; | |
f67539c2 | 25 | |
20effc67 TL |
26 | public: |
27 | Tracer() = default; | |
28 | Tracer(opentelemetry::nostd::string_view service_name); | |
f67539c2 | 29 | |
20effc67 TL |
30 | void init(opentelemetry::nostd::string_view service_name); |
31 | void shutdown(); | |
f67539c2 | 32 | |
20effc67 TL |
33 | bool is_enabled() const; |
34 | // creates and returns a new span with `trace_name` | |
35 | // this span represents a trace, since it has no parent. | |
36 | jspan start_trace(opentelemetry::nostd::string_view trace_name); | |
37 | // creates and returns a new span with `span_name` which parent span is `parent_span' | |
38 | jspan add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span); | |
39 | // creates and return a new span with `span_name` | |
40 | // the span is added to the trace which it's context is `parent_ctx`. | |
41 | // parent_ctx contains the required information of the trace. | |
42 | jspan add_span(opentelemetry::nostd::string_view span_name, const jspan_context& parent_ctx); | |
f67539c2 | 43 | |
20effc67 TL |
44 | }; |
45 | ||
46 | void encode(const jspan_context& span, ceph::buffer::list& bl, uint64_t f = 0); | |
47 | void decode(jspan_context& span_ctx, ceph::buffer::list::const_iterator& bl); | |
48 | ||
49 | } // namespace tracing | |
50 | ||
51 | ||
52 | #else // !HAVE_JAEGER | |
53 | ||
54 | #include <string_view> | |
55 | ||
56 | ||
57 | ||
58 | class Value { | |
59 | public: | |
60 | template <typename T> Value(T val) {} | |
61 | }; | |
62 | ||
63 | struct jspan_context { | |
64 | jspan_context() {} | |
65 | jspan_context(bool sampled_flag, bool is_remote) {} | |
66 | }; | |
67 | ||
68 | struct span_stub { | |
69 | jspan_context _ctx; | |
70 | template <typename T> | |
71 | void SetAttribute(std::string_view key, const T& value) const noexcept {} | |
72 | void AddEvent(std::string_view, std::initializer_list<std::pair<std::string_view, Value>> fields) {} | |
73 | const jspan_context& GetContext() { return _ctx; } | |
74 | void UpdateName(std::string_view) {} | |
75 | }; | |
76 | ||
77 | class jspan { | |
78 | span_stub span; | |
79 | public: | |
80 | span_stub& operator*() { return span; } | |
81 | const span_stub& operator*() const { return span; } | |
82 | ||
83 | span_stub* operator->() { return &span; } | |
84 | const span_stub* operator->() const { return &span; } | |
85 | ||
86 | operator bool() const { return false; } | |
87 | }; | |
88 | ||
89 | namespace tracing { | |
90 | ||
91 | struct Tracer { | |
92 | bool is_enabled() const { return false; } | |
93 | jspan start_trace(std::string_view) { return {}; } | |
94 | jspan add_span(std::string_view, const jspan&) { return {}; } | |
95 | jspan add_span(std::string_view span_name, const jspan_context& parent_ctx) { return {}; } | |
96 | void init(std::string_view service_name) {} | |
97 | void shutdown() {} | |
98 | }; | |
99 | inline void encode(const jspan_context& span, bufferlist& bl, uint64_t f=0) {} | |
100 | inline void decode(jspan_context& span_ctx, ceph::buffer::list::const_iterator& bl) {} | |
f67539c2 | 101 | } |
20effc67 TL |
102 | |
103 | #endif // !HAVE_JAEGER |