-
Notifications
You must be signed in to change notification settings - Fork 11
Capture RPC calls metrics #691
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
Conversation
export function getClient( | ||
networkId: NetworkId, | ||
appName?: string, | ||
): PublicClient<ReturnType<typeof http>, Chain> { | ||
let client = clientsCache.get(networkId) | ||
if (client) { | ||
return client | ||
} | ||
|
||
const rpcUrl = getConfig().NETWORK_ID_TO_RPC_URL[networkId] | ||
function loggingHttpTransport( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to see you're tackling this! 👍
One early feedback I see in this implementation is that the app won't be correctly reported if there are more than 1 client requested for a given network:
const client = getClient('celo-mainnet', 'ubeswap');
// then in another app
const client2 = getClient('celo-mainnet', 'locked-celo');
// client2 is actually the same as client, because we cache them
// so client2 calls will be counted as 'ubeswap' instead of 'locked-celo'
The reason we cache them is because we take advantage of viem clients batching: https://github.com/mobilestack-xyz/hooks/blob/67da2c869492664781f71f6e63f0d40fad747c02/src/runtime/client.ts#L50-L61
And this actually makes it somewhat less clear how to count RPC calls by app.
For instance: 2 apps make an RPC call, but the real final RPC is 1 multicall containing both of them.
i.e. 1 single HTTP request.
The important thing is how many RPC HTTP requests are being made.
I guess if there's no simple way to breakdown by app because of batching, we could omit that breakdown and just count the number of RPC HTTP requests by network.
Closes: #597
RPC call data is captured by a custom transport.
Logs have the following format:
<networkId>: [<appName>] Call to <address>(multicall optional)
Example log:
ethereum-mainnet: [curve] Call to 0xca11bde05977b3631167028862be2a173976ca11(multicall)
A metrics object captures network and app specific metrics.