Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sentry tracing attempt two #93

Merged
merged 1 commit into from
Nov 7, 2024
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
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),
}),
],
};
Loading