Skip to content

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

Merged
ccharly merged 30 commits intomainfrom
cc/feat/perf-logging
Mar 23, 2026
Merged

feat(multichain-account-service): add local perf tracing (debug) + more traces#8244
ccharly merged 30 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
Changes wrap and propagate the tracing callback through MultichainAccountService/MultichainAccountWallet and add new trace events around account creation/alignment; while largely observational, it touches core wallet/provider flows and timeout handling, so regressions could affect account operations.

Overview
Adds debug-only local performance tracing by introducing analytics/perf (plus timer) and conditionally wrapping the configured TraceCallback when DEBUG enables the package logger.

Expands tracing coverage and structure: new TraceName entries and helpers (toProviderDataTraces, toCreateAccountsV2DataTraces), traces around wallet alignment and group creation, and provider-side traces for Snap createAccount v1 vs batched createAccounts v2.

Refactors withTimeout to accept a thunk (() => Promise) and updates all call sites accordingly; updates/extends tests to validate trace propagation/wrapping and deferred alignment behavior, and removes the old constants/traces.ts in favor of analytics/traces.

Written by Cursor Bugbot for commit 750e8aa. 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.

gantunesr
gantunesr previously approved these changes Mar 23, 2026
Copy link
Member

@gantunesr gantunesr left a comment

Choose a reason for hiding this comment

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

looks good

@ccharly ccharly added this pull request to the merge queue Mar 23, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 23, 2026
Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com>
@ccharly ccharly enabled auto-merge March 23, 2026 10:43
@ccharly ccharly added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 902248b Mar 23, 2026
326 checks passed
@ccharly ccharly deleted the cc/feat/perf-logging branch March 23, 2026 11:30
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.

2 participants