Files
inbuxa-server/crates/common/src/telemetry/metrics/otel.rs
T
jcoffey-dev 6a53d47106 Mark the files this fork changed (AGPL section 5(a))
The AGPL asks a modified version to carry prominent notices saying it was
modified, and giving a date. Publishing the source is the conveyance that
asks for it, so it wants doing before the repository is public rather than
at the release.

Every upstream file the fork changed now says so in its header, beneath the
notice it came with: 164 files, found by diffing against the upstream
snapshot branch rather than by guessing, so the list is what actually
differs. Files the fork wrote itself already carry their own copyright and
need nothing. Upstream's notices are untouched, which its licence requires
and which was already true.

The README says the same thing in prose, since the obligation is on the
work as a whole and not only its Rust files.

Builds unchanged: the server and the test binary both compile.
2026-09-19 23:48:35 -07:00

103 lines
3.3 KiB
Rust

/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*
* Modified by Coffey Labs in 2026 for INBUXA.
*/
use crate::config::telemetry::OtelMetrics;
use opentelemetry_sdk::metrics::{
Temporality,
data::{
AggregatedMetrics, Gauge, GaugeDataPoint, Histogram, HistogramDataPoint, Metric,
MetricData, ResourceMetrics, ScopeMetrics, Sum, SumDataPoint,
},
exporter::PushMetricExporter,
};
use std::time::SystemTime;
use trc::{Collector, TelemetryEvent};
impl OtelMetrics {
pub async fn push_metrics(&self, start_time: SystemTime) {
let mut metrics = Vec::with_capacity(256);
let time = SystemTime::now();
// Add counters
for counter in Collector::collect_counters() {
metrics.push(Metric::new(
counter.id().as_str(),
counter.id().description(),
"events",
AggregatedMetrics::U64(MetricData::Sum(Sum::new(
vec![SumDataPoint::new(vec![], counter.value(), vec![])],
start_time,
time,
Temporality::Cumulative,
true,
))),
));
}
// Add gauges
for gauge in Collector::collect_gauges() {
metrics.push(Metric::new(
gauge.id().as_str(),
gauge.id().description(),
gauge.id().unit(),
AggregatedMetrics::U64(MetricData::Gauge(Gauge::new(
vec![GaugeDataPoint::new(vec![], gauge.get(), vec![])],
Some(start_time),
time,
))),
));
}
// Add histograms
for histogram in Collector::collect_histograms() {
metrics.push(Metric::new(
histogram.id().as_str(),
histogram.id().description(),
histogram.id().unit(),
AggregatedMetrics::U64(MetricData::Histogram(Histogram::new(
vec![HistogramDataPoint::new(
vec![],
histogram.count(),
histogram.upper_bounds_vec(),
histogram.buckets_vec(),
histogram.min(),
histogram.max(),
histogram.sum(),
vec![],
)],
start_time,
time,
Temporality::Cumulative,
))),
));
}
// Export metrics
let rm = ResourceMetrics::new(
self.resource.clone(),
vec![ScopeMetrics::new(self.instrumentation.clone(), metrics)],
);
if let Err(err) = self.exporter.export(&rm).await {
trc::event!(
Telemetry(TelemetryEvent::OtelMetricsExporterError),
Reason = err.to_string(),
);
}
}
pub fn enable_errors() {
// TODO: Remove this when the OpenTelemetry SDK supports error handling
/*let _ = set_error_handler(|error| {
trc::event!(
Telemetry(TelemetryEvent::OtelMetricsExporterError),
Reason = error.to_string(),
);
});*/
}
}