Skip to content

Commit 4c7adf1

Browse files
committed
add logging
1 parent 5fc5ae7 commit 4c7adf1

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/api/routes/swap/swapRouter.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import {
1010
} from "@/common/utils/httpHandlers"
1111
import { findSwaps } from "@/swapService/runner"
1212
import type { SwapParams } from "@/swapService/types"
13-
import { ApiError, findToken, getSwapper } from "@/swapService/utils"
13+
import {
14+
ApiError,
15+
findToken,
16+
getSwapper,
17+
parseHrtimeToSeconds,
18+
} from "@/swapService/utils"
1419
import { StatusCodes } from "http-status-codes"
1520
import { InvalidAddressError } from "viem"
1621
import { z } from "zod"
@@ -66,7 +71,28 @@ swapRouter.get(
6671
validateRequest(getSwapSchema),
6772
async (req: Request, res: Response) => {
6873
try {
69-
const swaps = await findSwaps(parseRequest(req))
74+
const startTime = process.hrtime()
75+
const swapParams = parseRequest(req)
76+
const swaps = await findSwaps(swapParams)
77+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime))
78+
console.log("ROUTE EXECUTING")
79+
if (elapsedSeconds > 10) {
80+
console.log(
81+
`SLOW ROUTE [10]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
82+
)
83+
} else if (elapsedSeconds > 5) {
84+
console.log(
85+
`SLOW ROUTE [5]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
86+
)
87+
} else if (elapsedSeconds > 3) {
88+
console.log(
89+
`SLOW ROUTE [3]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
90+
)
91+
} else if (elapsedSeconds > 1) {
92+
console.log(
93+
`SLOW ROUTE [1]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
94+
)
95+
}
7096
return handleServiceResponse(
7197
ServiceResponse.success<SwapResponse>(swaps),
7298
res,

src/swapService/strategies/balmySDK/customSourceList.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LOG_SLOW_QUERY_TIMEOUT_SECONDS } from "@/swapService/config/constants"
2+
import { parseHrtimeToSeconds } from "@/swapService/utils"
23
import type {
34
IFetchService,
45
IProviderService,
@@ -7,6 +8,7 @@ import type {
78
SourceListQuoteResponse,
89
} from "@balmy/sdk"
910
import { LocalSourceList } from "@balmy/sdk/dist/services/quotes/source-lists/local-source-list"
11+
import { stringify } from "viem"
1012
import { CustomKyberswapQuoteSource } from "./sources/kyberswapQuoteSource"
1113
import { CustomLiFiQuoteSource } from "./sources/lifiQuoteSource"
1214
import { CustomMagpieQuoteSource } from "./sources/magpieQuoteSource"
@@ -107,13 +109,3 @@ export class CustomSourceList extends LocalSourceList {
107109
}
108110
}
109111
}
110-
111-
function parseHrtimeToSeconds(hrtime: [number, number]) {
112-
return Number((hrtime[0] + hrtime[1] / 1e9).toFixed(3))
113-
}
114-
115-
function stringify(obj: object) {
116-
return JSON.stringify(obj, (_, v) =>
117-
typeof v === "bigint" ? v.toString() : v,
118-
)
119-
}

src/swapService/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,7 @@ export function promiseWithTimeout(fn: any, timeoutSeconds: number) {
583583
),
584584
])
585585
}
586+
587+
export function parseHrtimeToSeconds(hrtime: [number, number]) {
588+
return Number((hrtime[0] + hrtime[1] / 1e9).toFixed(3))
589+
}

0 commit comments

Comments
 (0)