Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
start sketching out internal metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Mar 11, 2024
1 parent 7dc0192 commit 65de23e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions targets/otlp/src/data/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) struct EventEncoder {

pub(crate) struct SumEncoder {
pub single_point_per_sample: bool,
// TODO: delta to cumulative
}

impl SumEncoder {
Expand Down
42 changes: 42 additions & 0 deletions targets/otlp/src/internal_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::sync::atomic::{AtomicUsize, Ordering};

use emit::Clock;

macro_rules! increment {
($metric:path) => {
increment!($metric, 1);
};
($metic:path, $by:expr) => {
$metic.fetch_add($by, std::sync::atomic::Ordering::Relaxed);
};
}

pub(crate) static INTERNAL_METRICS: InternalMetrics = InternalMetrics {
log_batches_sent: AtomicUsize::new(0),
};

pub(crate) struct InternalMetrics {
pub(crate) log_batches_sent: AtomicUsize,
}

impl InternalMetrics {
pub(crate) fn emit(&self) {
let InternalMetrics {
ref log_batches_sent,
} = self;

let rt = emit::runtime::internal();

let extent = rt.now();

emit::info!(
rt,
extent,
"{metric_value} {signal} batches sent",
metric_name: "batches_sent",
metric_agg: "count",
metric_value: log_batches_sent.load(Ordering::Relaxed),
signal: "logs"
);
}
}
2 changes: 2 additions & 0 deletions targets/otlp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(stmt_expr_attributes, proc_macro_hygiene)]

#[macro_use]
mod internal_metrics;
mod client;
pub mod data;
mod error;
Expand Down

0 comments on commit 65de23e

Please sign in to comment.