Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

DEVPROD-931: Remove Bugsnag #425

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env-cmdrc.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"REACT_APP_LOBSTER_URL": "http://localhost:9090/lobster",
"REACT_APP_LOGKEEPER_URL": "http://localhost:8080",
"REACT_APP_SPRUCE_URL": "http://localhost:3000",
"REACT_APP_RELEASE_STAGE": "local",
"REACT_APP_BUGSNAG_API_KEY": "local"
"REACT_APP_RELEASE_STAGE": "local"
},
"devStaging": {
"REACT_APP_EVERGREEN_URL": "https://evergreen-staging.corp.mongodb.com",
Expand Down
2 changes: 0 additions & 2 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ functions:
shell: bash
script: |
echo "Generating .env-cmdrc.json"
REACT_APP_BUGSNAG_API_KEY=${REACT_APP_BUGSNAG_API_KEY} \
REACT_APP_SENTRY_AUTH_TOKEN=${REACT_APP_SENTRY_AUTH_TOKEN} \
REACT_APP_SENTRY_DSN=${REACT_APP_SENTRY_DSN} \
NEW_RELIC_ACCOUNT_ID=${NEW_RELIC_ACCOUNT_ID} \
Expand Down Expand Up @@ -344,7 +343,6 @@ functions:
shell: bash
script: |
${PREPARE_SHELL}
REACT_APP_BUGSNAG_API_KEY=${REACT_APP_BUGSNAG_API_KEY} \
BUCKET=${bucket} \
AWS_ACCESS_KEY_ID=${aws_key} \
AWS_SECRET_ACCESS_KEY=${aws_secret} \
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="ui-version" content="%GIT_SHA%">
<meta name="package-version" content="%APP_VERSION%" />
<link rel="shortcut icon" href="/favicon.ico" />
<title>Parsley</title>
<script type="text/javascript">
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.122",
"scripts": {
"bootstrap-logkeeper": "./scripts/bootstrap-logkeeper.sh",
"build": "tsc && . ./scripts/deploy/app-version.sh && GIT_SHA=`git rev-parse HEAD` vite build",
"build": "tsc && GIT_SHA=`git rev-parse HEAD` APP_VERSION=$npm_package_version vite build",
"build:local": "env-cmd -e local -r .env-cmdrc.local.json yarn build",
"build:beta": "env-cmd -e beta yarn build",
"build:staging": "env-cmd -e staging yarn build",
Expand All @@ -31,16 +31,13 @@
"start": "vite",
"verify-backend": "./scripts/verify-backend.sh",
"storybook": "storybook dev -p 6006",
"storybook:build": "./scripts/deploy/app-version.sh && env-cmd -e local -r .env-cmdrc.local.json storybook build",
"storybook:build": "env-cmd -e local -r .env-cmdrc.local.json storybook build",
"test": "jest --watchAll=false",
"test:watch": "jest --watch --verbose",
"upload-source-maps": "env-cmd -e production node ./scripts/deploy/upload-bugsnag-sourcemaps",
"postversion": "scripts/push-version.sh"
},
"dependencies": {
"@apollo/client": "3.7.12",
"@bugsnag/js": "7.20.2",
"@bugsnag/plugin-react": "7.19.0",
"@emotion/react": "11.11.0",
"@emotion/styled": "11.11.0",
"@leafygreen-ui/badge": "8.0.2",
Expand Down Expand Up @@ -84,7 +81,6 @@
"xss": "1.0.14"
},
"devDependencies": {
"@bugsnag/source-maps": "2.3.1",
"@emotion/babel-plugin": "11.11.0",
"@emotion/eslint-plugin": "11.11.0",
"@emotion/jest": "11.11.0",
Expand Down
18 changes: 0 additions & 18 deletions scripts/deploy/app-version.sh

This file was deleted.

8 changes: 1 addition & 7 deletions scripts/deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#!/bin/sh

# This script runs the aws cli command to deploy the app to s3
# It also uploads source maps to bugsnag
# This script runs the AWS CLI command to deploy the app to S3.

# Try this step and throw an error if it fails
echo "Deploying to S3"
aws s3 sync dist/ s3://"${BUCKET}"/ --acl public-read --follow-symlinks --delete --exclude .env-cmdrc.json
echo "Deployed to S3"

# If the above step succeeds, run this step
echo "Uploading source maps to Bugsnag"
./scripts/deploy/app-version.sh && node ./scripts/deploy/upload-bugsnag-sourcemaps.js
echo "Source maps uploaded to Bugsnag"
9 changes: 0 additions & 9 deletions scripts/deploy/upload-bugsnag-sourcemaps.js

This file was deleted.

1 change: 0 additions & 1 deletion scripts/setup-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const production = {
REACT_APP_PARSLEY_URL: "https://parsley.mongodb.com",
REACT_APP_RELEASE_STAGE: "production",
BUCKET: process.env.BUCKET,
REACT_APP_BUGSNAG_API_KEY: process.env.REACT_APP_BUGSNAG_API_KEY,
NEW_RELIC_ACCOUNT_ID: process.env.NEW_RELIC_ACCOUNT_ID,
NEW_RELIC_TRUST_KEY: process.env.NEW_RELIC_TRUST_KEY,
NEW_RELIC_AGENT_ID: process.env.NEW_RELIC_AGENT_ID,
Expand Down
8 changes: 6 additions & 2 deletions src/components/DetailsMenu/ButtonRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Icon from "components/Icon";
import { QueryParams } from "constants/queryParams";
import { useLogContext } from "context/LogContext";
import { useQueryParam } from "hooks/useQueryParam";
import { leaveBreadcrumb } from "utils/errorReporting";
import { SentryBreadcrumb, leaveBreadcrumb } from "utils/errorReporting";
import { copyToClipboard, getJiraFormat } from "utils/string";
import { DetailRow } from "../styles";

Expand Down Expand Up @@ -35,7 +35,11 @@ const ButtonRow: React.FC = () => {
disabled={!bookmarks.length}
leftGlyph={<Icon glyph="Copy" />}
onClick={async () => {
leaveBreadcrumb("copy-jira", { bookmarks }, "user");
leaveBreadcrumb(
"copy-jira",
{ bookmarks },
SentryBreadcrumb.User
);
await copyToClipboard(getJiraFormat(bookmarks, getLine));
setHasCopied(!hasCopied);
sendEvent({ name: "Clicked Copy To Jira" });
Expand Down
67 changes: 0 additions & 67 deletions src/components/ErrorHandling/Bugsnag.tsx

This file was deleted.

24 changes: 3 additions & 21 deletions src/components/ErrorHandling/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Component } from "react";
import Bugsnag from "@bugsnag/js";
import { ErrorBoundary as BugsnagErrorBoundary } from "./Bugsnag";
import ErrorFallback from "./ErrorFallback";
import { ErrorBoundary as SentryErrorBoundary, isInitialized } from "./Sentry";

Expand Down Expand Up @@ -38,26 +36,10 @@ export class DefaultErrorBoundary extends Component<
export const ErrorBoundary: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const bugsnagEnabled = Bugsnag.isStarted();
const sentryEnabled = isInitialized();

if (!bugsnagEnabled && !sentryEnabled) {
return <DefaultErrorBoundary>{children}</DefaultErrorBoundary>;
if (sentryEnabled) {
return <SentryErrorBoundary>{children}</SentryErrorBoundary>;
}

let errorBoundary = children;

if (sentryEnabled && bugsnagEnabled) {
errorBoundary = (
<BugsnagErrorBoundary>
<SentryErrorBoundary>{children}</SentryErrorBoundary>
</BugsnagErrorBoundary>
);
} else if (sentryEnabled) {
errorBoundary = <SentryErrorBoundary>{children}</SentryErrorBoundary>;
} else if (bugsnagEnabled) {
errorBoundary = <BugsnagErrorBoundary>{children}</BugsnagErrorBoundary>;
}

return <>{errorBoundary}</>; // eslint-disable-line react/jsx-no-useless-fragment
return <DefaultErrorBoundary>{children}</DefaultErrorBoundary>;
};
43 changes: 0 additions & 43 deletions src/components/ErrorHandling/initialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Bugsnag from "@bugsnag/js";
import BugsnagPluginReact from "@bugsnag/plugin-react";
import * as Sentry from "@sentry/react";
import { mockEnvironmentVariables } from "test_utils/utils";
import { initializeErrorHandling } from ".";
Expand All @@ -8,8 +6,6 @@ const { cleanup, mockEnv } = mockEnvironmentVariables();

describe("should initialize error handlers according to release stage", () => {
beforeEach(() => {
jest.spyOn(Bugsnag, "start").mockImplementation(jest.fn());
jest.spyOn(Bugsnag, "isStarted").mockImplementation(jest.fn(() => false));
jest.spyOn(Sentry, "init").mockImplementation(jest.fn());
jest
.spyOn(Sentry, "Replay")
Expand All @@ -23,29 +19,18 @@ describe("should initialize error handlers according to release stage", () => {

it("development", () => {
mockEnv("NODE_ENV", "development");
mockEnv("REACT_APP_VERSION", "1.0.0");
mockEnv("REACT_APP_RELEASE_STAGE", "production");
initializeErrorHandling();

expect(Bugsnag.start).not.toHaveBeenCalled();
expect(Sentry.init).not.toHaveBeenCalled();
});

it("production", () => {
mockEnv("NODE_ENV", "production");
mockEnv("REACT_APP_VERSION", "1.0.0");
mockEnv("REACT_APP_RELEASE_STAGE", "production");
mockEnv("REACT_APP_BUGSNAG_API_KEY", "fake-bugsnag-key");
mockEnv("REACT_APP_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Bugsnag.start).toHaveBeenCalledWith({
apiKey: "fake-bugsnag-key",
appVersion: "1.0.0",
plugins: [new BugsnagPluginReact()],
releaseStage: "production",
});

expect(Sentry.init).toHaveBeenCalledWith({
debug: false,
dsn: "fake-sentry-key",
Expand All @@ -60,18 +45,9 @@ describe("should initialize error handlers according to release stage", () => {
it("beta", () => {
mockEnv("REACT_APP_RELEASE_STAGE", "beta");
mockEnv("NODE_ENV", "production");
mockEnv("REACT_APP_VERSION", "1.0.0");
mockEnv("REACT_APP_BUGSNAG_API_KEY", "fake-bugsnag-key");
mockEnv("REACT_APP_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Bugsnag.start).toHaveBeenCalledWith({
apiKey: "fake-bugsnag-key",
appVersion: "1.0.0",
plugins: [new BugsnagPluginReact()],
releaseStage: "beta",
});

expect(Sentry.init).toHaveBeenCalledWith({
debug: true,
dsn: "fake-sentry-key",
Expand All @@ -85,19 +61,10 @@ describe("should initialize error handlers according to release stage", () => {

it("staging", () => {
mockEnv("NODE_ENV", "production");
mockEnv("REACT_APP_VERSION", "1.0.0");
mockEnv("REACT_APP_RELEASE_STAGE", "staging");
mockEnv("REACT_APP_BUGSNAG_API_KEY", "fake-bugsnag-key");
mockEnv("REACT_APP_SENTRY_DSN", "fake-sentry-key");
initializeErrorHandling();

expect(Bugsnag.start).toHaveBeenCalledWith({
apiKey: "fake-bugsnag-key",
appVersion: "1.0.0",
plugins: [new BugsnagPluginReact()],
releaseStage: "staging",
});

expect(Sentry.init).toHaveBeenCalledWith({
debug: true,
dsn: "fake-sentry-key",
Expand All @@ -112,8 +79,6 @@ describe("should initialize error handlers according to release stage", () => {

describe("should not initialize if the client is already running", () => {
beforeEach(() => {
jest.spyOn(Bugsnag, "start").mockImplementation(jest.fn());
jest.spyOn(Bugsnag, "isStarted").mockImplementation(jest.fn(() => false));
jest.spyOn(Sentry, "init").mockImplementation(jest.fn());
mockEnv("NODE_ENV", "production");
});
Expand All @@ -123,19 +88,11 @@ describe("should not initialize if the client is already running", () => {
cleanup();
});

it("does not initialize Bugsnag twice", () => {
jest.spyOn(Bugsnag, "isStarted").mockImplementation(jest.fn(() => true));
initializeErrorHandling();
expect(Bugsnag.start).not.toHaveBeenCalled();
expect(Sentry.init).toHaveBeenCalledTimes(1);
});

it("does not initialize Sentry twice", () => {
const mockClient = { getClient: jest.fn(() => true) };
// @ts-expect-error - Type error occurs because the entire return value of getCurrentHub is not mocked
jest.spyOn(Sentry, "getCurrentHub").mockReturnValue(mockClient);
initializeErrorHandling();
expect(Bugsnag.start).toHaveBeenCalledTimes(1);
expect(Sentry.init).not.toHaveBeenCalled();
});
});
6 changes: 0 additions & 6 deletions src/components/ErrorHandling/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import Bugsnag from "@bugsnag/js";
import { isProductionBuild } from "utils/environmentVariables";
import { initializeBugsnag } from "./Bugsnag";
import { initializeSentry, isInitialized } from "./Sentry";

export const initializeErrorHandling = () => {
if (!isProductionBuild()) {
return;
}

if (!Bugsnag.isStarted()) {
initializeBugsnag();
}

if (!isInitialized()) {
initializeSentry();
}
Expand Down
Loading