NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/metrics/meter.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <chrono>
7 #include <memory>
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
11 
12 #include "opentelemetry/common/macros.h"
13 #include "opentelemetry/metrics/meter.h"
14 #include "opentelemetry/metrics/noop.h"
15 #include "opentelemetry/nostd/shared_ptr.h"
16 #include "opentelemetry/nostd/string_view.h"
17 #include "opentelemetry/nostd/unique_ptr.h"
18 #include "opentelemetry/sdk/common/attributemap_hash.h"
19 #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
20 #include "opentelemetry/sdk/metrics/instrument_metadata_validator.h"
21 #include "opentelemetry/sdk/metrics/instruments.h"
22 #include "opentelemetry/sdk/metrics/meter_config.h"
23 #include "opentelemetry/sdk/metrics/meter_context.h"
24 #include "opentelemetry/sdk/metrics/state/async_metric_storage.h"
25 #include "opentelemetry/sdk/resource/resource.h"
26 #include "opentelemetry/sdk_config.h"
27 #include "opentelemetry/version.h"
28 
30 namespace sdk
31 {
32 namespace metrics
33 {
34 
35 class MetricStorage;
36 class SyncWritableMetricStorage;
37 class AsyncWritableMetricsStorge;
38 class ObservableRegistry;
39 
40 class Meter final : public opentelemetry::metrics::Meter
41 {
42 public:
44  explicit Meter(
45  std::weak_ptr<sdk::metrics::MeterContext> meter_context,
46  std::unique_ptr<opentelemetry::sdk::instrumentationscope::InstrumentationScope> scope =
47  opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept;
48 
50  nostd::string_view name,
51  nostd::string_view description = "",
52  nostd::string_view unit = "") noexcept override;
53 
55  nostd::string_view name,
56  nostd::string_view description = "",
57  nostd::string_view unit = "") noexcept override;
58 
60  nostd::string_view name,
61  nostd::string_view description = "",
62  nostd::string_view unit = "") noexcept override;
63 
65  nostd::string_view name,
66  nostd::string_view description = "",
67  nostd::string_view unit = "") noexcept override;
68 
70  nostd::string_view name,
71  nostd::string_view description = "",
72  nostd::string_view unit = "") noexcept override;
73 
75  nostd::string_view name,
76  nostd::string_view description = "",
77  nostd::string_view unit = "") noexcept override;
78 
79 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
81  nostd::string_view name,
82  nostd::string_view description = "",
83  nostd::string_view unit = "") noexcept override;
84 
86  nostd::string_view name,
87  nostd::string_view description = "",
88  nostd::string_view unit = "") noexcept override;
89 #endif
90 
92  nostd::string_view name,
93  nostd::string_view description = "",
94  nostd::string_view unit = "") noexcept override;
95 
97  nostd::string_view name,
98  nostd::string_view description = "",
99  nostd::string_view unit = "") noexcept override;
100 
102  nostd::string_view name,
103  nostd::string_view description = "",
104  nostd::string_view unit = "") noexcept override;
105 
107  nostd::string_view name,
108  nostd::string_view description = "",
109  nostd::string_view unit = "") noexcept override;
110 
113  nostd::string_view description = "",
114  nostd::string_view unit = "") noexcept override;
115 
118  nostd::string_view description = "",
119  nostd::string_view unit = "") noexcept override;
120 
123 
124  OPENTELEMETRY_DEPRECATED_MESSAGE("Please use GetInstrumentationScope instead")
125  const sdk::instrumentationscope::InstrumentationScope *GetInstrumentationLibrary() const noexcept
126  {
127  return GetInstrumentationScope();
128  }
129 
131  std::vector<MetricData> Collect(CollectorHandle *collector,
132  opentelemetry::common::SystemTimestamp collect_ts) noexcept;
133 
134 private:
135  // order of declaration is important here - instrumentation scope should destroy after
136  // meter-context.
137  std::unique_ptr<sdk::instrumentationscope::InstrumentationScope> scope_;
138  std::weak_ptr<sdk::metrics::MeterContext> meter_context_;
139  // Mapping between instrument descriptor and Aggregation Storage.
140  using MetricStorageMap = std::unordered_map<InstrumentDescriptor,
141  std::shared_ptr<MetricStorage>,
144  MetricStorageMap storage_registry_;
145  std::shared_ptr<ObservableRegistry> observable_registry_;
146  MeterConfig meter_config_;
147  std::unique_ptr<SyncWritableMetricStorage> RegisterSyncMetricStorage(
148  InstrumentDescriptor &instrument_descriptor);
149  std::unique_ptr<AsyncWritableMetricStorage> RegisterAsyncMetricStorage(
150  InstrumentDescriptor &instrument_descriptor);
151  opentelemetry::common::SpinLockMutex storage_lock_;
152 
153  static opentelemetry::metrics::NoopMeter kNoopMeter;
154 
156  GetNoopObservableInsrument()
157  {
159  new opentelemetry::metrics::NoopObservableInstrument("", "", ""));
160  return noop_instrument;
161  }
162 
163  static bool ValidateInstrument(nostd::string_view name,
164  nostd::string_view description,
165  nostd::string_view unit)
166  {
167  const static InstrumentMetaDataValidator instrument_validator;
168  return instrument_validator.ValidateName(name) && instrument_validator.ValidateUnit(unit) &&
169  instrument_validator.ValidateDescription(description);
170  }
171 
172  // This function checks if the instrument is a duplicate of an existing one
173  // and emits a warning through the internal logger.
174  static void WarnOnDuplicateInstrument(
176  const MetricStorageMap &storage_registry,
177  const InstrumentDescriptor &new_instrument);
178 
179  // This function checks if the instrument has a name case conflict with an existing one
180  // and emits a warning through the internal logger.
181  static void WarnOnNameCaseConflict(const sdk::instrumentationscope::InstrumentationScope *scope,
182  const InstrumentDescriptor &existing_instrument,
183  const InstrumentDescriptor &new_instrument);
184 };
185 } // namespace metrics
186 } // namespace sdk
sdk::metrics::Meter::CreateDoubleObservableGauge
nostd::shared_ptr< opentelemetry::metrics::ObservableInstrument > CreateDoubleObservableGauge(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::InstrumentEqualNameCaseInsensitive
Definition: includes/opentelemetry/sdk/metrics/instruments.h:159
sdk::instrumentationscope::InstrumentationScope
Definition: includes/opentelemetry/sdk/instrumentationscope/instrumentation_scope.h:26
sdk::metrics::InstrumentDescriptorHash
Definition: includes/opentelemetry/sdk/metrics/instruments.h:196
nostd::unique_ptr
Provide a simplified port of std::unique_ptr that has ABI stability.
Definition: includes/opentelemetry/nostd/unique_ptr.h:45
sdk::metrics::CollectorHandle
Definition: includes/opentelemetry/sdk/metrics/state/metric_collector.h:25
nostd::shared_ptr
Provide a type-erased version of std::shared_ptr that has ABI stability.
Definition: includes/opentelemetry/nostd/shared_ptr.h:28
sdk::metrics::Meter
Definition: includes/opentelemetry/sdk/metrics/meter.h:40
sdk::metrics::Meter::Collect
std::vector< MetricData > Collect(CollectorHandle *collector, opentelemetry::common::SystemTimestamp collect_ts) noexcept
collect metrics across all the instruments configured for the meter
sdk::metrics::Meter::CreateDoubleHistogram
nostd::unique_ptr< opentelemetry::metrics::Histogram< double > > CreateDoubleHistogram(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
sdk::metrics::Meter::CreateDoubleCounter
nostd::unique_ptr< opentelemetry::metrics::Counter< double > > CreateDoubleCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
sdk::metrics::Meter::CreateDoubleObservableUpDownCounter
nostd::shared_ptr< opentelemetry::metrics::ObservableInstrument > CreateDoubleObservableUpDownCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::Meter::CreateInt64ObservableCounter
nostd::shared_ptr< opentelemetry::metrics::ObservableInstrument > CreateInt64ObservableCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::Meter::GetInstrumentationLibrary
const sdk::instrumentationscope::InstrumentationScope * GetInstrumentationLibrary() const noexcept
Definition: includes/opentelemetry/sdk/metrics/meter.h:125
sdk::metrics::Meter::CreateInt64ObservableUpDownCounter
nostd::shared_ptr< opentelemetry::metrics::ObservableInstrument > CreateInt64ObservableUpDownCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::Meter::GetInstrumentationScope
const sdk::instrumentationscope::InstrumentationScope * GetInstrumentationScope() const noexcept
Returns the associated instrumentation scope.
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::metrics::Meter::CreateDoubleUpDownCounter
nostd::unique_ptr< opentelemetry::metrics::UpDownCounter< double > > CreateDoubleUpDownCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
sdk::metrics::Meter::Meter
Meter(std::weak_ptr< sdk::metrics::MeterContext > meter_context, std::unique_ptr< opentelemetry::sdk::instrumentationscope::InstrumentationScope > scope=opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept
Construct a new Meter with the given pipeline.
sdk::metrics::InstrumentDescriptor
Definition: includes/opentelemetry/sdk/metrics/instruments.h:61
sdk::metrics::Meter::CreateUInt64Counter
nostd::unique_ptr< opentelemetry::metrics::Counter< uint64_t > > CreateUInt64Counter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::Meter::CreateUInt64Histogram
nostd::unique_ptr< opentelemetry::metrics::Histogram< uint64_t > > CreateUInt64Histogram(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::Meter::CreateInt64UpDownCounter
nostd::unique_ptr< opentelemetry::metrics::UpDownCounter< int64_t > > CreateInt64UpDownCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
sdk::metrics::MeterConfig
MeterConfig defines various configurable aspects of a Meter's behavior.
Definition: includes/opentelemetry/sdk/metrics/meter_config.h:19
sdk::metrics::Meter::CreateInt64ObservableGauge
nostd::shared_ptr< opentelemetry::metrics::ObservableInstrument > CreateInt64ObservableGauge(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
OPENTELEMETRY_DEPRECATED_MESSAGE
#define OPENTELEMETRY_DEPRECATED_MESSAGE(msg)
Definition: includes/opentelemetry/common/macros.h:244
sdk::metrics::Meter::CreateDoubleObservableCounter
nostd::shared_ptr< opentelemetry::metrics::ObservableInstrument > CreateDoubleObservableCounter(nostd::string_view name, nostd::string_view description="", nostd::string_view unit="") noexcept override
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37