From 65e65d5de3ec3966a073638688ed5c3329449441 Mon Sep 17 00:00:00 2001 From: Spencer Murray Date: Thu, 7 Nov 2024 16:37:49 -0500 Subject: [PATCH] Add sentry tracing attempt 2 --- src/background/main.ts | 50 ++++++++++++++++++++++++++------------- webpack/webpack.common.js | 4 ++-- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/background/main.ts b/src/background/main.ts index 45b6041..5b89fca 100644 --- a/src/background/main.ts +++ b/src/background/main.ts @@ -1,4 +1,5 @@ import browser from "webextension-polyfill"; +import * as Sentry from "@sentry/browser"; import { MessageType } from "src/types"; import { Codecov } from "src/service"; @@ -9,6 +10,21 @@ import { async function main(): Promise { browser.runtime.onMessage.addListener(handleMessages); + + 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, + }); } async function handleMessages(message: { @@ -16,22 +32,24 @@ async function handleMessages(message: { payload: any; referrer?: string; }) { - 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); - } + return 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); + } + }); } main().catch(console.log); diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 80d492a..cc98076 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -50,7 +50,7 @@ module.exports = { browser: "webextensions-polyfill", }), new DefinePlugin({ - SENTRY_DSN: process.env.SENTRY_DSN - }) + SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN), + }), ], };