Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add send method metrics #707

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions lib/rpc/SingleJsonRpcProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class SingleJsonRpcProvider extends StaticJsonRpcProvider {
try {
await this.getBlockNumber_EvaluateHealthiness()
} catch (error: any) {
this.log.error(`Encounter error for shadow call for evaluating healthiness: ${JSON.stringify(error)}`)
this.log.error({ error }, `Encounter error for shadow call for evaluating healthiness: ${JSON.stringify(error)}`)
// Swallow the error.
}
}
Expand All @@ -186,7 +186,7 @@ export class SingleJsonRpcProvider extends StaticJsonRpcProvider {
try {
await (this as any)[`${methodName}_EvaluateLatency`](...args)
} catch (error: any) {
this.log.error(`Encounter error for shadow evaluate latency call: ${JSON.stringify(error)}`)
this.log.error({ error }, `Encounter error for shadow evaluate latency call: ${JSON.stringify(error)}`)
// Swallow the error.
}
}
Expand Down Expand Up @@ -241,6 +241,10 @@ export class SingleJsonRpcProvider extends StaticJsonRpcProvider {
metric.putMetric(`${this.metricPrefix}_becomes_${newHealthiness}`, 1, MetricLoggerUnit.Count)
}

logSendMetrod(method: string) {
metric.putMetric(`${this.metricPrefix}_send_${method}`, 1, MetricLoggerUnit.Count)
}

private async wrappedFunctionCall(
callType: CallType,
fnName: string,
Expand All @@ -265,18 +269,11 @@ export class SingleJsonRpcProvider extends StaticJsonRpcProvider {
const result = await fn(...args)
perf.latencyInMs = Date.now() - perf.startTimestampInMs

if (this.url.startsWith('https://eth-mainnet-fast.g.alchemy.com') && perf.latencyInMs >= 500) {
this.log.warn(
`Provider call latency is high: provider: ${this.url}, fnName: ${fnName}, fn: ${fn}, args: ${JSON.stringify([
...args,
])}, latency: ${perf.latencyInMs}`
)
}

return result
} catch (error: any) {
perf.succeed = false
this.log.debug(
this.log.error(
{ error },
`Provider call failed: provider: ${this.url}, fnName: ${fnName}, fn: ${fn}, args: ${JSON.stringify([
...args,
])}, error details: ${JSON.stringify(error)}`
Expand Down Expand Up @@ -315,7 +312,10 @@ export class SingleJsonRpcProvider extends StaticJsonRpcProvider {
this.log.debug(`${this.providerId}: Successfully synced with DB and updated states`)
this.logDbSyncSuccess()
} catch (err: any) {
this.log.error(`${this.providerId}: Encountered unhandled error when sync provider state: ${JSON.stringify(err)}`)
this.log.error(
{ err },
`${this.providerId}: Encountered unhandled error when sync provider state: ${JSON.stringify(err)}`
)
this.logDbSyncFailure()
// Won't throw. A fail of sync won't stop us from serving requests.
} finally {
Expand Down Expand Up @@ -430,6 +430,7 @@ export class SingleJsonRpcProvider extends StaticJsonRpcProvider {
}

override send(method: string, params: Array<any>): Promise<any> {
this.logSendMetrod(method)
return this.wrappedFunctionCall(CallType.NORMAL, 'send', super.send.bind(this), method, params)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rpc/UniJsonRpcProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class UniJsonRpcProvider extends StaticJsonRpcProvider {
latency = Date.now() - start
return result
} catch (error: any) {
this.log.error(JSON.stringify(error))
this.log.error({ error }, JSON.stringify(error))
throw error
} finally {
this.lastUsedProvider = selectedProvider
Expand Down
Loading