summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/opentelemetry-cpp/api/include/opentelemetry/metrics/noop.h
blob: c47f7489f0e4ddb9e0c090c0152a6f4f4735d66d (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifndef ENABLE_METRICS_PREVIEW

#  include "opentelemetry/metrics/async_instruments.h"
#  include "opentelemetry/metrics/meter.h"
#  include "opentelemetry/metrics/meter_provider.h"
#  include "opentelemetry/metrics/observer_result.h"
#  include "opentelemetry/metrics/sync_instruments.h"
#  include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
{

template <class T>
class NoopCounter : public Counter<T>
{
public:
  NoopCounter(nostd::string_view name,
              nostd::string_view description,
              nostd::string_view unit) noexcept
  {}
  void Add(T value) noexcept override {}
  void Add(T value, const opentelemetry::context::Context &context) noexcept override {}
  void Add(T value, const common::KeyValueIterable &attributes) noexcept override {}
  void Add(T value,
           const common::KeyValueIterable &attributes,
           const opentelemetry::context::Context &context) noexcept override
  {}
};

template <class T>
class NoopHistogram : public Histogram<T>
{
public:
  NoopHistogram(nostd::string_view name,
                nostd::string_view description,
                nostd::string_view unit) noexcept
  {}
  void Record(T value, const opentelemetry::context::Context &context) noexcept override {}
  void Record(T value,
              const common::KeyValueIterable &attributes,
              const opentelemetry::context::Context &context) noexcept override
  {}
};

template <class T>
class NoopUpDownCounter : public UpDownCounter<T>
{
public:
  NoopUpDownCounter(nostd::string_view name,
                    nostd::string_view description,
                    nostd::string_view unit) noexcept
  {}
  void Add(T value) noexcept override {}
  void Add(T value, const opentelemetry::context::Context &context) noexcept override {}
  void Add(T value, const common::KeyValueIterable &attributes) noexcept override {}
  void Add(T value,
           const common::KeyValueIterable &attributes,
           const opentelemetry::context::Context &context) noexcept override
  {}
};

template <class T>
class NoopObservableCounter : public ObservableCounter<T>
{
public:
  NoopObservableCounter(nostd::string_view name,
                        void (*callback)(ObserverResult<T> &),
                        nostd::string_view description,
                        nostd::string_view unit) noexcept
  {}

  NoopObservableCounter(nostd::string_view name,
                        void (*callback)(ObserverResult<T> &, const common::KeyValueIterable &),
                        nostd::string_view description,
                        nostd::string_view unit) noexcept
  {}
};

template <class T>
class NoopObservableGauge : public ObservableGauge<T>
{
public:
  NoopObservableGauge(nostd::string_view name,
                      void (*callback)(ObserverResult<T> &),
                      nostd::string_view description,
                      nostd::string_view unit) noexcept
  {}

  NoopObservableGauge(nostd::string_view name,
                      void (*callback)(ObserverResult<T> &, const common::KeyValueIterable &),
                      nostd::string_view description,
                      nostd::string_view unit) noexcept
  {}
};

template <class T>
class NoopObservableUpDownCounter : public ObservableUpDownCounter<T>
{
public:
  NoopObservableUpDownCounter(nostd::string_view name,
                              void (*callback)(ObserverResult<T> &),
                              nostd::string_view description,
                              nostd::string_view unit) noexcept
  {}

  NoopObservableUpDownCounter(nostd::string_view name,
                              void (*callback)(ObserverResult<T> &,
                                               const common::KeyValueIterable &),
                              nostd::string_view description,
                              nostd::string_view unit) noexcept
  {}
};

/**
 * No-op implementation of Meter.
 */
class NoopMeter final : public Meter
{
public:
  nostd::shared_ptr<Counter<long>> CreateLongCounter(nostd::string_view name,
                                                     nostd::string_view description = "",
                                                     nostd::string_view unit = "") noexcept override
  {
    return nostd::shared_ptr<Counter<long>>{new NoopCounter<long>(name, description, unit)};
  }

  nostd::shared_ptr<Counter<double>> CreateDoubleCounter(
      nostd::string_view name,
      nostd::string_view description = "",
      nostd::string_view unit        = "") noexcept override
  {
    return nostd::shared_ptr<Counter<double>>{new NoopCounter<double>(name, description, unit)};
  }

  void CreateLongObservableCounter(nostd::string_view name,
                                   void (*callback)(ObserverResult<long> &, void *),
                                   nostd::string_view description = "",
                                   nostd::string_view unit        = "",
                                   void *state                    = nullptr) noexcept override
  {}

  void CreateDoubleObservableCounter(nostd::string_view name,
                                     void (*callback)(ObserverResult<double> &, void *),
                                     nostd::string_view description = "",
                                     nostd::string_view unit        = "",
                                     void *state                    = nullptr) noexcept override
  {}

  nostd::shared_ptr<Histogram<long>> CreateLongHistogram(
      nostd::string_view name,
      nostd::string_view description = "",
      nostd::string_view unit        = "") noexcept override
  {
    return nostd::shared_ptr<Histogram<long>>{new NoopHistogram<long>(name, description, unit)};
  }

  nostd::shared_ptr<Histogram<double>> CreateDoubleHistogram(
      nostd::string_view name,
      nostd::string_view description = "",
      nostd::string_view unit        = "") noexcept override
  {
    return nostd::shared_ptr<Histogram<double>>{new NoopHistogram<double>(name, description, unit)};
  }

  void CreateLongObservableGauge(nostd::string_view name,
                                 void (*callback)(ObserverResult<long> &, void *),
                                 nostd::string_view description = "",
                                 nostd::string_view unit        = "",
                                 void *state                    = nullptr) noexcept override
  {}

  void CreateDoubleObservableGauge(nostd::string_view name,
                                   void (*callback)(ObserverResult<double> &, void *),
                                   nostd::string_view description = "",
                                   nostd::string_view unit        = "",
                                   void *state                    = nullptr) noexcept override
  {}

  nostd::shared_ptr<UpDownCounter<long>> CreateLongUpDownCounter(
      nostd::string_view name,
      nostd::string_view description = "",
      nostd::string_view unit        = "") noexcept override
  {
    return nostd::shared_ptr<UpDownCounter<long>>{
        new NoopUpDownCounter<long>(name, description, unit)};
  }

  nostd::shared_ptr<UpDownCounter<double>> CreateDoubleUpDownCounter(
      nostd::string_view name,
      nostd::string_view description = "",
      nostd::string_view unit        = "") noexcept override
  {
    return nostd::shared_ptr<UpDownCounter<double>>{
        new NoopUpDownCounter<double>(name, description, unit)};
  }

  void CreateLongObservableUpDownCounter(nostd::string_view name,
                                         void (*callback)(ObserverResult<long> &, void *),
                                         nostd::string_view description = "",
                                         nostd::string_view unit        = "",
                                         void *state                    = nullptr) noexcept override
  {}

  void CreateDoubleObservableUpDownCounter(nostd::string_view name,
                                           void (*callback)(ObserverResult<double> &, void *),
                                           nostd::string_view description = "",
                                           nostd::string_view unit        = "",
                                           void *state = nullptr) noexcept override
  {}
};

/**
 * No-op implementation of a MeterProvider.
 */
class NoopMeterProvider final : public MeterProvider
{
public:
  NoopMeterProvider() : meter_{nostd::shared_ptr<Meter>(new NoopMeter)} {}

  nostd::shared_ptr<Meter> GetMeter(nostd::string_view library_name,
                                    nostd::string_view library_version,
                                    nostd::string_view schema_url) noexcept override
  {
    return meter_;
  }

private:
  nostd::shared_ptr<Meter> meter_;
};
}  // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif