opentelemetry_sdk

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, [View]s, 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")
    .build();

// 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();

Re-exports§

  • pub use pipeline::Pipeline;

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.
  • Errors returned by the metrics API.
  • Defines the window that an aggregation was calculated over.

Type Aliases§

  • A specialized Result type for metric operations.