Skip to content

Commit ba1becb

Browse files
committed
Don't send errors to sentry if users have not opted-in to participate in metametrics
1 parent b60325c commit ba1becb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

app/scripts/background.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ function setupController(initState, initLangCode, remoteSourcePort) {
383383
// log error so we dont break the pipeline
384384
if (!dataPersistenceFailing) {
385385
dataPersistenceFailing = true;
386-
captureException(err);
386+
if (state.data.metamask.participateInMetaMetrics) {
387+
captureException(err);
388+
}
387389
}
388390
log.error('error setting state in local store:', err);
389391
}

app/scripts/lib/setupSentry.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ export default function setupSentry({ release, getState }) {
103103
environment,
104104
integrations: [new Dedupe(), new ExtraErrorData()],
105105
release,
106-
beforeSend: (report) => rewriteReport(report),
106+
beforeSend: (report) => {
107+
if (getState) {
108+
const appState = getState();
109+
if (!appState?.store?.metamask?.participateInMetaMetrics) {
110+
return null;
111+
}
112+
} else {
113+
return null;
114+
}
115+
return rewriteReport(report);
116+
},
107117
});
108118

109119
function rewriteReport(report) {

app/scripts/metamask-controller.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ export default class MetamaskController extends EventEmitter {
341341
},
342342
));
343343

344+
this.captureException = (...args) => {
345+
return this.getState()?.metamask?.participateInMetaMetrics
346+
? captureException(...args)
347+
: undefined;
348+
};
349+
344350
this.metaMetricsController = new MetaMetricsController({
345351
segment,
346352
preferencesStore: this.preferencesController.store,
@@ -357,7 +363,7 @@ export default class MetamaskController extends EventEmitter {
357363
version: this.platform.getVersion(),
358364
environment: process.env.METAMASK_ENVIRONMENT,
359365
initState: initState.MetaMetricsController,
360-
captureException,
366+
captureException: this.captureException.bind(this),
361367
});
362368

363369
this.on('update', (update) => {
@@ -595,7 +601,7 @@ export default class MetamaskController extends EventEmitter {
595601
this.accountTracker.store.getState().accounts || {},
596602
).length;
597603

598-
captureException(
604+
this.captureException(
599605
new Error(
600606
`Attempt to get permission specifications failed because their were ${accounts.length} accounts, but ${identitiesCount} identities, and the ${keyringTypesWithMissingIdentities} keyrings included accounts with missing identities. Meanwhile, there are ${accountTrackerCount} accounts in the account tracker.`,
601607
),

0 commit comments

Comments
 (0)