pub struct AnalyticsClient {
pub backend_canister_id: Principal,
}Expand description
Client for recording metrics to an IC Metrics analytics canister.
Create once per canister and store in a thread_local!. All calls are
fire-and-forget — they enqueue a one-way inter-canister call and return
immediately without blocking execution.
§Example
use ic_analytics_sdk::AnalyticsClient;
use candid::Principal;
thread_local! {
static ANALYTICS: AnalyticsClient = AnalyticsClient::new(
Principal::from_text("YOUR-ANALYTICS-CANISTER-ID").unwrap()
);
}Fields§
§backend_canister_id: PrincipalImplementations§
Source§impl AnalyticsClient
impl AnalyticsClient
Sourcepub fn new(backend_canister_id: Principal) -> Self
pub fn new(backend_canister_id: Principal) -> Self
Creates a new client pointing at the given analytics canister.
Sourcepub fn record_metric(&self, metric: Metric) -> Result<(), String>
pub fn record_metric(&self, metric: Metric) -> Result<(), String>
Enqueues a one-way call to record a metric. Non-blocking.
MetricValue::TimeSeries is automatically converted to
Histogram { x: now_ms, y } using the current IC time before the
call is sent.
Trait Implementations§
Source§impl Clone for AnalyticsClient
impl Clone for AnalyticsClient
Source§fn clone(&self) -> AnalyticsClient
fn clone(&self) -> AnalyticsClient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AnalyticsClient
impl RefUnwindSafe for AnalyticsClient
impl Send for AnalyticsClient
impl Sync for AnalyticsClient
impl Unpin for AnalyticsClient
impl UnsafeUnpin for AnalyticsClient
impl UnwindSafe for AnalyticsClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more