-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Flask] bitrise pipelines #6645
Changes from 1 commit
99710ef
f621274
95fda8a
018ff06
3e0e16e
cd861a8
9b02f37
47b75d2
50a3475
5247447
5924596
7b275c4
56f03d4
69ccfe9
061b507
df55ec1
e82ff36
5727bc3
2acb01b
5ca20dd
5b6d2d8
48b71e8
575e326
2191e4c
17b6758
2a71962
37aeb8a
80aa292
78c4a01
da12ce0
fe3069e
f79aab3
9490d89
38d2dc6
1da8ac1
6dfcce6
cbd72aa
889d066
285b28c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* eslint-disable import/no-namespace */ | ||
import * as Sentry from '@sentry/react-native'; | ||
import { Dedupe, ExtraErrorData } from '@sentry/integrations'; | ||
import extractEthJsErrorMessage from './extractEthJsErrorMessage'; | ||
import extractEthJsErrorMessage from '../extractEthJsErrorMessage'; | ||
import DefaultPreference from 'react-native-default-preference'; | ||
import { AGREED, METRICS_OPT_IN } from '../constants/storage'; | ||
import { AGREED, METRICS_OPT_IN } from '../../constants/storage'; | ||
|
||
const METAMASK_ENVIRONMENT = process.env['METAMASK_ENVIRONMENT'] || 'local'; // eslint-disable-line dot-notation | ||
const METAMASK_BUILD_TYPE = process.env.METAMASK_BUILD_TYPE || 'main'; | ||
const METAMASK_BUILD_TYPE = process.env['METAMASK_BUILD_TYPE'] || 'main'; // eslint-disable-line dot-notation | ||
|
||
const ERROR_URL_ALLOWLIST = [ | ||
'cryptocompare.com', | ||
|
@@ -150,24 +150,54 @@ function sanitizeAddressesFromErrorMessages(report) { | |
}); | ||
} | ||
|
||
/** | ||
* Derives the Sentry environment based on input parameters. | ||
* This function is similar to the environment logic used in MetaMask extension. | ||
* - https://github.com/MetaMask/metamask-extension/blob/34375a57e558853aab95fe35d5f278aa52b66636/app/scripts/lib/setupSentry.js#L91 | ||
* | ||
* @param {boolean} isDev - Represents if the current environment is development (__DEV__ global variable). | ||
* @param {string} [metamaskEnvironment='local'] - The environment MetaMask is running in | ||
* (process.env.METAMASK_ENVIRONMENT). | ||
* It defaults to 'local' if not provided. | ||
* @param {string} [metamaskBuildType='main'] - The build type of MetaMask | ||
* (process.env.METAMASK_BUILD_TYPE). | ||
* It defaults to 'main' if not provided. | ||
* | ||
* @returns {string} - The Sentry environment. Possible values are 'development', 'local', | ||
* 'production', or a string in the format `${metamaskEnvironment}-${metamaskBuildType}`. | ||
* 'development' is returned if 'isDev' is true or 'metamaskEnvironment' is not provided. | ||
* 'metamaskEnvironment' is returned if 'metamaskBuildType' is 'main' or undefined. | ||
* `${metamaskEnvironment}-${metamaskBuildType}` is returned for other cases, | ||
* for example 'production-flask' or 'debug-flask'. | ||
*/ | ||
export function deriveSentryEnvironment( | ||
isDev, | ||
metamaskEnvironment = 'local', | ||
metamaskBuildType = 'main', | ||
) { | ||
const environment = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Thoughts on splitting this up onto multiple statements? The standard metamask ESLint config (not yet used here) disallows nested ternaries. They're a bit hard to read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have broken it up into multiple return statements in my latest commit. |
||
isDev || !metamaskEnvironment | ||
? 'development' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we include the build type even for development builds? Seems like it could be useful |
||
: metamaskBuildType === 'main' | ||
? metamaskEnvironment | ||
: `${metamaskEnvironment}-${metamaskBuildType}`; | ||
|
||
return environment; | ||
} | ||
|
||
// Setup sentry remote error reporting | ||
export function setupSentry() { | ||
const init = async () => { | ||
const dsn = process.env.MM_SENTRY_DSN; | ||
|
||
/* Similar to the environment logic we use on extension: | ||
- https://github.com/MetaMask/metamask-extension/blob/34375a57e558853aab95fe35d5f278aa52b66636/app/scripts/lib/setupSentry.js#L91 | ||
*/ | ||
const environment = | ||
__DEV__ || !METAMASK_ENVIRONMENT | ||
? 'development' | ||
: METAMASK_BUILD_TYPE === 'main' | ||
? METAMASK_ENVIRONMENT | ||
: `${METAMASK_ENVIRONMENT}-${METAMASK_BUILD_TYPE}`; | ||
|
||
const metricsOptIn = await DefaultPreference.get(METRICS_OPT_IN); | ||
|
||
const integrations = [new Dedupe(), new ExtraErrorData()]; | ||
const environment = deriveSentryEnvironment( | ||
__DEV__, | ||
METAMASK_ENVIRONMENT, | ||
METAMASK_BUILD_TYPE, | ||
); | ||
|
||
Sentry.init({ | ||
dsn, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable dot-notation */ | ||
import { deriveSentryEnvironment } from './sentryUtils'; | ||
|
||
describe('deriveSentryEnvironment', () => { | ||
test('should return production-flask for environment if __DEV__ is false, METAMASK_ENVIRONMENT is production, and METAMASK_BUILD_TYPE is flask', async () => { | ||
const METAMASK_ENVIRONMENT = 'production'; | ||
const METAMASK_BUILD_TYPE = 'flask'; | ||
const isDev = false; | ||
|
||
const env = deriveSentryEnvironment( | ||
isDev, | ||
METAMASK_ENVIRONMENT, | ||
METAMASK_BUILD_TYPE, | ||
); | ||
expect(env).toBe('production-flask'); | ||
}); | ||
|
||
test('should return local-flask for environment if __DEV__ is false, METAMASK_ENVIRONMENT is undefined, and METAMASK_BUILD_TYPE is flask', async () => { | ||
const METAMASK_BUILD_TYPE = 'flask'; | ||
const isDev = false; | ||
|
||
const env = deriveSentryEnvironment(isDev, undefined, METAMASK_BUILD_TYPE); | ||
expect(env).toBe('local-flask'); | ||
}); | ||
|
||
test('should return debug-flask for environment if __DEV__ is false, METAMASK_ENVIRONMENT is debug, and METAMASK_BUILD_TYPE is flask', async () => { | ||
const METAMASK_BUILD_TYPE = 'flask'; | ||
const METAMASK_ENVIRONMENT = 'debug'; | ||
const isDev = false; | ||
|
||
const env = deriveSentryEnvironment( | ||
isDev, | ||
METAMASK_ENVIRONMENT, | ||
METAMASK_BUILD_TYPE, | ||
); | ||
expect(env).toBe('debug-flask'); | ||
}); | ||
|
||
test('should return local for environment if __DEV__ is false, METAMASK_ENVIRONMENT is local, and METAMASK_BUILD_TYPE is undefined', async () => { | ||
const isDev = false; | ||
const METAMASK_ENVIRONMENT = 'local'; | ||
|
||
const env = deriveSentryEnvironment(isDev, METAMASK_ENVIRONMENT); | ||
expect(env).toBe('local'); | ||
}); | ||
|
||
test('should return local for environment if __DEV__ is false, and both METAMASK_ENVIRONMENT and METAMASK_BUILD_TYPE are undefined', async () => { | ||
const isDev = false; | ||
|
||
const env = deriveSentryEnvironment(isDev); | ||
expect(env).toBe('local'); | ||
}); | ||
|
||
test('should return production for environment if __DEV__ is false, METAMASK_ENVIRONMENT is production, and METAMASK_BUILD_TYPE is undefined', async () => { | ||
const METAMASK_ENVIRONMENT = 'production'; | ||
const isDev = false; | ||
|
||
const env = deriveSentryEnvironment(isDev, METAMASK_ENVIRONMENT, undefined); | ||
expect(env).toBe('production'); | ||
}); | ||
|
||
test('should return development for environment if __DEV__ is true', async () => { | ||
const isDev = true; | ||
|
||
const env = deriveSentryEnvironment(isDev, '', ''); | ||
expect(env).toBe('development'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it might be better to include less specifics here, so we don't have to update it each time we add a new environment