@@ -81,8 +81,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
8181 client . data . userId = userId
8282 this . userIdToSocketMap . set ( userId , client )
8383 this . metricsService . setActiveSocketConnections ( this . userIdToSocketMap . size )
84+ this . metricsService . recordSocketConnectionEvent ( 'connect' )
8485 this . logger . log ( `[소켓 연결] userId: ${ userId } ` )
8586 } catch {
87+ this . metricsService . recordSocketConnectionEvent ( 'error' )
8688 this . logger . error ( `[소켓 연결 실패] - ${ client . id } ` )
8789 client . disconnect ( )
8890 }
@@ -107,6 +109,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
107109 if ( userId ) {
108110 this . userIdToSocketMap . delete ( userId )
109111 this . metricsService . setActiveSocketConnections ( this . userIdToSocketMap . size )
112+ this . metricsService . recordSocketConnectionEvent ( 'disconnect' )
110113 this . logger . log ( `[소켓 연결 해제] userId: ${ userId } ` )
111114 } else {
112115 this . logger . log ( `[소켓 연결 해제] - ${ client . id } ` )
@@ -118,6 +121,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
118121 @SubscribeMessage ( 'battle:join' )
119122 async joinBattle ( @MessageBody ( ) battleJoinRequestDto : BattleJoinRequestDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
120123 const stopTimer = this . metricsService . startSocketTimer ( 'battle:join' )
124+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:join' )
121125 try {
122126 const userId = this . getUserIdFromSocket ( client )
123127
@@ -145,8 +149,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
145149
146150 client . emit ( 'battle:joined' , { ...res } )
147151 stopTimer ( 'success' )
152+ stopActionTimer ( 'success' )
148153 } catch ( error ) {
149154 stopTimer ( 'error' )
155+ stopActionTimer ( 'error' )
150156 if ( error instanceof Error ) {
151157 client . emit ( 'battle:join:error' , {
152158 message : error . message ,
@@ -157,19 +163,27 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
157163
158164 @SubscribeMessage ( 'battle:leave' )
159165 async handleLeave ( @MessageBody ( ) dto : { battleId : string } , @ConnectedSocket ( ) client : SocketWithUserId ) {
166+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:leave' )
160167 const { battleId } = dto
161168 const userId = this . getUserIdFromSocket ( client )
162169 const battleRoomId = getBattleRoomId ( battleId )
163170
164- const result = await this . participationUseCase . leave ( userId , battleId )
165- client . data . battleId = undefined
171+ try {
172+ const result = await this . participationUseCase . leave ( userId , battleId )
173+ client . data . battleId = undefined
166174
167- this . server . to ( battleRoomId ) . emit ( 'battle:leaved' , result )
175+ this . server . to ( battleRoomId ) . emit ( 'battle:leaved' , result )
176+ stopActionTimer ( 'success' )
177+ } catch ( error ) {
178+ stopActionTimer ( 'error' )
179+ throw error
180+ }
168181 }
169182
170183 @SubscribeMessage ( 'battle:start' )
171184 async handleStart ( @MessageBody ( ) dto : BattleStartDto ) {
172185 const stopTimer = this . metricsService . startSocketTimer ( 'battle:start' )
186+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:start' )
173187 try {
174188 const { battleId } = dto
175189 await this . creationUseCase . start ( battleId )
@@ -178,15 +192,18 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
178192
179193 this . server . to ( battleRoomId ) . emit ( 'battle:started' )
180194 stopTimer ( 'success' )
195+ stopActionTimer ( 'success' )
181196 } catch ( error ) {
182197 stopTimer ( 'error' )
198+ stopActionTimer ( 'error' )
183199 throw error
184200 }
185201 }
186202
187203 @SubscribeMessage ( 'battle:attack' )
188204 async handleAttack ( @MessageBody ( ) dto : AttackRequestDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
189205 const stopTimer = this . metricsService . startSocketTimer ( 'battle:attack' )
206+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:attack' )
190207 try {
191208 const userId = this . getUserIdFromSocket ( client )
192209 const battleId : string = dto . battleId
@@ -197,8 +214,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
197214
198215 this . server . to ( teamRoom ) . emit ( 'battle:attack:created' , attack )
199216 stopTimer ( 'success' )
217+ stopActionTimer ( 'success' )
200218 } catch ( error ) {
201219 stopTimer ( 'error' )
220+ stopActionTimer ( 'error' )
202221 if ( error instanceof Error ) {
203222 client . emit ( 'battle:attack:error' , {
204223 message : error . message ,
@@ -210,6 +229,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
210229 @SubscribeMessage ( 'battle:defense' )
211230 async handleDefense ( @MessageBody ( ) dto : DefenseRequestDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
212231 const stopTimer = this . metricsService . startSocketTimer ( 'battle:defense' )
232+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:defense' )
213233 try {
214234 const userId = this . getUserIdFromSocket ( client )
215235 const battleId : string = dto . battleId
@@ -220,8 +240,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
220240
221241 this . server . to ( teamRoom ) . emit ( 'battle:defense:created' , defense )
222242 stopTimer ( 'success' )
243+ stopActionTimer ( 'success' )
223244 } catch ( error ) {
224245 stopTimer ( 'error' )
246+ stopActionTimer ( 'error' )
225247 if ( error instanceof Error ) {
226248 client . emit ( 'battle:defense:error' , {
227249 message : error . message ,
@@ -233,6 +255,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
233255 @SubscribeMessage ( 'battle:attack:vote' )
234256 async handleAttackVote ( @MessageBody ( ) dto : AttackVoteRequestDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
235257 const stopTimer = this . metricsService . startSocketTimer ( 'battle:attack:vote' )
258+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:attack:vote' )
236259 try {
237260 const userId = this . getUserIdFromSocket ( client )
238261 const battleId : string = dto . battleId
@@ -246,8 +269,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
246269 this . server . to ( teamRoom ) . emit ( 'battle:attack:voted' , update )
247270 } )
248271 stopTimer ( 'success' )
272+ stopActionTimer ( 'success' )
249273 } catch ( error ) {
250274 stopTimer ( 'error' )
275+ stopActionTimer ( 'error' )
251276 if ( error instanceof Error ) {
252277 client . emit ( 'battle:attack:vote:error' , {
253278 message : error . message ,
@@ -259,6 +284,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
259284 @SubscribeMessage ( 'battle:defense:vote' )
260285 async handleDefenseVote ( @MessageBody ( ) dto : DefenseVoteRequestDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
261286 const stopTimer = this . metricsService . startSocketTimer ( 'battle:defense:vote' )
287+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:defense:vote' )
262288 try {
263289 const userId = this . getUserIdFromSocket ( client )
264290 const battleId : string = dto . battleId
@@ -272,8 +298,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
272298 this . server . to ( teamRoom ) . emit ( 'battle:defense:voted' , update )
273299 } )
274300 stopTimer ( 'success' )
301+ stopActionTimer ( 'success' )
275302 } catch ( error ) {
276303 stopTimer ( 'error' )
304+ stopActionTimer ( 'error' )
277305 if ( error instanceof Error ) {
278306 client . emit ( 'battle:defense:vote:error' , {
279307 message : error . message ,
@@ -285,6 +313,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
285313 @SubscribeMessage ( 'battle:user:skip' )
286314 async handlePhaseSkip ( @MessageBody ( ) dto : { skip : boolean ; battleId : string } , @ConnectedSocket ( ) client : SocketWithUserId ) {
287315 const stopTimer = this . metricsService . startSocketTimer ( 'battle:user:skip' )
316+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:user:skip' )
288317 const userId = this . getUserIdFromSocket ( client )
289318 try {
290319 const { skip, battleId } = dto
@@ -294,8 +323,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
294323 this . server . to ( battleRoomId ) . emit ( 'battle:user:skipped' , { totalSkips } )
295324
296325 stopTimer ( 'success' )
326+ stopActionTimer ( 'success' )
297327 } catch ( error ) {
298328 stopTimer ( 'error' )
329+ stopActionTimer ( 'error' )
299330 if ( error instanceof Error ) {
300331 client . emit ( 'battle:user:skip:error' , {
301332 message : error . message ,
@@ -362,6 +393,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
362393 @SubscribeMessage ( 'battle:chat' )
363394 async handleChat ( @MessageBody ( ) battleChatDto : BattleChatDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
364395 const stopTimer = this . metricsService . startSocketTimer ( 'battle:chat' )
396+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:chat' )
365397 try {
366398 const userId = this . getUserIdFromSocket ( client )
367399
@@ -374,8 +406,10 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
374406 // this.server.to(roomId).emit('battle:chatted', saved)
375407 this . server . to ( roomId ) . except ( client . id ) . emit ( 'battle:chatted' , saved )
376408 stopTimer ( 'success' )
409+ stopActionTimer ( 'success' )
377410 } catch ( error ) {
378411 stopTimer ( 'error' )
412+ stopActionTimer ( 'error' )
379413 if ( error instanceof Error ) {
380414 client . emit ( 'battle:chat:error' , { message : error . message } )
381415 }
@@ -385,15 +419,18 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect
385419 @SubscribeMessage ( 'battle:team:vote' )
386420 async handleTeamVote ( @MessageBody ( ) dto : BattleTeamVoteDto , @ConnectedSocket ( ) client : SocketWithUserId ) {
387421 const stopTimer = this . metricsService . startSocketTimer ( 'battle:team:vote' )
422+ const stopActionTimer = this . metricsService . startServiceActionTimer ( 'battle:team:vote' )
388423 try {
389424 const userId = this . getUserIdFromSocket ( client )
390425 const battleId : string = dto . battleId
391426 const team : BattleTeam = dto . team
392427
393428 await this . interactionUseCase . switchTeam ( battleId , userId , team )
394429 stopTimer ( 'success' )
430+ stopActionTimer ( 'success' )
395431 } catch ( error ) {
396432 stopTimer ( 'error' )
433+ stopActionTimer ( 'error' )
397434 if ( error instanceof Error ) {
398435 client . emit ( 'battle:team:vote:error' , { message : error . message } )
399436 }
0 commit comments