pdk-classy 1.9.1-alpha.2

PDK Classy
Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

pub use crate::proxy_wasm::types::MetricType;

use crate::proxy_wasm::hostcalls;

// Import macros - now exported from the parent module
use crate::{function, unwrap_or_default};

/// An interface of the `Envoy` `Metrics API`.
pub trait MetricsHost {
    fn define_metric(&self, metric_type: MetricType, name: &str) -> u32;

    fn get_metric(&self, metric_id: u32) -> u64;

    fn record_metric(&self, metric_id: u32, value: u64);

    fn increment_metric(&self, metric_id: u32, offset: i64);
}

pub struct DefaultMetricsHost;

impl MetricsHost for DefaultMetricsHost {
    fn define_metric(&self, metric_type: MetricType, name: &str) -> u32 {
        unwrap_or_default!(hostcalls::define_metric(metric_type, name))
    }

    fn get_metric(&self, metric_id: u32) -> u64 {
        unwrap_or_default!(hostcalls::get_metric(metric_id))
    }

    fn record_metric(&self, metric_id: u32, value: u64) {
        unwrap_or_default!(hostcalls::record_metric(metric_id, value))
    }

    fn increment_metric(&self, metric_id: u32, offset: i64) {
        unwrap_or_default!(hostcalls::increment_metric(metric_id, offset))
    }
}