Skip to content

Commit

Permalink
Merge pull request #93 from codecov/spalmurray/sentry-tracing-2
Browse files Browse the repository at this point in the history
Add sentry tracing attempt two
  • Loading branch information
spalmurray-codecov authored Nov 7, 2024
2 parents fcf95ba + 65e65d5 commit 3ec8392
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
50 changes: 34 additions & 16 deletions src/background/main.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,29 +10,46 @@ import {

async function main(): Promise<void> {
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: {
type: MessageType;
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);
4 changes: 2 additions & 2 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
],
};

0 comments on commit 3ec8392

Please sign in to comment.