NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/metrics/meter_context.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 <atomic>
7 #include <chrono>
8 #include <memory>
9 #include <vector>
10 
11 #include "opentelemetry/common/spin_lock_mutex.h"
12 #include "opentelemetry/common/timestamp.h"
13 #include "opentelemetry/nostd/function_ref.h"
14 #include "opentelemetry/nostd/span.h"
15 #include "opentelemetry/nostd/string_view.h"
16 #include "opentelemetry/sdk/instrumentationscope/scope_configurator.h"
17 #include "opentelemetry/sdk/metrics/export/metric_filter.h"
18 #include "opentelemetry/sdk/metrics/meter_config.h"
19 #include "opentelemetry/sdk/metrics/metric_reader.h"
20 #include "opentelemetry/sdk/metrics/state/metric_collector.h"
21 #include "opentelemetry/sdk/metrics/view/instrument_selector.h"
22 #include "opentelemetry/sdk/metrics/view/meter_selector.h"
23 #include "opentelemetry/sdk/metrics/view/view.h"
24 #include "opentelemetry/sdk/metrics/view/view_registry.h"
25 #include "opentelemetry/sdk/resource/resource.h"
26 #include "opentelemetry/version.h"
27 
28 #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
29 # include "opentelemetry/sdk/metrics/exemplar/filter_type.h"
30 #endif
31 
32 namespace testing
33 {
34 class MetricCollectorTest;
35 }
36 
38 namespace sdk
39 {
40 namespace metrics
41 {
42 
43 // forward declaration
44 class CollectorHandle;
45 class InstrumentSelector;
46 class Meter;
47 class MetricReader;
48 class MeterSelector;
49 
54 class MeterContext : public std::enable_shared_from_this<MeterContext>
55 {
56 public:
63  std::unique_ptr<ViewRegistry> views = std::unique_ptr<ViewRegistry>(new ViewRegistry()),
64  const opentelemetry::sdk::resource::Resource &resource =
65  opentelemetry::sdk::resource::Resource::Create({}),
69  .Build())) noexcept;
70 
75  const opentelemetry::sdk::resource::Resource &GetResource() const noexcept;
76 
81  ViewRegistry *GetViewRegistry() const noexcept;
82 
88 
93  bool ForEachMeter(nostd::function_ref<bool(std::shared_ptr<Meter> &meter)> callback) noexcept;
94 
102 
108 
113  opentelemetry::common::SystemTimestamp GetSDKStartTime() noexcept;
114 
126  void AddMetricReader(std::shared_ptr<MetricReader> reader,
127  std::unique_ptr<MetricFilter> metric_filter = nullptr) noexcept;
128 
137  void AddView(std::unique_ptr<InstrumentSelector> instrument_selector,
138  std::unique_ptr<MeterSelector> meter_selector,
139  std::unique_ptr<View> view) noexcept;
140 
141 #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
142 
143  void SetExemplarFilter(ExemplarFilterType exemplar_filter_type) noexcept;
144 
145  ExemplarFilterType GetExemplarFilter() const noexcept;
146 
147 #endif
148 
155  void AddMeter(const std::shared_ptr<Meter> &meter);
156 
159  nostd::string_view schema_url);
160 
166  bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;
167 
171  bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;
172 
173 private:
174  friend class ::testing::MetricCollectorTest;
175 
176  opentelemetry::sdk::resource::Resource resource_;
177  std::vector<std::shared_ptr<CollectorHandle>> collectors_;
178  std::unique_ptr<ViewRegistry> views_;
179  opentelemetry::common::SystemTimestamp sdk_start_ts_;
180  std::unique_ptr<instrumentationscope::ScopeConfigurator<MeterConfig>> meter_configurator_;
181  std::vector<std::shared_ptr<Meter>> meters_;
182 
183 #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
184  metrics::ExemplarFilterType exemplar_filter_type_ = metrics::ExemplarFilterType::kAlwaysOff;
185 #endif
186 
187 #if defined(__cpp_lib_atomic_value_initialization) && \
188  __cpp_lib_atomic_value_initialization >= 201911L
189  std::atomic_flag shutdown_latch_{};
190 #else
191  std::atomic_flag shutdown_latch_ = ATOMIC_FLAG_INIT;
192 #endif
193  opentelemetry::common::SpinLockMutex forceflush_lock_;
194  opentelemetry::common::SpinLockMutex meter_lock_;
195 };
196 
197 } // namespace metrics
198 } // namespace sdk
testing
Definition: includes/opentelemetry/sdk/metrics/meter_context.h:32
sdk::metrics::MeterContext::AddView
void AddView(std::unique_ptr< InstrumentSelector > instrument_selector, std::unique_ptr< MeterSelector > meter_selector, std::unique_ptr< View > view) noexcept
Attaches a View to list of configured Views for this Meter context.
sdk::metrics::MeterContext::GetViewRegistry
ViewRegistry * GetViewRegistry() const noexcept
Obtain the View Registry configured.
nostd::function_ref
Definition: includes/opentelemetry/nostd/function_ref.h:17
sdk::metrics::ViewRegistry
Definition: includes/opentelemetry/sdk/metrics/view/view_registry.h:41
nostd::unique_ptr
std::unique_ptr< _Types... > unique_ptr
Definition: includes/opentelemetry/std/unique_ptr.h:19
sdk::metrics::MeterConfig::Default
static MeterConfig Default()
Returns a MeterConfig that represents a Meter configured with the default behavior.
prometheus::detail::make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: includes/prometheus/detail/future_std.h:28
sdk::metrics::MeterContext::ForEachMeter
bool ForEachMeter(nostd::function_ref< bool(std::shared_ptr< Meter > &meter)> callback) noexcept
NOTE - INTERNAL method, can change in the future.
sdk::metrics::MeterContext::GetMeters
nostd::span< std::shared_ptr< Meter > > GetMeters() noexcept
NOTE - INTERNAL method, can change in the future.
sdk::metrics::MeterContext::RemoveMeter
void RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url)
sdk::metrics::MeterContext::GetMeterConfigurator
const instrumentationscope::ScopeConfigurator< MeterConfig > & GetMeterConfigurator() const noexcept
Obtain the ScopeConfigurator with this meter context.
sdk::metrics::MeterContext
A class which stores the MeterProvider context.
Definition: includes/opentelemetry/sdk/metrics/meter_context.h:54
version
int version
Definition: sources/libs/nvll_batch_jpeg_encode/oss/jpeglib.h:908
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
nostd::span
Back port of std::span.
Definition: includes/opentelemetry/nostd/span.h:51
sdk::metrics::MeterContext::MeterContext
MeterContext(std::unique_ptr< ViewRegistry > views=std::unique_ptr< ViewRegistry >(new ViewRegistry()), const opentelemetry::sdk::resource::Resource &resource=opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr< instrumentationscope::ScopeConfigurator< MeterConfig >> meter_configurator=std::make_unique< instrumentationscope::ScopeConfigurator< MeterConfig >>(instrumentationscope::ScopeConfigurator< MeterConfig >::Builder(MeterConfig::Default()) .Build())) noexcept
Initialize a new meter provider.
sdk::metrics::MeterContext::ForceFlush
bool ForceFlush(std::chrono::microseconds timeout=(std::chrono::microseconds::max)()) noexcept
Force all active Collectors to flush any buffered meter data within the given timeout.
max
int max(int a, int b)
Compute the component-wise maximum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:60
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
sdk::metrics::MeterContext::GetSDKStartTime
opentelemetry::common::SystemTimestamp GetSDKStartTime() noexcept
GET SDK Start time.
sdk::instrumentationscope::ScopeConfigurator::Builder
A builder class for the ScopeConfigurator that facilitates the creation of ScopeConfigurators.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:26
sdk::instrumentationscope::ScopeConfigurator
A scope configurator is a function that returns the scope config for a given instrumentation scope.
Definition: includes/opentelemetry/sdk/instrumentationscope/scope_configurator.h:20
sdk::metrics::MeterContext::AddMetricReader
void AddMetricReader(std::shared_ptr< MetricReader > reader, std::unique_ptr< MetricFilter > metric_filter=nullptr) noexcept
Create a MetricCollector from a MetricReader using this MeterContext and add it to the list of config...
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
sdk::metrics::MeterContext::AddMeter
void AddMeter(const std::shared_ptr< Meter > &meter)
NOTE - INTERNAL method, can change in future.
sdk::metrics::MeterContext::Shutdown
bool Shutdown(std::chrono::microseconds timeout=(std::chrono::microseconds::max)()) noexcept
Shutdown the Collectors associated with this meter provider.
sdk::metrics::MeterContext::GetCollectors
nostd::span< std::shared_ptr< CollectorHandle > > GetCollectors() noexcept
Obtain the configured collectors.
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37
sdk::metrics::MeterContext::GetResource
const opentelemetry::sdk::resource::Resource & GetResource() const noexcept
Obtain the resource associated with this meter context.