feat: added tracing for money-account-balance-service network requests - #9434
Merged
Merged
Conversation
…rapped network calls with traces
10 tasks
Contributor
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Kureev
approved these changes
Jul 9, 2026
4 tasks
pull Bot
pushed a commit
to dmrazzy/core
that referenced
this pull request
Jul 21, 2026
MetaMask#9451) Add a `trace` constructor callback to MoneyAccountApiDataService that emits best-effort backdated spans for all HTTP calls (fetchPositions, fetchInterest, fetchHistory, fetchRateHistory). Tracing is isolated from fetch/retry logic so trace failures never impact queries. Mirrors the approach used in money-account-balance-service (PR MetaMask#9434). ## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Additive, optional observability with isolated error handling; no changes to API contracts or core fetch/retry semantics beyond wrapping existing logic. > > **Overview** > Adds an optional **`trace`** constructor callback so consumers can observe Money Account API HTTP calls without changing fetch, cache, or retry behavior. > > Each of **`fetchPositions`**, **`fetchInterest`**, **`fetchHistory`**, and **`fetchRateHistory`** runs its network work through a shared **`#traceNetworkRequest`** helper that emits **best-effort backdated** spans with **`startTime`**, **`success`**, and **`errorName`** (when applicable). Traces fire only on **cache misses** (when the `queryFn` actually runs). Trace emission is wrapped so sync throws and async rejections are logged and **never** affect query results. > > New public types include **`MoneyAccountApiDataServiceOptions`**, **`MoneyAccountApiDataServiceTraceCallback`**, **`MoneyAccountApiDataServiceTraceRequest`**, and **`TRACES`** name constants; the changelog documents the feature. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit fa19ff9. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
Merged
10 tasks
pull Bot
pushed a commit
to Reality2byte/metamask-mobile
that referenced
this pull request
Jul 23, 2026
…etaMask#33701) ## **Description** Adds Sentry tracing instrumentation to `MoneyAccountApiDataService` network calls (`fetchPositions`, `fetchInterest`, `fetchHistory`, `fetchRateHistory`). Bumps `@metamask/money-account-api-data-service` to `^0.3.0` which exposes an optional `trace` constructor callback ([MetaMask/core#9451](MetaMask/core#9451)), then wires a Sentry adapter into the service init — matching the pattern already established in `money-account-balance-service-init.ts`. ### Changes - Bumped `@metamask/money-account-api-data-service` from `^0.2.0` to `^0.3.0` - Added `sentryTrace` adapter in `money-account-api-data-service-init.ts` that: - Forwards trace requests into the shared `trace()` utility (Sentry `startSpan`) - Tags spans with `op: TraceOperation.MoneyAccountDataFetch` for Sentry filtering - Includes `app_state` (foreground/background) in trace data for performance segmentation - Passes through service-provided `tags` and `data` (e.g. `success`, `errorName`) - Passed `trace: sentryTrace` to the `MoneyAccountApiDataService` constructor - Added unit tests covering trace callback forwarding, operation tagging, app state enrichment, and caller data preservation ## **Changelog** CHANGELOG entry: Instrument Money Account API data service HTTP calls with Sentry tracing ## **Related issues** Fixes: N/A Related: https://consensyssoftware.atlassian.net/browse/MUSD-1044 Related: - Core tracing PR: MetaMask/core#9451 - Balance service tracing (prior art): MetaMask/core#9434 ## **Manual testing steps** ```gherkin Feature: Sentry tracing for Money Account API calls Scenario: Traces appear in Sentry for API data service calls Given the user has metrics consent enabled And the user has a funded Money Account When the user navigates to Money home (triggering fetchPositions) Then a Sentry span is emitted with operation "money.account.data_fetch" And the span includes startTime, success, and app_state attributes Scenario: Trace failures do not impact queries Given Sentry is unreachable or throws internally When the user triggers a Money API fetch Then the balance still loads successfully And no user-facing error is shown ``` ## **Screenshots/Recordings** N/A — observability-only change with no visual impact ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. #### Performance checks (if applicable) - [ ] I've tested on Android - [ ] I've tested with a power user scenario - [x] I've instrumented key operations with Sentry traces for production performance metrics ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Observability-only wiring with no changes to fetch logic or user-facing behavior; pattern matches existing balance service tracing. > > **Overview** > Wires **Sentry tracing** into `MoneyAccountApiDataService` by bumping `@metamask/money-account-api-data-service` to **^0.3.0** and passing a new `sentryTrace` adapter at init time, mirroring the balance service pattern. > > The adapter forwards the package’s optional trace callback into the shared `trace()` helper, sets `op` to `TraceOperation.MoneyAccountDataFetch`, and enriches span data with **`app_state`** (or `unknown` when unset) while preserving caller `tags` and `data`. Unit tests cover constructor wiring, operation tagging, app state handling, data merge behavior, and callback forwarding. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e4a1f88. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Added optional tracing for network requests in money-account-balance-service.
Changes
tracearg to money-account-balance-service constructor.traceNetworkRequestwhich runs a network request and emits a best-effort backdated trace. Tracing failure does not impact our queries.traceNetworkRequestReferences
Fixes: MUSD-1140: Add Sentry tracing for money-account-balance-service network requests
Checklist
Note
Low Risk
Additive optional API with no-op default; tracing is isolated from fetch/retry logic and covered by tests, so balance and APY behavior should be unchanged when trace is not provided or fails.
Overview
Adds optional observability for
MoneyAccountBalanceServicevia a new constructortracecallback, aimed at wiring Sentry (or similar) without changing balance/APY behavior when tracing is omitted or fails.A private
#traceNetworkRequesthelper runs each real network call, then emits a backdated trace withstartTime,chainId,operation,success, and optionalerrorName/tokenAddress. Trace emission is best-effort (async, errors logged only); query failures still propagate, and cached hits do not trace.RPC and HTTP paths are wrapped: ERC-20
balanceOf, Accountantbase/getRate, Multicall3aggregate3, LensbalanceOfInAssets, and the Veda vault APYfetch. Named trace constants (TRACES) and exported types (MoneyAccountBalanceServiceOptions, trace callback/request) support consumers. Changelog and a broadtracingtest suite cover success, cache skip, trace callback failures, and failed requests.Reviewed by Cursor Bugbot for commit 975339c. Bugbot is set up for automated code reviews on this repo. Configure here.