Skip to content

Commit

Permalink
SENTRY_DSN_FAKE
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardBraham committed Aug 29, 2024
1 parent eafcc4e commit 5d93032
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
32 changes: 22 additions & 10 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const SENTRY_DSN_DEV = process.env.SENTRY_DSN_DEV;
const SENTRY_DSN_MMI = process.env.SENTRY_MMI_DSN;
/* eslint-enable prefer-destructuring */

// This is a fake DSN that can be used to test Sentry without sending data to the real Sentry server.
const SENTRY_DSN_FAKE = 'https://[email protected]/0000000';

export const ERROR_URL_ALLOWLIST = {
CRYPTOCOMPARE: 'cryptocompare.com',
COINGECKO: 'coingecko.com',
Expand Down Expand Up @@ -94,20 +97,23 @@ function getClientOptions() {
// we can safely turn them off by setting the `sendClientReports` option to
// `false`.
sendClientReports: false,
tracesSampleRate: METAMASK_DEBUG || process.env.CIRCLECI ? 1.0 : 0.01,
tracesSampleRate:
METAMASK_DEBUG || getManifestFlags().circleci ? 1.0 : 0.01,
transport: makeTransport,
};
}

function setCircleCiTags() {
Sentry.setTag('circleci.enabled', Boolean(process.env.CIRCLECI));

if (process.env.CIRCLECI) {
Sentry.setTag('circleci.branch', process.env.CIRCLE_BRANCH);
Sentry.setTag('circleci.buildNum', process.env.CIRCLE_BUILD_NUM);
Sentry.setTag('circleci.job', process.env.CIRCLE_JOB);
Sentry.setTag('circleci.nodeIndex', process.env.CIRCLE_NODE_INDEX);
Sentry.setTag('circleci.prNumber', process.env.CIRCLE_PR_NUMBER);
const { circleci } = getManifestFlags();

Sentry.setTag('circleci.enabled', circleci.enabled);

if (circleci.enabled) {
Sentry.setTag('circleci.branch', circleci.branch);
Sentry.setTag('circleci.buildNum', circleci.buildNum);
Sentry.setTag('circleci.job', circleci.job);
Sentry.setTag('circleci.nodeIndex', circleci.nodeIndex);
Sentry.setTag('circleci.prNumber', circleci.prNumber);
}
}

Expand Down Expand Up @@ -194,6 +200,10 @@ function getSentryEnvironment() {
}

function getSentryTarget() {
if (getManifestFlags().doNotForceSentryForThisTest) {
return SENTRY_DSN_FAKE;
}

if (METAMASK_ENVIRONMENT !== 'production') {
return SENTRY_DSN_DEV;
}
Expand All @@ -218,9 +228,11 @@ function getSentryTarget() {
* @returns `true` if MetaMetrics is enabled, `false` otherwise.
*/
async function getMetaMetricsEnabled() {
const flags = getManifestFlags();

if (
METAMASK_BUILD_TYPE === 'mmi' ||
(process.env.CIRCLECI && !getManifestFlags().doNotForceSentryForThisTest)
(flags.circleci && !flags.doNotForceSentryForThisTest)
) {
return true;
}
Expand Down
18 changes: 6 additions & 12 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,31 +271,25 @@ env:
# URL of security alerts API used to validate dApp requests
- SECURITY_ALERTS_API_URL: 'http://localhost:3000'

# Enables the notifications feature within the build:
# Enables the notifications feature within the build:
- NOTIFICATIONS: ''

- METAMASK_RAMP_API_CONTENT_BASE_URL: https://on-ramp-content.api.cx.metamask.io

###
# Meta variables
###

# Uses yaml anchors to DRY - https://juju.is/docs/sdk/yaml-anchors-and-aliases
- METAMASK_BUILD_TYPE_DEFAULT: *default

###
# Account Abstraction (EIP-4337)
###
- EIP_4337_ENTRYPOINT: null

- EIP_4337_ENTRYPOINT: null
###
# Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render
# This should NEVER be enabled in production since it slows down react
###
- ENABLE_WHY_DID_YOU_RENDER: false

###
# Env variables for CircleCI to send to Sentry
###
- CIRCLECI: false
- CIRCLE_BRANCH: ''
- CIRCLE_BUILD_NUM: -1
- CIRCLE_JOB: ''
- CIRCLE_NODE_INDEX: -1
- CIRCLE_PR_NUMBER: -1
13 changes: 12 additions & 1 deletion test/e2e/alterBuiltManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ function restoreBackupManifest() {
}
}

export function setManifestFlags(flags: object) {
export function setManifestFlags(flags: { circleci?: object } = {}) {
if (process.env.CIRCLECI) {
flags.circleci = {
enabled: true,
branch: process.env.CIRCLE_BRANCH,
buildNum: process.env.CIRCLE_BUILD_NUM,
job: process.env.CIRCLE_JOB,
nodeIndex: process.env.CIRCLE_NODE_INDEX,
prNumber: process.env.CIRCLE_PR_NUMBER,
};
}

const manifest = JSON.parse(
fs.readFileSync('dist/chrome/manifest.json').toString(),
);
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ async function withFixtures(options, testSuite) {
}
await mockServer.start(8000);

if (manifestFlags) {
setManifestFlags(manifestFlags);
}
setManifestFlags(manifestFlags);

driver = (await buildWebDriver(driverOptions)).driver;
webDriver = driver.driver;
Expand Down

0 comments on commit 5d93032

Please sign in to comment.