Class MeterContext

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< MeterContext >

Class Documentation

class MeterContext : public std::enable_shared_from_this<MeterContext>

A class which stores the MeterProvider context.

Public Functions

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

Parameters:
  • views – The views to be configured with meter context.

  • resource – The resource for this meter context.

const opentelemetry::sdk::resource::Resource &GetResource() const noexcept

Obtain the resource associated with this meter context.

Returns:

The resource for this meter context

ViewRegistry *GetViewRegistry() const noexcept

Obtain the View Registry configured

Returns:

The reference to view registry

const instrumentationscope::ScopeConfigurator<MeterConfig> &GetMeterConfigurator() const noexcept

Obtain the ScopeConfigurator with this meter context.

Returns:

The ScopeConfigurator for this meter context.

bool ForEachMeter(nostd::function_ref<bool(std::shared_ptr<Meter> &meter)> callback) noexcept

NOTE - INTERNAL method, can change in the future. Process callback for each meter in thread-safe manner

nostd::span<std::shared_ptr<Meter>> GetMeters() noexcept

NOTE - INTERNAL method, can change in the future. Get the configured meters. This method is NOT thread safe, and only called through MeterProvider

nostd::span<std::shared_ptr<CollectorHandle>> GetCollectors() noexcept

Obtain the configured collectors.

opentelemetry::common::SystemTimestamp GetSDKStartTime() noexcept

GET SDK Start time

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 configured collectors.

Note: This reader may not receive any in-flight meter data, but will get newly created meter data. Note: This method is not thread safe, and should ideally be called from main thread.

Parameters:
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.

Note: This view may not receive any in-flight meter data, but will get newly created meter data. Note: This method is not thread safe, and should ideally be called from main thread.

Parameters:

view – The Views for this meter context. This must not be a nullptr.

void AddMeter(const std::shared_ptr<Meter> &meter)

NOTE - INTERNAL method, can change in future. Adds a meter to the list of configured meters in thread safe manner.

Parameters:

meter – The meter to be added.

void RemoveMeter(nostd::string_view name, nostd::string_view version, nostd::string_view schema_url)
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.

bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept

Shutdown the Collectors associated with this meter provider.

Friends

friend class ::testing::MetricCollectorTest