@@ -27,7 +27,11 @@ import { PreSATPTransferResponse } from "../../generated/proto/cacti/satp/v02/se
2727import { stringify as safeStableStringify } from "safe-stable-stringify" ;
2828import { getMessageTypeName } from "../satp-utils" ;
2929import { MessageType } from "../../generated/proto/cacti/satp/v02/common/message_pb" ;
30- import { saveMessageInSessionData , setError } from "../session-utils" ;
30+ import {
31+ collectSessionAttributes ,
32+ saveMessageInSessionData ,
33+ setError ,
34+ } from "../session-utils" ;
3135import { BridgeManagerClientInterface } from "../../cross-chain-mechanisms/bridge/interfaces/bridge-manager-client-interface" ;
3236import { MonitorService } from "../../services/monitoring/monitor" ;
3337import { context , SpanStatusCode } from "@opentelemetry/api" ;
@@ -77,10 +81,6 @@ export class Stage1SATPHandler implements SATPHandler {
7781 const fnTag = `${ this . getHandlerIdentifier ( ) } #${ stepTag } ` ;
7882 const { span, context : ctx } = this . monitorService . startSpan ( fnTag ) ;
7983 return context . with ( ctx , async ( ) => {
80- const attributes : Record <
81- string ,
82- undefined | string | number | boolean | string [ ] | number [ ] | boolean [ ]
83- > = { } ;
8484 let session : SATPSession | undefined ;
8585 try {
8686 this . Log . debug ( `${ fnTag } , Transfer Proposal...` ) ;
@@ -124,33 +124,23 @@ export class Stage1SATPHandler implements SATPHandler {
124124 span . setAttribute ( "sessionId" , session . getSessionId ( ) ) ;
125125 span . setAttribute (
126126 "senderNetworkId" ,
127- session ? .getServerSessionData ( ) . senderAsset ?. networkId ?. id ?? "" ,
127+ session . getServerSessionData ( ) . senderAsset ?. networkId ?. id ?? "" ,
128128 ) ;
129129 span . setAttribute (
130130 "receiverNetworkId" ,
131- session ? .getServerSessionData ( ) . receiverAsset ?. networkId ?. id ?? "" ,
131+ session . getServerSessionData ( ) . receiverAsset ?. networkId ?. id ?? "" ,
132132 ) ;
133133
134- attributes . senderNetworkId =
135- session ?. getServerSessionData ( ) . senderAsset ?. networkId ?. id ||
136- undefined ;
137- attributes . receiverNetworkId =
138- session ?. getServerSessionData ( ) . receiverAsset ?. networkId ?. id ||
139- undefined ;
140- attributes . senderGatewayNetworkId =
141- session ?. getServerSessionData ( ) . senderGatewayNetworkId || undefined ;
142- attributes . receiverGatewayNetworkId =
143- session ?. getServerSessionData ( ) . recipientGatewayNetworkId ||
144- undefined ;
145- attributes . assetProfileId =
146- session ?. getServerSessionData ( ) . assetProfileId || undefined ;
147- attributes . sessionId = session ?. getSessionId ( ) || undefined ;
148- attributes . sourceLedgerAssetId =
149- session ?. getServerSessionData ( ) . sourceLedgerAssetId || undefined ;
150- attributes . recipientLedgerAssetId =
151- session ?. getServerSessionData ( ) . recipientLedgerAssetId || undefined ;
152- attributes . satp_phase = 1 ;
153- attributes . operation = "transferProposal" ;
134+ const attributes : Record <
135+ string ,
136+ | undefined
137+ | string
138+ | number
139+ | boolean
140+ | string [ ]
141+ | number [ ]
142+ | boolean [ ]
143+ > = collectSessionAttributes ( session , "server" ) ;
154144
155145 const startTimestamp =
156146 session . getServerSessionData ( ) . receivedTimestamps ?. stage1
@@ -164,7 +154,11 @@ export class Stage1SATPHandler implements SATPHandler {
164154 await this . monitorService . recordHistogram (
165155 "operation_duration" ,
166156 duration ,
167- attributes ,
157+ { ...attributes , satp_phase : 1 , operation : "transferProposal" } ,
158+ ) ;
159+ } else {
160+ this . Log . warn (
161+ `${ fnTag } , Missing timestamps for operation duration calculation` ,
168162 ) ;
169163 }
170164
@@ -198,7 +192,7 @@ export class Stage1SATPHandler implements SATPHandler {
198192 const fnTag = `${ this . getHandlerIdentifier ( ) } #${ stepTag } ` ;
199193 const { span, context : ctx } = this . monitorService . startSpan ( fnTag ) ;
200194 return context . with ( ctx , async ( ) => {
201- const attributes : Record <
195+ let attributes : Record <
202196 string ,
203197 undefined | string | number | boolean | string [ ] | number [ ] | boolean [ ]
204198 > = { } ;
@@ -215,31 +209,14 @@ export class Stage1SATPHandler implements SATPHandler {
215209 span . setAttribute ( "sessionId" , session . getSessionId ( ) ) ;
216210 span . setAttribute (
217211 "senderNetworkId" ,
218- session ? .getServerSessionData ( ) . senderAsset ?. networkId ?. id ?? "" ,
212+ session . getServerSessionData ( ) . senderAsset ?. networkId ?. id ?? "" ,
219213 ) ;
220214 span . setAttribute (
221215 "receiverNetworkId" ,
222- session ? .getServerSessionData ( ) . receiverAsset ?. networkId ?. id ?? "" ,
216+ session . getServerSessionData ( ) . receiverAsset ?. networkId ?. id ?? "" ,
223217 ) ;
224218
225- attributes . senderNetworkId =
226- session ?. getServerSessionData ( ) . senderAsset ?. networkId ?. id ||
227- undefined ;
228- attributes . receiverNetworkId =
229- session ?. getServerSessionData ( ) . receiverAsset ?. networkId ?. id ||
230- undefined ;
231- attributes . senderGatewayNetworkId =
232- session ?. getServerSessionData ( ) . senderGatewayNetworkId || undefined ;
233- attributes . receiverGatewayNetworkId =
234- session ?. getServerSessionData ( ) . recipientGatewayNetworkId ||
235- undefined ;
236- attributes . assetProfileId =
237- session ?. getServerSessionData ( ) . assetProfileId || undefined ;
238- attributes . sessionId = session ?. getSessionId ( ) || undefined ;
239- attributes . sourceLedgerAssetId =
240- session ?. getServerSessionData ( ) . sourceLedgerAssetId || undefined ;
241- attributes . recipientLedgerAssetId =
242- session ?. getServerSessionData ( ) . recipientLedgerAssetId || undefined ;
219+ attributes = collectSessionAttributes ( session , "server" ) ;
243220
244221 this . monitorService . updateCounter (
245222 "initiated_transactions" ,
@@ -277,28 +254,6 @@ export class Stage1SATPHandler implements SATPHandler {
277254 }
278255
279256 saveMessageInSessionData ( session . getServerSessionData ( ) , message ) ;
280-
281- attributes . senderNetworkId =
282- session ?. getServerSessionData ( ) . senderAsset ?. networkId ?. id ||
283- undefined ;
284- attributes . receiverNetworkId =
285- session ?. getServerSessionData ( ) . receiverAsset ?. networkId ?. id ||
286- undefined ;
287- attributes . senderGatewayNetworkId =
288- session ?. getServerSessionData ( ) . senderGatewayNetworkId || undefined ;
289- attributes . receiverGatewayNetworkId =
290- session ?. getServerSessionData ( ) . recipientGatewayNetworkId ||
291- undefined ;
292- attributes . assetProfileId =
293- session ?. getServerSessionData ( ) . assetProfileId || undefined ;
294- attributes . sessionId = session ?. getSessionId ( ) || undefined ;
295- attributes . sourceLedgerAssetId =
296- session ?. getServerSessionData ( ) . sourceLedgerAssetId || undefined ;
297- attributes . recipientLedgerAssetId =
298- session ?. getServerSessionData ( ) . recipientLedgerAssetId || undefined ;
299- attributes . satp_phase = 1 ;
300- attributes . operation = "transferCommence" ;
301-
302257 const startTimestamp =
303258 session . getServerSessionData ( ) . receivedTimestamps ?. stage1
304259 ?. transferCommenceRequestMessageTimestamp ;
@@ -311,7 +266,11 @@ export class Stage1SATPHandler implements SATPHandler {
311266 await this . monitorService . recordHistogram (
312267 "operation_duration" ,
313268 duration ,
314- attributes ,
269+ { ...attributes , satp_phase : 1 , operation : "transferCommence" } ,
270+ ) ;
271+ } else {
272+ this . Log . warn (
273+ `${ fnTag } , Missing timestamps for operation duration calculation` ,
315274 ) ;
316275 }
317276
@@ -325,26 +284,9 @@ export class Stage1SATPHandler implements SATPHandler {
325284 ) } `,
326285 ) ;
327286 setError ( session , MessageType . TRANSFER_COMMENCE_RESPONSE , error ) ;
328-
329- attributes . senderNetworkId =
330- session ?. getServerSessionData ( ) . senderAsset ?. networkId ?. id ||
331- undefined ;
332- attributes . receiverNetworkId =
333- session ?. getServerSessionData ( ) . receiverAsset ?. networkId ?. id ||
334- undefined ;
335- attributes . senderGatewayNetworkId =
336- session ?. getServerSessionData ( ) . senderGatewayNetworkId || undefined ;
337- attributes . receiverGatewayNetworkId =
338- session ?. getServerSessionData ( ) . recipientGatewayNetworkId ||
339- undefined ;
340- attributes . assetProfileId =
341- session ?. getServerSessionData ( ) . assetProfileId || undefined ;
342- attributes . sessionId = session ?. getSessionId ( ) || undefined ;
343- attributes . sourceLedgerAssetId =
344- session ?. getServerSessionData ( ) . sourceLedgerAssetId || undefined ;
345- attributes . recipientLedgerAssetId =
346- session ?. getServerSessionData ( ) . recipientLedgerAssetId || undefined ;
347- attributes . satp_phase = 1 ;
287+ if ( session ) {
288+ attributes = collectSessionAttributes ( session , "server" ) ;
289+ }
348290
349291 this . monitorService . updateCounter (
350292 "ongoing_transactions" ,
@@ -468,7 +410,7 @@ export class Stage1SATPHandler implements SATPHandler {
468410 const fnTag = `${ this . getHandlerIdentifier ( ) } #${ stepTag } ` ;
469411 const { span, context : ctx } = this . monitorService . startSpan ( fnTag ) ;
470412 return context . with ( ctx , async ( ) => {
471- const attributes : Record <
413+ let attributes : Record <
472414 string ,
473415 undefined | string | number | boolean | string [ ] | number [ ] | boolean [ ]
474416 > = { } ;
@@ -522,26 +464,9 @@ export class Stage1SATPHandler implements SATPHandler {
522464 ) ;
523465 setError ( session , MessageType . TRANSFER_COMMENCE_REQUEST , error ) ;
524466
525- attributes . senderNetworkId =
526- session ?. getClientSessionData ( ) ?. senderAsset ?. networkId ?. id ||
527- undefined ;
528- attributes . receiverNetworkId =
529- session ?. getClientSessionData ( ) ?. receiverAsset ?. networkId ?. id ||
530- undefined ;
531- attributes . senderGatewayNetworkId =
532- session ?. getClientSessionData ( ) ?. senderGatewayNetworkId ||
533- undefined ;
534- attributes . receiverGatewayNetworkId =
535- session ?. getClientSessionData ( ) ?. recipientGatewayNetworkId ||
536- undefined ;
537- attributes . assetProfileId =
538- session ?. getClientSessionData ( ) ?. assetProfileId || undefined ;
539- attributes . sessionId = session ?. getSessionId ( ) || undefined ;
540- attributes . sourceLedgerAssetId =
541- session ?. getClientSessionData ( ) ?. sourceLedgerAssetId || undefined ;
542- attributes . recipientLedgerAssetId =
543- session ?. getClientSessionData ( ) ?. recipientLedgerAssetId ||
544- undefined ;
467+ if ( session ) {
468+ attributes = collectSessionAttributes ( session , "client" ) ;
469+ }
545470 attributes . satp_phase = 1 ;
546471
547472 this . monitorService . updateCounter (
0 commit comments