From 2c243853119006281c38bf7cc48ba199d66a3a9a Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Wed, 14 Oct 2026 23:03:59 +0300 Subject: [PATCH] fix: separate T-Bank RPC network time from queue wait (WealthLedger/backend#81) --- src/common/logging/structured-logger.service.ts | 1 + src/integrations/tbank/tbank.client.spec.ts | 2 ++ src/integrations/tbank/tbank.client.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/common/logging/structured-logger.service.ts b/src/common/logging/structured-logger.service.ts index 095e896..a05baaa 100644 --- a/src/common/logging/structured-logger.service.ts +++ b/src/common/logging/structured-logger.service.ts @@ -18,6 +18,7 @@ const allowedFields = new Set([ 'grpcCode', 'headersReceived', 'method', + 'networkMs', 'operation', 'queueWaitMs', 'requestId', diff --git a/src/integrations/tbank/tbank.client.spec.ts b/src/integrations/tbank/tbank.client.spec.ts index a35da59..4f73c6b 100644 --- a/src/integrations/tbank/tbank.client.spec.ts +++ b/src/integrations/tbank/tbank.client.spec.ts @@ -165,6 +165,8 @@ describe('TbankClient operations', () => { operation: 'getAccounts', grpcCode: status.DEADLINE_EXCEEDED, queueWaitMs: 0, channelState: 'CONNECTING', headersReceived: false, })); + const [, , fields] = logger.event.mock.calls.at(-1) as [string, string, { networkMs: unknown }]; + expect(typeof fields.networkMs).toBe('number'); expect(JSON.stringify(logger.event.mock.calls)).not.toContain('secret'); } finally { jest.useRealTimers(); diff --git a/src/integrations/tbank/tbank.client.ts b/src/integrations/tbank/tbank.client.ts index c6100b9..e3be72a 100644 --- a/src/integrations/tbank/tbank.client.ts +++ b/src/integrations/tbank/tbank.client.ts @@ -64,6 +64,7 @@ type TbankClientService = Client & Record>; type RpcDiagnostics = { channelState?: string; headersReceived?: boolean; + networkMs?: number; queueWaitMs?: number; trackingId?: string; }; @@ -524,10 +525,13 @@ export class TbankClient { throw new ServiceUnavailableException({ code: TbankErrorCode.Unavailable }); } const response = await this.queue.run(() => { - diagnostics.queueWaitMs = Math.round(performance.now() - startedAt); + const sentAt = performance.now(); + diagnostics.queueWaitMs = Math.round(sentAt - startedAt); return this.request( token, client, method, request, diagnostics, - ); + ).finally(() => { + diagnostics.networkMs = Math.round(performance.now() - sentAt); + }); }); this.logger.event('debug', 'tbank.rpc.completed', { operation: method, -- 2.54.0