Skip to content

Commit

Permalink
Add Sentry reporting
Browse files Browse the repository at this point in the history
Errors are reported using `captureException`, and non-errors are added
as breadcrumbs. This means the non-error events won't be directly sent
to Sentry, but they will be included as context for any errors that do
occur.

Closes #1321
  • Loading branch information
Gudahtt committed Feb 18, 2020
1 parent c8bc08b commit aa8ee4d
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 13 deletions.
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ project.ext.react = [
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/@sentry/react-native/sentry.gradle"

/**
* Set this to true to create two separate APKs instead of one:
Expand Down Expand Up @@ -208,6 +209,7 @@ android {
}

dependencies {
implementation project(':@sentry_react-native')
implementation project(':react-native-sensors')
implementation project(':react-native-reanimated')
implementation project(':react-native-webview')
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/java/io/metamask/MainApplication.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.metamask;

import com.facebook.react.ReactApplication;
import io.sentry.RNSentryPackage;
import com.sensors.RNSensorsPackage;
import com.swmansion.reanimated.ReanimatedPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
Expand Down Expand Up @@ -49,6 +50,7 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNSentryPackage(),
new RNSensorsPackage(),
new ReanimatedPackage(),
new RNCWebViewPackage(),
Expand Down
5 changes: 5 additions & 0 deletions android/sentry.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defaults.url=https://sentry.io/
defaults.org=metamask
defaults.project=metamask-mobile
auth.token=f3a55b2e27454dd4aa1628a7ee7e71ae7e70ca0089e24ffeab8c5d6ae6f47369
cli.executable=node_modules/@sentry/cli/bin/sentry-cli
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'MetaMask'
include ':@sentry_react-native'
project(':@sentry_react-native').projectDir = new File(rootProject.projectDir, '../node_modules/@sentry/react-native/android')
include ':react-native-sensors'
project(':react-native-sensors').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sensors/android')
include ':react-native-reanimated'
Expand Down
8 changes: 6 additions & 2 deletions app/util/Logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

import { addBreadcrumb, captureException } from '@sentry/react-native';
import AsyncStorage from '@react-native-community/async-storage';

/**
Expand All @@ -21,7 +23,9 @@ export default class Logger {
args.unshift('[MetaMask DEBUG]:');
console.log.apply(null, args); // eslint-disable-line no-console
} else if (metricsOptIn === 'agreed') {
console.log(args);
addBreadcrumb({
message: JSON.stringify(args)
});
}
}

Expand All @@ -38,7 +42,7 @@ export default class Logger {
args.unshift('[MetaMask DEBUG]:');
console.warn(args); // eslint-disable-line no-console
} else if (metricsOptIn === 'agreed') {
console.log(args);
captureException(args);
}
}
}
20 changes: 20 additions & 0 deletions app/util/setupSentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { init } from '@sentry/react-native';
import { Dedupe, ExtraErrorData } from '@sentry/integrations';

const METAMASK_ENVIRONMENT = process.env['METAMASK_ENVIRONMENT']; // eslint-disable-line dot-notation
// const SENTRY_DSN = 'https://ae39e4b08d464bba9fbf121c85ccfca0@sentry.io/2299799'
const TEST_SENTRY_DSN = 'https://1cb0be9b81554de381b65ffa80874924@sentry.io/2453959';

// Setup sentry remote error reporting
export default function setupSentry() {
let environment = METAMASK_ENVIRONMENT;
if (__DEV__) {
environment = 'development';
}
init({
dsn: TEST_SENTRY_DSN,
debug: __DEV__,
environment,
integrations: [new Dedupe(), new ExtraErrorData()]
});
}
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import './shim.js';

import crypto from 'crypto'; // eslint-disable-line import/no-nodejs-modules, no-unused-vars
require('react-native-browser-polyfill'); // eslint-disable-line import/no-commonjs

import setupSentry from './app/util/setupSentry';
setupSentry();

import { AppRegistry, YellowBox } from 'react-native';
import Root from './app/components/Views/Root';
import { name } from './app.json';
Expand Down
47 changes: 45 additions & 2 deletions ios/MetaMask.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
};
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */; };
Expand Down Expand Up @@ -96,6 +95,8 @@
FD9BDCD5059C483EAE9C0160 /* libRNVectorIcons.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 70BCC86172F14AB2BF4DDA97 /* libRNVectorIcons.a */; };
FEA573B66E7541C5A06F7EE1 /* libRNCAsyncStorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 512F0EF98E9D4D0185343707 /* libRNCAsyncStorage.a */; };
2A27FC9EEF1F4FD18E658544 /* config.json in Resources */ = {isa = PBXBuildFile; fileRef = EF1C01B7F08047F9B8ADCFBA /* config.json */; };
1F350AF8ECD04C04A76C92C0 /* libRNSentry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E1888C6B981243669BA00002 /* libRNSentry.a */; };
E3F09DA4B9F147B8811B78BE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F19825C44D9D49838B8B39D4 /* libz.tbd */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -853,6 +854,9 @@
F9DFF7AC557B46B6BEFAA1C1 /* libRNShakeEvent.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNShakeEvent.a; sourceTree = "<group>"; };
FE3C9A2458A1416290DEDAD4 /* branch.json */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = branch.json; path = ../branch.json; sourceTree = "<group>"; };
EF1C01B7F08047F9B8ADCFBA /* config.json */ = {isa = PBXFileReference; name = "config.json"; path = "../app/fonts/config.json"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
70988A2A19B140A89BF69948 /* RNSentry.xcodeproj */ = {isa = PBXFileReference; name = "RNSentry.xcodeproj"; path = "../node_modules/@sentry/react-native/ios/RNSentry.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
E1888C6B981243669BA00002 /* libRNSentry.a */ = {isa = PBXFileReference; name = "libRNSentry.a"; path = "libRNSentry.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
F19825C44D9D49838B8B39D4 /* libz.tbd */ = {isa = PBXFileReference; name = "libz.tbd"; path = "usr/lib/libz.tbd"; sourceTree = SDKROOT; fileEncoding = undefined; lastKnownFileType = sourcecode.text-based-dylib-definition; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -899,6 +903,8 @@
CCD42AFF04EE46C481A5715C /* libRNCWebView.a in Frameworks */,
8F038E7D26A045499C0C2CDC /* libRNReanimated.a in Frameworks */,
0DAA03955C324BF9813B14EE /* libRNSensors.a in Frameworks */,
1F350AF8ECD04C04A76C92C0 /* libRNSentry.a in Frameworks */,
E3F09DA4B9F147B8811B78BE /* libz.tbd in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1327,6 +1333,7 @@
children = (
153C1A742217BCDC0088EFE0 /* JavaScriptCore.framework */,
2D16E6891FA4F8E400B85C8A /* libReact.a */,
F19825C44D9D49838B8B39D4 /* libz.tbd */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -1436,6 +1443,7 @@
243DFD20AE7F45D5BBB115E2 /* RNCWebView.xcodeproj */,
3F524C43670B4F7DBBBB4B5C /* RNReanimated.xcodeproj */,
CBAA0A8C106D459EA02E314B /* RNSensors.xcodeproj */,
70988A2A19B140A89BF69948 /* RNSentry.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down Expand Up @@ -1484,6 +1492,22 @@
name = Products;
sourceTree = "<group>";
};
57D0091455694796AAA21539 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
path = Application;
sourceTree = "<group>";
};
45C45F6CAB7F4405944D88B2 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
path = Application;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -1497,6 +1521,7 @@
13B07F8E1A680F5B00A75B9A /* Resources */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
15ACCA0022655C3A0063978B /* Embed Frameworks */,
A3FF5283B2184432BFF814EE /* Upload Debug Symbols to Sentry */,
);
buildRules = (
);
Expand Down Expand Up @@ -2372,7 +2397,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "#if [ \"${CONFIGURATION}\" == \"Debug\" ]; then\n# export SKIP_BUNDLING=true\n#fi\n\nexport NODE_BINARY=${which node}\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
shellScript = "export SENTRY_PROPERTIES=sentry.properties\n#if [ \"${CONFIGURATION}\" == \"Debug\" ]; then\n# export SKIP_BUNDLING=true\n#fi\n\nexport NODE_BINARY=${which node}\n../node_modules/@sentry/cli/bin/sentry-cli react-native xcode ../node_modules/react-native/scripts/react-native-xcode.sh\n";
};
15FDD86321B76696006B7C35 /* Override xcconfig files */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -2392,6 +2417,20 @@
shellPath = /bin/sh;
shellScript = "if [ -e ../.ios.env ]\nthen\n cp -rf ../.ios.env debug.xcconfig\n cp -rf ../.ios.env release.xcconfig\nelse\n cp -rf ../.ios.env.example debug.xcconfig\n cp -rf ../.ios.env.example release.xcconfig\nfi\n\n";
};
A3FF5283B2184432BFF814EE /* Upload Debug Symbols to Sentry */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
name = "Upload Debug Symbols to Sentry";
inputPaths = (
);
outputPaths = (
);
shellPath = /bin/sh;
shellScript = "export SENTRY_PROPERTIES=sentry.properties\n../node_modules/@sentry/cli/bin/sentry-cli upload-dsym";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -2490,6 +2529,7 @@
"$(SRCROOT)/../node_modules/react-native-webview/ios",
"$(SRCROOT)/../node_modules/react-native-reanimated/ios/**",
"$(SRCROOT)/../node_modules/react-native-sensors/ios/**",
"$(SRCROOT)/../node_modules/@sentry/react-native/ios/**",
);
INFOPLIST_FILE = MetaMask/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
Expand All @@ -2498,6 +2538,7 @@
"$(inherited)",
"\"$(SRCROOT)/MetaMask/System/Library/Frameworks\"",
"\"$(SRCROOT)/MetaMask\"",
"\"$(SRCROOT)/MetaMask\"",
);
LLVM_LTO = YES;
MARKETING_VERSION = 0.2.13;
Expand Down Expand Up @@ -2562,6 +2603,7 @@
"$(SRCROOT)/../node_modules/react-native-webview/ios",
"$(SRCROOT)/../node_modules/react-native-reanimated/ios/**",
"$(SRCROOT)/../node_modules/react-native-sensors/ios/**",
"$(SRCROOT)/../node_modules/@sentry/react-native/ios/**",
);
INFOPLIST_FILE = MetaMask/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
Expand All @@ -2570,6 +2612,7 @@
"$(inherited)",
"\"$(SRCROOT)/MetaMask/System/Library/Frameworks\"",
"\"$(SRCROOT)/MetaMask\"",
"\"$(SRCROOT)/MetaMask\"",
);
LLVM_LTO = YES;
MARKETING_VERSION = 0.2.13;
Expand Down
5 changes: 5 additions & 0 deletions ios/sentry.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defaults.url=https://sentry.io/
defaults.org=metamask
defaults.project=metamask-mobile
auth.token=f3a55b2e27454dd4aa1628a7ee7e71ae7e70ca0089e24ffeab8c5d6ae6f47369
cli.executable=node_modules/@sentry/cli/bin/sentry-cli
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"dependencies": {
"@react-native-community/async-storage": "1.2.0",
"@react-native-community/netinfo": "4.1.5",
"@sentry/integrations": "^5.11.1",
"@sentry/react-native": "1.2.2",
"@tradle/react-native-http": "2.0.1",
"@walletconnect/react-native": "1.0.0-beta.37",
"asyncstorage-down": "4.2.0",
Expand Down Expand Up @@ -273,7 +275,7 @@
"^.+\\.js$": "<rootDir>jest.preprocessor.js"
},
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|@react-navigation|@react-native-community|react-navigation|react-navigation-redux-helpers)"
"node_modules/(?!(jest-)?react-native|@react-navigation|@react-native-community|react-navigation|react-navigation-redux-helpers|@sentry)"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
Expand Down
Loading

0 comments on commit aa8ee4d

Please sign in to comment.