Skip to content

feat: added tracing for money-account-balance-service network requests - #9434

Merged
Matt561 merged 5 commits into
mainfrom
feat/money-account-balance-service-request-tracing
Jul 9, 2026
Merged

feat: added tracing for money-account-balance-service network requests#9434
Matt561 merged 5 commits into
mainfrom
feat/money-account-balance-service-request-tracing

Conversation

@Matt561

@Matt561 Matt561 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Explanation

Added optional tracing for network requests in money-account-balance-service.

Changes

  • Added optional trace arg to money-account-balance-service constructor.
  • Added traceNetworkRequest which runs a network request and emits a best-effort backdated trace. Tracing failure does not impact our queries.
  • Wrapped all RPC and HTTP calls with traceNetworkRequest

References

Fixes: MUSD-1140: Add Sentry tracing for money-account-balance-service network requests

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

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 MoneyAccountBalanceService via a new constructor trace callback, aimed at wiring Sentry (or similar) without changing balance/APY behavior when tracing is omitted or fails.

A private #traceNetworkRequest helper runs each real network call, then emits a backdated trace with startTime, chainId, operation, success, and optional errorName / 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, Accountant base / getRate, Multicall3 aggregate3, Lens balanceOfInAssets, and the Veda vault APY fetch. Named trace constants (TRACES) and exported types (MoneyAccountBalanceServiceOptions, trace callback/request) support consumers. Changelog and a broad tracing test 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.

@Matt561
Matt561 marked this pull request as ready for review July 9, 2026 15:06
@Matt561
Matt561 requested review from a team as code owners July 9, 2026 15:06
@Matt561
Matt561 temporarily deployed to default-branch July 9, 2026 15:06 — with GitHub Actions Inactive
@Matt561

Matt561 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-previews

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.4-preview-975339c60
@metamask-previews/accounts-controller@39.0.4-preview-975339c60
@metamask-previews/address-book-controller@7.1.2-preview-975339c60
@metamask-previews/ai-controllers@0.8.0-preview-975339c60
@metamask-previews/analytics-controller@1.2.1-preview-975339c60
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-975339c60
@metamask-previews/announcement-controller@8.1.0-preview-975339c60
@metamask-previews/app-metadata-controller@2.0.1-preview-975339c60
@metamask-previews/approval-controller@9.0.2-preview-975339c60
@metamask-previews/assets-controller@10.1.0-preview-975339c60
@metamask-previews/assets-controllers@109.3.1-preview-975339c60
@metamask-previews/authenticated-user-storage@3.0.0-preview-975339c60
@metamask-previews/base-controller@9.1.0-preview-975339c60
@metamask-previews/base-data-service@0.1.3-preview-975339c60
@metamask-previews/bitcoin-regtest-up@1.0.0-preview-975339c60
@metamask-previews/bridge-controller@77.3.2-preview-975339c60
@metamask-previews/bridge-status-controller@74.1.1-preview-975339c60
@metamask-previews/build-utils@3.0.4-preview-975339c60
@metamask-previews/chain-agnostic-permission@1.7.0-preview-975339c60
@metamask-previews/chomp-api-service@3.1.0-preview-975339c60
@metamask-previews/claims-controller@0.5.3-preview-975339c60
@metamask-previews/client-controller@1.0.1-preview-975339c60
@metamask-previews/client-utils@0.0.0-preview-975339c60
@metamask-previews/compliance-controller@2.1.0-preview-975339c60
@metamask-previews/composable-controller@12.0.1-preview-975339c60
@metamask-previews/config-registry-controller@0.4.1-preview-975339c60
@metamask-previews/connectivity-controller@0.2.0-preview-975339c60
@metamask-previews/controller-utils@12.3.0-preview-975339c60
@metamask-previews/core-backend@6.5.0-preview-975339c60
@metamask-previews/delegation-controller@3.0.2-preview-975339c60
@metamask-previews/earn-controller@12.2.2-preview-975339c60
@metamask-previews/eip-5792-middleware@3.0.4-preview-975339c60
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-975339c60
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-975339c60
@metamask-previews/ens-controller@19.1.5-preview-975339c60
@metamask-previews/eth-block-tracker@15.0.1-preview-975339c60
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-975339c60
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-975339c60
@metamask-previews/foundryup@1.0.1-preview-975339c60
@metamask-previews/gas-fee-controller@26.2.4-preview-975339c60
@metamask-previews/gator-permissions-controller@4.2.2-preview-975339c60
@metamask-previews/geolocation-controller@0.1.3-preview-975339c60
@metamask-previews/java-tron-up@1.0.0-preview-975339c60
@metamask-previews/json-rpc-engine@10.5.0-preview-975339c60
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-975339c60
@metamask-previews/keyring-controller@27.1.0-preview-975339c60
@metamask-previews/local-node-utils@1.0.0-preview-975339c60
@metamask-previews/logging-controller@8.0.2-preview-975339c60
@metamask-previews/message-manager@14.1.2-preview-975339c60
@metamask-previews/messenger@2.0.0-preview-975339c60
@metamask-previews/messenger-cli@0.2.0-preview-975339c60
@metamask-previews/money-account-api-data-service@0.1.0-preview-975339c60
@metamask-previews/money-account-balance-service@2.1.2-preview-975339c60
@metamask-previews/money-account-controller@0.3.3-preview-975339c60
@metamask-previews/money-account-upgrade-controller@2.2.1-preview-975339c60
@metamask-previews/multichain-account-service@12.0.0-preview-975339c60
@metamask-previews/multichain-api-middleware@4.0.1-preview-975339c60
@metamask-previews/multichain-network-controller@3.2.1-preview-975339c60
@metamask-previews/multichain-transactions-controller@7.1.1-preview-975339c60
@metamask-previews/name-controller@9.1.2-preview-975339c60
@metamask-previews/network-connection-banner-controller@0.1.0-preview-975339c60
@metamask-previews/network-controller@34.0.0-preview-975339c60
@metamask-previews/network-enablement-controller@5.4.1-preview-975339c60
@metamask-previews/notification-services-controller@25.0.0-preview-975339c60
@metamask-previews/passkey-controller@2.0.1-preview-975339c60
@metamask-previews/permission-controller@13.1.1-preview-975339c60
@metamask-previews/permission-log-controller@5.1.0-preview-975339c60
@metamask-previews/perps-controller@9.2.1-preview-975339c60
@metamask-previews/phishing-controller@17.2.0-preview-975339c60
@metamask-previews/platform-api-docs@0.0.0-preview-975339c60
@metamask-previews/polling-controller@16.0.8-preview-975339c60
@metamask-previews/preferences-controller@23.1.0-preview-975339c60
@metamask-previews/profile-metrics-controller@4.0.1-preview-975339c60
@metamask-previews/profile-sync-controller@28.2.0-preview-975339c60
@metamask-previews/ramps-controller@15.1.0-preview-975339c60
@metamask-previews/rate-limit-controller@7.0.1-preview-975339c60
@metamask-previews/react-data-query@0.2.1-preview-975339c60
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-975339c60
@metamask-previews/sample-controllers@5.0.3-preview-975339c60
@metamask-previews/seedless-onboarding-controller@10.0.3-preview-975339c60
@metamask-previews/selected-network-controller@26.1.5-preview-975339c60
@metamask-previews/shield-controller@5.1.2-preview-975339c60
@metamask-previews/signature-controller@39.2.7-preview-975339c60
@metamask-previews/smart-transactions-controller@25.0.0-preview-975339c60
@metamask-previews/snap-account-service@2.0.0-preview-975339c60
@metamask-previews/social-controllers@2.4.0-preview-975339c60
@metamask-previews/solana-test-validator-up@1.0.0-preview-975339c60
@metamask-previews/stellar-quickstart-up@0.0.0-preview-975339c60
@metamask-previews/storage-service@1.0.2-preview-975339c60
@metamask-previews/subscription-controller@6.2.0-preview-975339c60
@metamask-previews/transaction-controller@68.3.0-preview-975339c60
@metamask-previews/transaction-pay-controller@23.17.4-preview-975339c60
@metamask-previews/user-operation-controller@41.2.6-preview-975339c60
@metamask-previews/wallet@7.0.0-preview-975339c60
@metamask-previews/wallet-cli@0.0.0-preview-975339c60

@Matt561
Matt561 added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit d2113cc Jul 9, 2026
425 checks passed
@Matt561
Matt561 deleted the feat/money-account-balance-service-request-tracing branch July 9, 2026 15:45
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>
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants