forked from lavina/lavina
add instrumentation
This commit is contained in:
parent
ec49489ef1
commit
799332946c
|
@ -59,6 +59,7 @@ pub struct PlayerConnection {
|
|||
}
|
||||
impl PlayerConnection {
|
||||
/// Handled in [Player::send_message].
|
||||
#[tracing::instrument(skip(self, body), name = "PlayerConnection::send_message")]
|
||||
pub async fn send_message(&mut self, room_id: RoomId, body: Str) -> Result<SendMessageResult> {
|
||||
let (promise, deferred) = oneshot();
|
||||
let cmd = ClientCommand::SendMessage { room_id, body, promise };
|
||||
|
@ -67,6 +68,7 @@ impl PlayerConnection {
|
|||
}
|
||||
|
||||
/// Handled in [Player::join_room].
|
||||
#[tracing::instrument(skip(self), name = "PlayerConnection::join_room")]
|
||||
pub async fn join_room(&mut self, room_id: RoomId) -> Result<JoinResult> {
|
||||
let (promise, deferred) = oneshot();
|
||||
let cmd = ClientCommand::JoinRoom { room_id, promise };
|
||||
|
@ -75,6 +77,7 @@ impl PlayerConnection {
|
|||
}
|
||||
|
||||
/// Handled in [Player::change_topic].
|
||||
#[tracing::instrument(skip(self, new_topic), name = "PlayerConnection::change_topic")]
|
||||
pub async fn change_topic(&mut self, room_id: RoomId, new_topic: Str) -> Result<()> {
|
||||
let (promise, deferred) = oneshot();
|
||||
let cmd = ClientCommand::ChangeTopic {
|
||||
|
@ -87,6 +90,7 @@ impl PlayerConnection {
|
|||
}
|
||||
|
||||
/// Handled in [Player::leave_room].
|
||||
#[tracing::instrument(skip(self), name = "PlayerConnection::leave_room")]
|
||||
pub async fn leave_room(&mut self, room_id: RoomId) -> Result<()> {
|
||||
let (promise, deferred) = oneshot();
|
||||
let cmd = ClientCommand::LeaveRoom { room_id, promise };
|
||||
|
@ -99,6 +103,7 @@ impl PlayerConnection {
|
|||
}
|
||||
|
||||
/// Handled in [Player::get_rooms].
|
||||
#[tracing::instrument(skip(self), name = "PlayerConnection::get_rooms")]
|
||||
pub async fn get_rooms(&self) -> Result<Vec<RoomInfo>> {
|
||||
let (promise, deferred) = oneshot();
|
||||
let cmd = ClientCommand::GetRooms { promise };
|
||||
|
@ -107,6 +112,7 @@ impl PlayerConnection {
|
|||
}
|
||||
|
||||
/// Handler in [Player::send_dialog_message].
|
||||
#[tracing::instrument(skip(self, body), name = "PlayerConnection::send_dialog_message")]
|
||||
pub async fn send_dialog_message(&self, recipient: PlayerId, body: Str) -> Result<()> {
|
||||
let (promise, deferred) = oneshot();
|
||||
let cmd = ClientCommand::SendDialogMessage {
|
||||
|
@ -400,6 +406,7 @@ impl Player {
|
|||
}
|
||||
|
||||
/// Handle an incoming update by changing the internal state and broadcasting it to all connections if necessary.
|
||||
#[tracing::instrument(skip(self, update), name = "Player::handle_update")]
|
||||
async fn handle_update(&mut self, update: Updates) {
|
||||
log::debug!(
|
||||
"Player received an update, broadcasting to {} connections",
|
||||
|
@ -461,6 +468,7 @@ impl Player {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "Player::join_room")]
|
||||
async fn join_room(&mut self, connection_id: ConnectionId, room_id: RoomId) -> JoinResult {
|
||||
if self.banned_from.contains(&room_id) {
|
||||
return JoinResult::Banned;
|
||||
|
@ -488,6 +496,7 @@ impl Player {
|
|||
JoinResult::Success(room_info)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "Player::leave_room")]
|
||||
async fn leave_room(&mut self, connection_id: ConnectionId, room_id: RoomId) {
|
||||
let room = self.my_rooms.remove(&room_id);
|
||||
if let Some(room) = room {
|
||||
|
@ -501,6 +510,7 @@ impl Player {
|
|||
self.broadcast_update(update, connection_id).await;
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, body), name = "Player::send_message")]
|
||||
async fn send_message(&mut self, connection_id: ConnectionId, room_id: RoomId, body: Str) -> SendMessageResult {
|
||||
let Some(room) = self.my_rooms.get(&room_id) else {
|
||||
tracing::info!("no room found");
|
||||
|
@ -518,6 +528,7 @@ impl Player {
|
|||
SendMessageResult::Success(created_at)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, new_topic), name = "Player::change_topic")]
|
||||
async fn change_topic(&mut self, connection_id: ConnectionId, room_id: RoomId, new_topic: Str) {
|
||||
let Some(room) = self.my_rooms.get(&room_id) else {
|
||||
tracing::info!("no room found");
|
||||
|
@ -528,6 +539,7 @@ impl Player {
|
|||
self.broadcast_update(update, connection_id).await;
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "Player::get_rooms")]
|
||||
async fn get_rooms(&self) -> Vec<RoomInfo> {
|
||||
let mut response = vec![];
|
||||
for (_, handle) in &self.my_rooms {
|
||||
|
@ -536,6 +548,7 @@ impl Player {
|
|||
response
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, body), name = "Player::send_dialog_message")]
|
||||
async fn send_dialog_message(&self, connection_id: ConnectionId, recipient: PlayerId, body: Str) {
|
||||
let created_at = chrono::Utc::now();
|
||||
self.dialogs.send_message(self.player_id.clone(), recipient.clone(), body.clone(), &created_at).await.unwrap();
|
||||
|
@ -552,6 +565,7 @@ impl Player {
|
|||
///
|
||||
/// This is called after handling a client command.
|
||||
/// Sending the update to the connection which sent the command is handled by the connection itself.
|
||||
#[tracing::instrument(skip(self, update), name = "Player::broadcast_update")]
|
||||
async fn broadcast_update(&self, update: Updates, except: ConnectionId) {
|
||||
for (a, b) in &self.connections {
|
||||
if ConnectionId(a) == except {
|
||||
|
|
|
@ -84,6 +84,7 @@ impl Storage {
|
|||
Ok(id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, content, created_at), name = "Storage::insert_message")]
|
||||
pub async fn insert_message(
|
||||
&mut self,
|
||||
room_id: u32,
|
||||
|
|
|
@ -138,12 +138,14 @@ impl RoomRegistryInner {
|
|||
#[derive(Clone)]
|
||||
pub struct RoomHandle(Arc<AsyncRwLock<Room>>);
|
||||
impl RoomHandle {
|
||||
#[tracing::instrument(skip(self, player_handle), name = "RoomHandle::subscribe")]
|
||||
pub async fn subscribe(&self, player_id: &PlayerId, player_handle: PlayerHandle) {
|
||||
let mut lock = self.0.write().await;
|
||||
tracing::info!("Adding a subscriber to a room");
|
||||
lock.subscriptions.insert(player_id.clone(), player_handle);
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "RoomHandle::add_member")]
|
||||
pub async fn add_member(&self, player_id: &PlayerId, player_storage_id: u32) {
|
||||
let mut lock = self.0.write().await;
|
||||
tracing::info!("Adding a new member to a room");
|
||||
|
@ -157,11 +159,13 @@ impl RoomHandle {
|
|||
lock.broadcast_update(update, player_id).await;
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "RoomHandle::unsubscribe")]
|
||||
pub async fn unsubscribe(&self, player_id: &PlayerId) {
|
||||
let mut lock = self.0.write().await;
|
||||
lock.subscriptions.remove(player_id);
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "RoomHandle::remove_member")]
|
||||
pub async fn remove_member(&self, player_id: &PlayerId, player_storage_id: u32) {
|
||||
let mut lock = self.0.write().await;
|
||||
tracing::info!("Removing a member from a room");
|
||||
|
@ -175,6 +179,7 @@ impl RoomHandle {
|
|||
lock.broadcast_update(update, player_id).await;
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, body, created_at), name = "RoomHandle::send_message")]
|
||||
pub async fn send_message(&self, player_id: &PlayerId, body: Str, created_at: DateTime<Utc>) {
|
||||
let mut lock = self.0.write().await;
|
||||
let res = lock.send_message(player_id, body, created_at).await;
|
||||
|
@ -183,6 +188,7 @@ impl RoomHandle {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self), name = "RoomHandle::get_room_info")]
|
||||
pub async fn get_room_info(&self) -> RoomInfo {
|
||||
let lock = self.0.read().await;
|
||||
RoomInfo {
|
||||
|
@ -192,6 +198,7 @@ impl RoomHandle {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, new_topic), name = "RoomHandle::set_topic")]
|
||||
pub async fn set_topic(&self, changer_id: &PlayerId, new_topic: Str) {
|
||||
let mut lock = self.0.write().await;
|
||||
let storage_id = lock.storage_id;
|
||||
|
@ -220,6 +227,7 @@ struct Room {
|
|||
storage: Storage,
|
||||
}
|
||||
impl Room {
|
||||
#[tracing::instrument(skip(self, body, created_at), name = "Room::send_message")]
|
||||
async fn send_message(&mut self, author_id: &PlayerId, body: Str, created_at: DateTime<Utc>) -> Result<()> {
|
||||
tracing::info!("Adding a message to room");
|
||||
self.storage
|
||||
|
@ -246,6 +254,7 @@ impl Room {
|
|||
///
|
||||
/// This is called after handling a client command.
|
||||
/// Sending the update to the player who sent the command is handled by the player actor.
|
||||
#[tracing::instrument(skip(self, update), name = "Room::broadcast_update")]
|
||||
async fn broadcast_update(&self, update: Updates, except: &PlayerId) {
|
||||
tracing::debug!("Broadcasting an update to {} subs", self.subscriptions.len());
|
||||
for (player_id, sub) in &self.subscriptions {
|
||||
|
|
|
@ -678,6 +678,7 @@ enum HandleResult {
|
|||
Leave,
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, name = "handle_incoming_message")]
|
||||
async fn handle_incoming_message(
|
||||
buffer: &str,
|
||||
config: &ServerConfig,
|
||||
|
|
Loading…
Reference in New Issue