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()), opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create({})) noexcept

Initialize a new meter provider

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

  • 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

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

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

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

NOTE - INTERNAL method, can change in 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) noexcept

Attaches a metric reader to list of configured readers for this Meter context.

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:

reader – The metric reader for this meter context. This must not be a nullptr.

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(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

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() noexcept

Shutdown the Collectors associated with this meter provider.