Module metrics

Source
Expand description

The crust of the OpenTelemetry metrics SDK.

§Configuration

The metrics SDK configuration is stored with each SdkMeterProvider. Configuration for Resources, Views, and ManualReader or PeriodicReader instances can be specified.

§Example

use opentelemetry::global;
use opentelemetry::KeyValue;
use opentelemetry_sdk::{metrics::SdkMeterProvider, Resource};

// Generate SDK configuration, resource, views, etc
let resource = Resource::default(); // default attributes about the current process

// Create a meter provider with the desired config
let meter_provider = SdkMeterProvider::builder().with_resource(resource).build();
global::set_meter_provider(meter_provider.clone());

// Use the meter provider to create meter instances
let meter = global::meter("my_app");

// Create instruments scoped to the meter
let counter = meter
    .u64_counter("power_consumption")
    .with_unit("kWh")
    .init();

// use instruments to record measurements
counter.add(10, &[KeyValue::new("rate", "standard")]);

// shutdown the provider at the end of the application to ensure any metrics not yet
// exported are flushed.
meter_provider.shutdown().unwrap();

Modules§

data
Types for delivery of pre-aggregated metric time series data.
exporter
Interfaces for exporting metrics
reader
Interfaces for reading and producing metrics

Structs§

AttributeSet
A unique set of attributes that can be used as instrument identifiers.
Instrument
Describes properties an instrument is created with, also used for filtering in Views.
ManualReader
A simple MetricReader that allows an application to read metrics on demand.
ManualReaderBuilder
Configuration for a ManualReader
MeterProviderBuilder
Configuration options for a MeterProvider.
PeriodicReader
A MetricReader that continuously collects and exports metric data at a set interval.
PeriodicReaderBuilder
Configuration options for PeriodicReader.
SdkMeter
Handles the creation and coordination of all metric instruments.
SdkMeterProvider
Handles the creation and coordination of Meters.
Stream
Describes the stream of data an instrument produces.

Enums§

Aggregation
The way recorded measurements are summarized.
InstrumentKind
The identifier of a group of instruments that all perform the same function.

Traits§

View
Used to customize the metrics that are output by the SDK.

Functions§

new_view
Creates a View that applies the Stream mask for all instruments that match criteria.