Skip to content

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Jun 24, 2025

This adds a new RPC method snap_trackError, which can be used to track errors in Sentry. It accepts a name, message, and stack, which should be turned into a proper Error class again on the client end before sending it to Sentry with Sentry.captureException.

To make the API a bit easier to use, I've added a getJsonError helper function which takes an error (string, Error class, or other value) and turns it into the properties expected by snap_trackError:

import { getJsonError } from '@metamask/snaps-sdk';

try {
  // ...
} catch (error) {
  await snap.request({
    method: 'snap_trackError',
    params: {
      error: getJsonError(error),
    },
  });
}

@Mrtenz Mrtenz changed the title Add snap_trackError method for error tracking through Sentry feat: Add snap_trackError method for error tracking through Sentry Jun 24, 2025
@Mrtenz Mrtenz force-pushed the mrtenz/snap_trackError branch from aa0e05f to 1ddb30c Compare June 24, 2025 09:54
@Mrtenz
Copy link
Member Author

Mrtenz commented Jun 24, 2025

@metamaskbot update-pr

Copy link

codecov bot commented Jun 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.23%. Comparing base (26b4c48) to head (49b4128).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3498   +/-   ##
=======================================
  Coverage   98.22%   98.23%           
=======================================
  Files         405      406    +1     
  Lines       11412    11453   +41     
  Branches     1779     1778    -1     
=======================================
+ Hits        11210    11251   +41     
  Misses        202      202           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Mrtenz Mrtenz marked this pull request as ready for review June 24, 2025 13:33
@Mrtenz Mrtenz requested a review from a team as a code owner June 24, 2025 13:33
@Mrtenz Mrtenz requested a review from FrederikBolding June 24, 2025 15:11
) {
return error.data;
const value = getObjectProperty(error, 'data');
if (value !== null && isValidJson(value) && !Array.isArray(value)) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to check for full JSON validity here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's what we did previously, I'm not sure if it's really needed, but kept it to be on the safe side.

@Mrtenz
Copy link
Member Author

Mrtenz commented Jun 25, 2025

@metamaskbot update-pr

@Mrtenz Mrtenz added this pull request to the merge queue Jun 25, 2025
Merged via the queue into main with commit 278d647 Jun 25, 2025
119 checks passed
@Mrtenz Mrtenz deleted the mrtenz/snap_trackError branch June 25, 2025 08:24
GuillaumeRx pushed a commit to MetaMask/metamask-extension that referenced this pull request Jun 30, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This adds support for the `snap_trackError` RPC method. See
MetaMask/snaps#3498 for more details.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/33866?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] 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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
GuillaumeRx pushed a commit to MetaMask/metamask-extension that referenced this pull request Jul 2, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This adds support for the `snap_trackError` RPC method. See
MetaMask/snaps#3498 for more details.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/33866?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] 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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
GuillaumeRx pushed a commit to MetaMask/metamask-extension that referenced this pull request Jul 3, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This adds support for the `snap_trackError` RPC method. See
MetaMask/snaps#3498 for more details.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/33866?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] 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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
xavier-brochard pushed a commit to MetaMask/snap-solana-wallet that referenced this pull request Jul 10, 2025
In order to track failed RPC requests, we've added an
`errorTrackingTransport` that wraps the existing transport pipeline to
track failed RPC requests. It integrates with the current architecture
and uses the new `snap_trackError` method to capture error details.
This transport wrapper acts as a lightweight solution, for us to have
better logs and debugging capabilities.
Reference: MetaMask/snaps#3498

What it does:

- Catches HTTP errors (4xx, 5xx)
- Detects JSON-RPC errors that come back in 2xx responses
- Preserves the original error flow so nothing breaks
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.

3 participants