Module opentelemetry::sdk::metrics

source ·
Expand description

The rust of the OpenTelemetry metrics SDK.

Configuration

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

Example

use opentelemetry_api::{
    metrics::{MeterProvider as _, Unit},
    KeyValue,
};
use opentelemetry_sdk::{metrics::MeterProvider, 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 provider = MeterProvider::builder().with_resource(resource).build();

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

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

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

Modules

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

Structs

Enums

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

Traits

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

Functions

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