mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +00:00
feat(metrics): Record metrics with OpenTelemetry and export over OTLP
This commit is contained in:
1 parent
e96b6e6665
commit
5185045cb6
33 files changed
+1118
-455
No files matched your search
@@ -2,6 +2,7 @@ use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, debug_error, err, info,
|
||||
matrix::{event::gen_event_id_canonical_json, pdu::PartialPdu},
|
||||
metrics::KeyValue,
|
||||
trace, warn,
|
||||
};
|
||||
use futures::FutureExt;
|
||||
@@ -113,6 +114,31 @@ pub(crate) async fn invite_helper(
|
||||
room_id: &RoomId,
|
||||
reason: Option<String>,
|
||||
is_direct: bool,
|
||||
) -> Result {
|
||||
let result =
|
||||
send_invite(services, sender_user, recipient_user, room_id, reason, is_direct).await;
|
||||
|
||||
let destination = if services.globals.user_is_local(recipient_user) {
|
||||
"local"
|
||||
} else {
|
||||
"remote"
|
||||
};
|
||||
services.server.metrics.instruments.invites.add(1, &[
|
||||
KeyValue::new("direction", "outgoing"),
|
||||
KeyValue::new("destination", destination),
|
||||
KeyValue::new("outcome", if result.is_ok() { "success" } else { "failure" }),
|
||||
]);
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
async fn send_invite(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
recipient_user: &UserId,
|
||||
room_id: &RoomId,
|
||||
reason: Option<String>,
|
||||
is_direct: bool,
|
||||
) -> Result {
|
||||
if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites {
|
||||
info!(
|
||||
|
||||
@@ -2,6 +2,7 @@ use axum::{Json, extract::State, response::IntoResponse};
|
||||
use conduwuit::{
|
||||
Err, Result,
|
||||
matrix::versions::{unstable_features, versions},
|
||||
metrics::PROMETHEUS_CONTENT_TYPE,
|
||||
utils::string::constant_time_eq,
|
||||
};
|
||||
use futures::StreamExt;
|
||||
@@ -80,7 +81,7 @@ pub(crate) async fn continuwuity_local_user_count(
|
||||
|
||||
/// # `GET /_continuwuity/metrics`
|
||||
///
|
||||
/// Prometheus metrics in the OpenMetrics text format. Only routed when
|
||||
/// Prometheus metrics in the text exposition format. Only routed when
|
||||
/// `allow_prometheus_metrics` is enabled.
|
||||
pub(crate) async fn continuwuity_metrics(
|
||||
State(services): State<crate::State>,
|
||||
@@ -100,14 +101,7 @@ pub(crate) async fn continuwuity_metrics(
|
||||
}
|
||||
}
|
||||
|
||||
services.update_metrics()?;
|
||||
let body = services.server.metrics.prometheus.encode()?;
|
||||
let body = services.server.metrics.render()?;
|
||||
|
||||
Ok((
|
||||
[(
|
||||
header::CONTENT_TYPE,
|
||||
"application/openmetrics-text; version=1.0.0; charset=utf-8",
|
||||
)],
|
||||
body,
|
||||
))
|
||||
Ok(([(header::CONTENT_TYPE, PROMETHEUS_CONTENT_TYPE)], body))
|
||||
}
|
||||
Reference in new issue
Block a user