From 9c0194e5076494ef1e04939e7a2f1e9ea45ec50a Mon Sep 17 00:00:00 2001 From: Spencer Murray <159931558+spalmurray-codecov@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:47:51 -0500 Subject: [PATCH] Revert "Add sentry tracing to network requests" --- src/background/main.ts | 49 +++++++++------------------ src/content/common/sentry.ts | 21 +++++------- src/content/github/file/main.tsx | 58 ++++++++++++++++---------------- webpack/webpack.common.js | 4 +-- 4 files changed, 55 insertions(+), 77 deletions(-) diff --git a/src/background/main.ts b/src/background/main.ts index 98c2395..45b6041 100644 --- a/src/background/main.ts +++ b/src/background/main.ts @@ -6,23 +6,8 @@ import { registerContentScript, unregisterContentScriptIfExists, } from "./dynamic_content_scripts"; -import * as Sentry from "@sentry/browser"; async function main(): Promise { - Sentry.init({ - // @ts-ignore SENTRY_DSN is populated by Webpack at build time - dsn: SENTRY_DSN, - - integrations: [ - Sentry.browserTracingIntegration({ - // disable automatic span creation - instrumentNavigation: false, - instrumentPageLoad: false, - }), - ], - - tracesSampleRate: 1.0, - }); browser.runtime.onMessage.addListener(handleMessages); } @@ -31,24 +16,22 @@ async function handleMessages(message: { payload: any; referrer?: string; }) { - Sentry.startSpan({ name: message.type }, async () => { - switch (message.type) { - case MessageType.FETCH_COMMIT_REPORT: - return Codecov.fetchCommitReport(message.payload, message.referrer!); - case MessageType.FETCH_PR_COMPARISON: - return Codecov.fetchPRComparison(message.payload, message.referrer!); - case MessageType.FETCH_FLAGS_LIST: - return Codecov.listFlags(message.payload, message.referrer!); - case MessageType.FETCH_COMPONENTS_LIST: - return Codecov.listComponents(message.payload, message.referrer!); - case MessageType.CHECK_AUTH: - return Codecov.checkAuth(message.payload); - case MessageType.REGISTER_CONTENT_SCRIPTS: - return registerContentScript(message.payload); - case MessageType.UNREGISTER_CONTENT_SCRIPTS: - return unregisterContentScriptIfExists(message.payload); - } - }); + switch (message.type) { + case MessageType.FETCH_COMMIT_REPORT: + return Codecov.fetchCommitReport(message.payload, message.referrer!); + case MessageType.FETCH_PR_COMPARISON: + return Codecov.fetchPRComparison(message.payload, message.referrer!); + case MessageType.FETCH_FLAGS_LIST: + return Codecov.listFlags(message.payload, message.referrer!); + case MessageType.FETCH_COMPONENTS_LIST: + return Codecov.listComponents(message.payload, message.referrer!); + case MessageType.CHECK_AUTH: + return Codecov.checkAuth(message.payload); + case MessageType.REGISTER_CONTENT_SCRIPTS: + return registerContentScript(message.payload); + case MessageType.UNREGISTER_CONTENT_SCRIPTS: + return unregisterContentScriptIfExists(message.payload); + } } main().catch(console.log); diff --git a/src/content/common/sentry.ts b/src/content/common/sentry.ts index f0e2f4c..7eaefa4 100644 --- a/src/content/common/sentry.ts +++ b/src/content/common/sentry.ts @@ -4,24 +4,19 @@ import { getDefaultIntegrations, makeFetchTransport, Scope, -} from "@sentry/browser"; +} from '@sentry/browser'; // Sentry config -// Browser extensions must initialize Sentry a bit differently to avoid +// Browser extensions must initialize Sentry a bit differently to avoid // conflicts between Sentry instances should the site the extension is running // on also use Sentry. Read more here: // https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/ -const sentryIntegrations = getDefaultIntegrations({}).filter( - (defaultIntegration) => { - return ![ - "BrowserApiErrors", - "TryCatch", - "Breadcrumbs", - "GlobalHandlers", - ].includes(defaultIntegration.name); - } -); +const sentryIntegrations = getDefaultIntegrations({}).filter(defaultIntegration => { + return !['BrowserApiErrors', 'TryCatch', 'Breadcrumbs', 'GlobalHandlers'].includes( + defaultIntegration.name + ); +}); const sentryClient = new BrowserClient({ // @ts-ignore SENTRY_DSN is populated by Webpack at build time @@ -35,4 +30,4 @@ const Sentry = new Scope(); Sentry.setClient(sentryClient); sentryClient.init(); -export default Sentry; +export default Sentry diff --git a/src/content/github/file/main.tsx b/src/content/github/file/main.tsx index 2060a4e..3857b6d 100644 --- a/src/content/github/file/main.tsx +++ b/src/content/github/file/main.tsx @@ -35,7 +35,7 @@ import { } from "../common/fetchers"; import { print } from "src/utils"; import { isFileUrl } from "../common/utils"; -import Sentry from "../../common/sentry"; +import Sentry from '../../common/sentry'; const globals: { coverageReport?: FileCoverageReport; @@ -47,7 +47,7 @@ const globals: { prompt?: HTMLElement; } = {}; -init(); +init() function init(): Promise { // this event discovered by "reverse-engineering GitHub" @@ -73,10 +73,10 @@ async function main(): Promise { globals.coverageButton = createCoverageButton(); - process(metadata); + process(metadata) } catch (e) { - Sentry.captureException(e); - throw e; + Sentry.captureException(e) + throw e } } @@ -111,16 +111,17 @@ async function process(metadata: FileMetadata): Promise { previousElement: globals.coverageButton!, selectedOptions: selectedFlags, onClick: handleFlagClick, - }).then(({ button, list }) => { - globals.flagsButton = button; - globals.flagsDrop = new Drop({ - target: button, - content: list, - classes: "drop-theme-arrows codecov-z1 codecov-bg-white", - position: "bottom right", - openOn: "click", - }); - }); + }) + .then(({ button, list }) => { + globals.flagsButton = button; + globals.flagsDrop = new Drop({ + target: button, + content: list, + classes: "drop-theme-arrows codecov-z1 codecov-bg-white", + position: "bottom right", + openOn: "click", + }); + }) } const components = await getComponents(metadata); @@ -150,16 +151,17 @@ async function process(metadata: FileMetadata): Promise { previousElement: globals.coverageButton!, onClick: handleComponentClick, selectedOptions: selectedComponents, - }).then(({ button, list }) => { - globals.componentsButton = button; - globals.componentsDrop = new Drop({ - target: button, - content: list, - classes: "drop-theme-arrows codecov-z1 codecov-bg-white", - position: "bottom right", - openOn: "click", - }); - }); + }) + .then(({ button, list }) => { + globals.componentsButton = button; + globals.componentsDrop = new Drop({ + target: button, + content: list, + classes: "drop-theme-arrows codecov-z1 codecov-bg-white", + position: "bottom right", + openOn: "click", + }); + }) } let coverageReportResponses: Array; @@ -239,9 +241,7 @@ async function promptPastReport(metadata: FileMetadata): Promise { const matches = regexp.exec(response.commit_file_url); const commit = matches?.groups?.commit; if (!commit) { - throw new Error( - "Could not parse commit hash from response for past coverage report" - ); + throw new Error("Could not parse commit hash from response for past coverage report") } const link = document.URL.replace( `blob/${metadata.branch}`, @@ -260,7 +260,7 @@ function createPrompt(child: any) { const ref = document.querySelector('[data-testid="latest-commit"]') ?.parentElement?.parentElement; if (!ref) { - throw new Error("Could not find reference element to render prompt"); + throw new Error("Could not find reference element to render prompt") } const prompt =
{child}
; return ref.insertAdjacentElement("afterend", prompt) as HTMLElement; diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index cc98076..80d492a 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -50,7 +50,7 @@ module.exports = { browser: "webextensions-polyfill", }), new DefinePlugin({ - SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN), - }), + SENTRY_DSN: process.env.SENTRY_DSN + }) ], };