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

Commit

Permalink
Remove bugsnag to sentry conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Oct 17, 2023
1 parent 0c8d043 commit 61d3df2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 132 deletions.
6 changes: 3 additions & 3 deletions src/components/HistoryTable/HistoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef } from "react";
import throttle from "lodash.throttle";
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
import { useDimensions } from "hooks/useDimensions";
import { leaveBreadcrumb } from "utils/errorReporting";
import { leaveBreadcrumb, SentryBreadcrumb } from "utils/errorReporting";
import { types } from ".";
import { useHistoryTable } from "./HistoryTableContext";
import EndOfHistoryRow from "./HistoryTableRow/EndOfHistoryRow";
Expand Down Expand Up @@ -55,7 +55,7 @@ const HistoryTable: React.FC<HistoryTableProps> = ({
{
selectedCommit,
},
"process"
SentryBreadcrumb.UI
);
listRef.current.scrollToIndex(selectedCommit.rowIndex);
}
Expand All @@ -71,7 +71,7 @@ const HistoryTable: React.FC<HistoryTableProps> = ({
selectedCommit,
processedCommitCount,
},
"process"
SentryBreadcrumb.UI
);
loadMoreItems();
}
Expand Down
6 changes: 3 additions & 3 deletions src/context/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useContext, useMemo, useReducer } from "react";
import { environmentVariables } from "utils";
import { leaveBreadcrumb } from "utils/errorReporting";
import { leaveBreadcrumb, SentryBreadcrumb } from "utils/errorReporting";

const { getLoginDomain, getUiUrl } = environmentVariables;

Expand Down Expand Up @@ -66,13 +66,13 @@ const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
window.location.href = `${getLoginDomain()}/login`;
})
.catch((error) => {
leaveBreadcrumb("Logout failed", { error }, "user");
leaveBreadcrumb("Logout failed", { error }, SentryBreadcrumb.User);
});
},
dispatchAuthenticated: () => {
if (!state.isAuthenticated) {
dispatch({ type: "authenticated" });
leaveBreadcrumb("Authenticated", {}, "user");
leaveBreadcrumb("Authenticated", {}, SentryBreadcrumb.User);
}
},
}),
Expand Down
14 changes: 11 additions & 3 deletions src/gql/GQLWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { RetryLink } from "@apollo/client/link/retry";
import { routes } from "constants/routes";
import { useAuthDispatchContext } from "context/auth";
import { environmentVariables } from "utils";
import { leaveBreadcrumb, reportError } from "utils/errorReporting";
import {
leaveBreadcrumb,
reportError,
SentryBreadcrumb,
} from "utils/errorReporting";

const { getGQLUrl } = environmentVariables;

Expand Down Expand Up @@ -128,7 +132,11 @@ const authLink = (logout: () => void): ApolloLink =>
networkError.statusCode === 401 &&
window.location.pathname !== routes.login
) {
leaveBreadcrumb("Not Authenticated", { statusCode: 401 }, "user");
leaveBreadcrumb(
"Not Authenticated",
{ status_code: 401 },
SentryBreadcrumb.User
);
logout();
}
});
Expand Down Expand Up @@ -164,7 +172,7 @@ const authenticateIfSuccessfulLink = (
status: !response.errors ? "OK" : "ERROR",
errors: response.errors,
},
"request"
SentryBreadcrumb.HTTP
);
return response;
})
Expand Down
6 changes: 3 additions & 3 deletions src/pages/taskHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { MAINLINE_COMMITS_FOR_HISTORY } from "gql/queries";
import { usePageTitle } from "hooks";
import { string } from "utils";
import { leaveBreadcrumb } from "utils/errorReporting";
import { leaveBreadcrumb, SentryBreadcrumb } from "utils/errorReporting";
import BuildVariantSelector from "./BuildVariantSelector";
import ColumnHeaders from "./ColumnHeaders";
import TaskHistoryRow from "./TaskHistoryRow";
Expand Down Expand Up @@ -76,7 +76,7 @@ const TaskHistoryContents: React.FC = () => {
taskName,
numCommits: mainlineCommits.versions.length,
},
"process"
SentryBreadcrumb.UI
);
ingestNewCommits(mainlineCommits);
},
Expand All @@ -96,7 +96,7 @@ const TaskHistoryContents: React.FC = () => {
taskName,
skipOrderNumber: data.mainlineCommits?.nextPageOrderNumber,
},
"process"
SentryBreadcrumb.UI
);
refetch({
mainlineCommitsOptions: {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/variantHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { MAINLINE_COMMITS_FOR_HISTORY } from "gql/queries";
import { usePageTitle } from "hooks";
import { string } from "utils";
import { leaveBreadcrumb } from "utils/errorReporting";
import { leaveBreadcrumb, SentryBreadcrumb } from "utils/errorReporting";
import ColumnHeaders from "./ColumnHeaders";
import TaskSelector from "./TaskSelector";
import VariantHistoryRow from "./VariantHistoryRow";
Expand Down Expand Up @@ -74,7 +74,7 @@ const VariantHistoryContents: React.FC = () => {
variantName,
numCommits: mainlineCommits.versions.length,
},
"process"
SentryBreadcrumb.UI
);
ingestNewCommits(mainlineCommits);
},
Expand All @@ -94,7 +94,7 @@ const VariantHistoryContents: React.FC = () => {
variantName,
skipOrderNumber: data.mainlineCommits?.nextPageOrderNumber,
},
"process"
SentryBreadcrumb.UI
);
refetch({
mainlineCommitsOptions: {
Expand Down
41 changes: 11 additions & 30 deletions src/utils/errorReporting.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import Bugsnag from "@bugsnag/js";
import * as Sentry from "@sentry/react";
import { mockEnvironmentVariables } from "test_utils/utils";
import { leaveBreadcrumb, reportError } from "utils/errorReporting";
import {
leaveBreadcrumb,
reportError,
SentryBreadcrumb,
} from "utils/errorReporting";

const { cleanup, mockEnv } = mockEnvironmentVariables();

describe("error reporting", () => {
beforeEach(() => {
jest.spyOn(console, "error").mockImplementation(() => {});
jest.spyOn(Bugsnag, "notify");
jest.spyOn(Sentry, "captureException");
});
afterEach(() => {
Expand All @@ -29,28 +31,23 @@ describe("error reporting", () => {
err,
severity: "warning",
});
expect(Bugsnag.notify).not.toHaveBeenCalled();
expect(Sentry.captureException).not.toHaveBeenCalled();
});

it("should report errors to Bugsnag and Sentry when in production", () => {
it("should report errors to Sentry when in production", () => {
mockEnv("NODE_ENV", "production");
jest.spyOn(Bugsnag, "notify").mockImplementation(jest.fn());
jest.spyOn(Sentry, "captureException").mockImplementation(jest.fn());

const err = new Error("test error");
const result = reportError(err);
result.severe();
expect(Bugsnag.notify).toHaveBeenCalledWith(err, expect.any(Function));
expect(Sentry.captureException).toHaveBeenCalledWith(err);
result.warning();
expect(Bugsnag.notify).toHaveBeenLastCalledWith(err, expect.any(Function));
expect(Sentry.captureException).toHaveBeenCalledWith(err);
});

it("supports metadata field", () => {
mockEnv("NODE_ENV", "production");
jest.spyOn(Bugsnag, "notify").mockImplementation(jest.fn());
jest.spyOn(Sentry, "captureException").mockImplementation(jest.fn());
const err = {
message: "GraphQL Error",
Expand All @@ -60,18 +57,15 @@ describe("error reporting", () => {
const metadata = { customField: "foo" };
const result = reportError(err, metadata);
result.severe();
expect(Bugsnag.notify).toHaveBeenCalledWith(err, expect.any(Function));
expect(Sentry.captureException).toHaveBeenCalledWith(err);
result.warning();
expect(Bugsnag.notify).toHaveBeenLastCalledWith(err, expect.any(Function));
expect(Sentry.captureException).toHaveBeenCalledWith(err);
});
});

describe("breadcrumbs", () => {
beforeEach(() => {
jest.spyOn(console, "debug").mockImplementation(() => {});
jest.spyOn(Bugsnag, "leaveBreadcrumb");
jest.spyOn(Sentry, "addBreadcrumb");
});
afterEach(() => {
Expand All @@ -81,7 +75,7 @@ describe("breadcrumbs", () => {

it("should log breadcrumbs into console when not in production", () => {
const message = "my message";
const type = "error";
const type = SentryBreadcrumb.Error;
const metadata = { foo: "bar" };

leaveBreadcrumb(message, metadata, type);
Expand All @@ -90,26 +84,19 @@ describe("breadcrumbs", () => {
metadata,
type,
});
expect(Bugsnag.leaveBreadcrumb).not.toHaveBeenCalled();
expect(Sentry.addBreadcrumb).not.toHaveBeenCalled();
});

it("should report breadcrumbs to Bugsnag and Sentry when in production and convert Sentry breadcrumbs", () => {
it("should report breadcrumbs to Sentry when in production", () => {
jest.useFakeTimers().setSystemTime(new Date("2020-01-01"));
mockEnv("NODE_ENV", "production");
jest.spyOn(Bugsnag, "leaveBreadcrumb").mockImplementation(jest.fn());
jest.spyOn(Sentry, "addBreadcrumb").mockImplementation(jest.fn());

const message = "my message";
const type = "log";
const metadata = { statusCode: 401 };
const type = SentryBreadcrumb.Info;
const metadata = { status_code: 401 };

leaveBreadcrumb(message, metadata, type);
expect(Bugsnag.leaveBreadcrumb).toHaveBeenCalledWith(
message,
metadata,
type
);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
message,
type: "info",
Expand All @@ -123,11 +110,10 @@ describe("breadcrumbs", () => {
jest.useFakeTimers().setSystemTime(new Date("2020-01-01"));
jest.spyOn(console, "warn").mockImplementation(() => {});
mockEnv("NODE_ENV", "production");
jest.spyOn(Bugsnag, "leaveBreadcrumb").mockImplementation(jest.fn());
jest.spyOn(Sentry, "addBreadcrumb").mockImplementation(jest.fn());

const message = "navigation message";
const type = "navigation";
const type = SentryBreadcrumb.Navigation;
const metadata = {};

leaveBreadcrumb(message, metadata, type);
Expand All @@ -139,11 +125,6 @@ describe("breadcrumbs", () => {
2,
"Navigation breadcrumbs should include a 'to' metadata field."
);
expect(Bugsnag.leaveBreadcrumb).toHaveBeenCalledWith(
message,
metadata,
type
);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
message,
type,
Expand Down
Loading

0 comments on commit 61d3df2

Please sign in to comment.