Skip to content

feat(multichain-account-service): add local perf tracing (debug) + more traces#8244

Open
ccharly wants to merge 27 commits intomainfrom
cc/feat/perf-logging
Open

feat(multichain-account-service): add local perf tracing (debug) + more traces#8244
ccharly wants to merge 27 commits intomainfrom
cc/feat/perf-logging

Conversation

@ccharly
Copy link
Contributor

@ccharly ccharly commented Mar 19, 2026

Explanation

Adding more perf tracing + a way to wrap Sentry perf logs with local debbuging, making it easier to get feedback when developping.

References

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Adds pervasive tracing wrappers (including optional performance timing) across wallet/group alignment and Snap account creation flows, and changes withTimeout to accept a thunk, which can subtly alter async timing/side effects. Main functional behavior should be unchanged, but instrumentation now wraps key operations and touches multiple providers/tests.

Overview
Adds local performance tracing (gated by DEBUG logger enablement) by introducing analytics/perf and auto-wrapping the configured trace callback in MultichainAccountService, then passing this trace down into MultichainAccountWallet and providers.

Expands trace coverage by adding new TraceName entries and wrapping key wallet operations (group creation and alignment, including post-/discovery alignment tags) plus Snap provider account creation paths (v1 and v2/batched) with richer trace data (provider set, group index/range).

Refactors provider timeout usage by changing withTimeout to take a callback returning a promise (avoiding eagerly-started work), and updates EVM/SOL/BTC/TRX discovery and Snap account creation call sites accordingly; updates/extends tests and moves TraceName from constants/traces into analytics/traces.

Written by Cursor Bugbot for commit a5709d7. This will update automatically on new commits. Configure here.

@ccharly ccharly changed the title Cc/feat/perf logging feat(multichain-account-service): add local perf tracing (debug) + more traces Mar 19, 2026
accounts: [[mockEvmAccount0, mockEvmAccount1, mockEvmAccount2]],
});

jest.spyOn(wallet, 'alignAccounts').mockResolvedValue(undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually had no effect!

Comment on lines +523 to +531
// We use a non-resolving mock for SOL provider because we want to verify
// that it's not called during group creation, but rather during the deferred alignment.
const {
promise: mockSolCreateAccountsPromise,
resolve: mockSolCreateAccountsResolve,
} = createDeferredPromise();
jest
.spyOn(solProvider, 'createAccounts')
.mockImplementationOnce(() => mockSolCreateAccountsPromise);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-wrote this logic since non-EVM post alignment is scheduled asynchronously, so it's not always reliable to have determinist behavior when you change async calls.

This should future-proof it in a more reliable way!

Comment on lines -656 to -662
const mockTrace = jest.fn().mockImplementation(async (request, fn) => {
expect(request.name).toBe(TraceName.SnapDiscoverAccounts);
expect(request.data).toStrictEqual({
provider: BTC_ACCOUNT_PROVIDER_NAME,
});
return await fn();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have new traces now for our providers, we cannot just expect this one.

Note

This comment applies to all our providers!

*/
export async function withTimeout<T>(
promise: Promise<T>,
fn: () => Promise<T>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to use a callback now, making it much easier to wrap the actual content in a trace call

@ccharly ccharly marked this pull request as ready for review March 19, 2026 20:19
@ccharly ccharly requested review from a team as code owners March 19, 2026 20:19
Comment on lines +75 to +76
SnapDiscoverAccounts = 'Snap Discover Accounts',
EvmDiscoverAccounts = 'EVM Discover Accounts',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially wrap those existing traces in new ones to match the new "trace naming" like ProviderDiscoverAccounts and then use the data.provider to filter them out differently? 🤔

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant