tweak tracing spans; inlines

db deserializer tracing instrument cover

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-02 05:30:51 +00:00
parent 685b127f99
commit 02f19cf951
16 changed files with 146 additions and 34 deletions

View file

@ -15,8 +15,12 @@ use ruma::{
use super::check_room_id;
#[implement(super::Service)]
#[tracing::instrument(
level = "warn",
skip_all,
fields(%origin),
)]
#[allow(clippy::type_complexity)]
#[tracing::instrument(skip_all)]
pub(super) async fn fetch_prev(
&self,
origin: &ServerName,

View file

@ -1,6 +1,6 @@
use std::collections::{hash_map, HashMap};
use conduwuit::{debug, implement, warn, Err, Error, PduEvent, Result};
use conduwuit::{debug, debug_warn, implement, Err, Error, PduEvent, Result};
use futures::FutureExt;
use ruma::{
api::federation::event::get_room_state_ids, events::StateEventType, EventId, OwnedEventId,
@ -13,7 +13,11 @@ use crate::rooms::short::ShortStateKey;
/// server's response to some extend (sic), but we still do a lot of checks
/// on the events
#[implement(super::Service)]
#[tracing::instrument(skip(self, create_event, room_version_id))]
#[tracing::instrument(
level = "warn",
skip_all,
fields(%origin),
)]
pub(super) async fn fetch_state(
&self,
origin: &ServerName,
@ -22,7 +26,6 @@ pub(super) async fn fetch_state(
room_version_id: &RoomVersionId,
event_id: &EventId,
) -> Result<Option<HashMap<u64, OwnedEventId>>> {
debug!("Fetching state ids");
let res = self
.services
.sending
@ -31,7 +34,7 @@ pub(super) async fn fetch_state(
event_id: event_id.to_owned(),
})
.await
.inspect_err(|e| warn!("Fetching state for event failed: {e}"))?;
.inspect_err(|e| debug_warn!("Fetching state for event failed: {e}"))?;
debug!("Fetching state events");
let state_vec = self

View file

@ -39,7 +39,12 @@ use crate::rooms::timeline::RawPduId;
/// 14. Check if the event passes auth based on the "current state" of the room,
/// if not soft fail it
#[implement(super::Service)]
#[tracing::instrument(skip(self, origin, value, is_timeline_event), name = "pdu")]
#[tracing::instrument(
name = "pdu",
level = "warn",
skip_all,
fields(%room_id, %event_id),
)]
pub async fn handle_incoming_pdu<'a>(
&self,
origin: &'a ServerName,

View file

@ -13,8 +13,10 @@ use ruma::{CanonicalJsonValue, EventId, OwnedEventId, RoomId, ServerName};
#[allow(clippy::type_complexity)]
#[allow(clippy::too_many_arguments)]
#[tracing::instrument(
skip(self, origin, event_id, room_id, eventid_info, create_event, first_pdu_in_room),
name = "prev"
name = "prev",
level = "warn",
skip_all,
fields(%prev_id),
)]
pub(super) async fn handle_prev_pdu<'a>(
&self,

View file

@ -95,7 +95,16 @@ impl crate::Service for Service {
impl Service {
/// Update current membership data.
#[tracing::instrument(skip(self, last_state))]
#[tracing::instrument(
level = "debug",
skip_all,
fields(
%room_id,
%user_id,
%sender,
?membership_event,
),
)]
#[allow(clippy::too_many_arguments)]
pub async fn update_membership(
&self,
@ -265,7 +274,7 @@ impl Service {
Ok(())
}
#[tracing::instrument(skip(self, room_id, appservice), level = "debug")]
#[tracing::instrument(level = "trace", skip_all)]
pub async fn appservice_in_room(
&self,
room_id: &RoomId,
@ -383,7 +392,7 @@ impl Service {
.map(|(_, server): (Ignore, &ServerName)| server)
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn server_in_room<'a>(
&'a self,
server: &'a ServerName,
@ -409,7 +418,7 @@ impl Service {
}
/// Returns true if server can see user by sharing at least one room.
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn server_sees_user(&self, server: &ServerName, user_id: &UserId) -> bool {
self.server_rooms(server)
.any(|room_id| self.is_joined(user_id, room_id))
@ -417,7 +426,7 @@ impl Service {
}
/// Returns true if user_a and user_b share at least one room.
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn user_sees_user(&self, user_a: &UserId, user_b: &UserId) -> bool {
let get_shared_rooms = self.get_shared_rooms(user_a, user_b);
@ -426,6 +435,7 @@ impl Service {
}
/// List the rooms common between two users
#[tracing::instrument(skip(self), level = "debug")]
pub fn get_shared_rooms<'a>(
&'a self,
user_a: &'a UserId,
@ -453,7 +463,7 @@ impl Service {
}
/// Returns the number of users which are currently in a room
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn room_joined_count(&self, room_id: &RoomId) -> Result<u64> {
self.db.roomid_joinedcount.get(room_id).await.deserialized()
}
@ -469,9 +479,9 @@ impl Service {
.ready_filter(|user| self.services.globals.user_is_local(user))
}
#[tracing::instrument(skip(self), level = "debug")]
/// Returns an iterator of all our local joined users in a room who are
/// active (not deactivated, not guest)
#[tracing::instrument(skip(self), level = "trace")]
pub fn active_local_users_in_room<'a>(
&'a self,
room_id: &'a RoomId,
@ -481,7 +491,7 @@ impl Service {
}
/// Returns the number of users which are currently invited to a room
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn room_invited_count(&self, room_id: &RoomId) -> Result<u64> {
self.db
.roomid_invitedcount
@ -518,7 +528,7 @@ impl Service {
.map(|(_, user_id): (Ignore, &UserId)| user_id)
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<u64> {
let key = (room_id, user_id);
self.db
@ -528,7 +538,7 @@ impl Service {
.deserialized()
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<u64> {
let key = (room_id, user_id);
self.db.roomuserid_leftcount.qry(&key).await.deserialized()
@ -566,7 +576,7 @@ impl Service {
.ignore_err()
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn invite_state(
&self,
user_id: &UserId,
@ -583,7 +593,7 @@ impl Service {
})
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn left_state(
&self,
user_id: &UserId,
@ -625,24 +635,25 @@ impl Service {
self.db.roomuseroncejoinedids.qry(&key).await.is_ok()
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn is_joined<'a>(&'a self, user_id: &'a UserId, room_id: &'a RoomId) -> bool {
let key = (user_id, room_id);
self.db.userroomid_joined.qry(&key).await.is_ok()
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> bool {
let key = (user_id, room_id);
self.db.userroomid_invitestate.qry(&key).await.is_ok()
}
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> bool {
let key = (user_id, room_id);
self.db.userroomid_leftstate.qry(&key).await.is_ok()
}
#[tracing::instrument(skip(self), level = "trace")]
pub async fn user_membership(
&self,
user_id: &UserId,
@ -683,7 +694,7 @@ impl Service {
/// distant future.
///
/// See <https://spec.matrix.org/latest/appendices/#routing>
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "trace")]
pub async fn servers_route_via(&self, room_id: &RoomId) -> Result<Vec<OwnedServerName>> {
let most_powerful_user_server = self
.services
@ -724,6 +735,7 @@ impl Service {
(cache.len(), cache.capacity())
}
#[tracing::instrument(level = "debug", skip_all)]
pub fn clear_appservice_in_room_cache(&self) {
self.appservice_in_room_cache
.write()
@ -731,6 +743,7 @@ impl Service {
.clear();
}
#[tracing::instrument(level = "debug", skip(self))]
pub async fn update_joined_count(&self, room_id: &RoomId) {
let mut joinedcount = 0_u64;
let mut invitedcount = 0_u64;
@ -784,11 +797,13 @@ impl Service {
.remove(room_id);
}
#[tracing::instrument(level = "debug", skip(self))]
fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) {
let key = (user_id, room_id);
self.db.roomuseroncejoinedids.put_raw(key, []);
}
#[tracing::instrument(level = "debug", skip(self, last_state, invite_via))]
pub async fn mark_as_invited(
&self,
user_id: &UserId,
@ -821,7 +836,7 @@ impl Service {
}
}
#[tracing::instrument(skip(self, servers), level = "debug")]
#[tracing::instrument(level = "debug", skip(self, servers))]
pub async fn add_servers_invite_via(&self, room_id: &RoomId, servers: Vec<OwnedServerName>) {
let mut servers: Vec<_> = self
.servers_invite_via(room_id)