Skip to content

Commit

Permalink
Merge pull request #53 from codecov/spalmurray/sentry
Browse files Browse the repository at this point in the history
feat: Add Sentry error monitoring
  • Loading branch information
spalmurray-codecov authored Nov 21, 2024
2 parents 1f9a6a7 + 5003d60 commit a749f4a
Show file tree
Hide file tree
Showing 8 changed files with 1,733 additions and 355 deletions.
1,984 changes: 1,639 additions & 345 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@
"codecov.api.gitProvider": {
"type": "string",
"default": "github",
"enum": ["github", "github_enterprise", "gitlab", "gitlab_enterprise", "bitbucket", "bitbucket_server"],
"enum": [
"github",
"github_enterprise",
"gitlab",
"gitlab_enterprise",
"bitbucket",
"bitbucket_server"
],
"description": "Where are your repositories hosted?",
"order": 4
},
Expand All @@ -155,6 +162,8 @@
"lint": "eslint src --ext ts"
},
"dependencies": {
"@sentry/browser": "^8.39.0",
"@sentry/webpack-plugin": "^2.22.6",
"axios": "^1.6.2",
"fs-extra": "^11.2.0",
"request-light": "^0.7.0",
Expand Down
21 changes: 16 additions & 5 deletions src/coverage/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
workspace,
} from "vscode";
import axios from "axios";
import Sentry from "../sentry";

type Coverage =
| {
Expand Down Expand Up @@ -239,9 +240,14 @@ export function activateCoverage(context: ExtensionContext) {

window.onDidChangeActiveTextEditor(
(editor) => {
activeEditor = editor;
if (editor) {
updateDecorations();
try {
activeEditor = editor;
if (editor) {
updateDecorations();
}
} catch (e) {
Sentry.captureException(e);
throw e;
}
},
null,
Expand All @@ -250,8 +256,13 @@ export function activateCoverage(context: ExtensionContext) {

workspace.onDidSaveTextDocument(
(event) => {
if (activeEditor && event === activeEditor.document) {
updateDecorations();
try {
if (activeEditor && event === activeEditor.document) {
updateDecorations();
}
} catch (e) {
Sentry.captureException(e);
throw e;
}
},
null,
Expand Down
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { ExtensionContext } from "vscode";
import { activateCoverage } from "./coverage/coverage";
import { activateYAML } from "./yaml/yamlClientMain";
import Sentry from "./sentry";

export function activate(context: ExtensionContext) {
activateCoverage(context);
return activateYAML(context);
try {
activateCoverage(context);
return activateYAML(context);
} catch (e) {
Sentry.captureException(e);
throw e;
}
}
38 changes: 38 additions & 0 deletions src/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
BrowserClient,
defaultStackParser,
getDefaultIntegrations,
makeFetchTransport,
Scope,
} from "@sentry/browser";

// Sentry config
// Browser extensions (and vscode 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 sentryClient = new BrowserClient({
// @ts-ignore SENTRY_DSN is populated by Webpack at build time
dsn: SENTRY_DSN,
transport: makeFetchTransport,
stackParser: defaultStackParser,
integrations: sentryIntegrations,
});

const Sentry = new Scope();
Sentry.setClient(sentryClient);
sentryClient.init();

export default Sentry;
8 changes: 7 additions & 1 deletion src/yaml/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { IJSONSchemaCache } from "./json-schema-cache";
import { getJsonSchemaContent } from "./json-schema-content-provider";
import { joinPath } from "./paths";
import { validateAction } from "./validate";
import Sentry from "../sentry";

export interface ISchemaAssociations {
[pattern: string]: string[];
Expand Down Expand Up @@ -134,7 +135,12 @@ export async function startClient(
// Activate validator
const command = "codecov.validate";
const commandHandler = () => {
validateAction(context);
try {
validateAction(context);
} catch (e) {
Sentry.captureException(e);
throw e;
}
};

context.subscriptions.push(commands.registerCommand(command, commandHandler));
Expand Down
5 changes: 4 additions & 1 deletion src/yaml/json-schema-content-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
} from "request-light";
import { SchemaExtensionAPI } from "./schema-extension-api";
import type { IJSONSchemaCache } from "./json-schema-cache";
import Sentry from "../sentry";

export class JSONSchemaDocumentContentProvider
implements TextDocumentContentProvider {
implements TextDocumentContentProvider
{
constructor(
private readonly schemaCache: IJSONSchemaCache,
private readonly schemaApi: SchemaExtensionAPI
Expand Down Expand Up @@ -117,6 +119,7 @@ export async function getJsonSchemaContent(
}

function createReject(error: XHRResponse): Promise<string> {
Sentry.captureException(error);
return Promise.reject(
error.responseText ||
getErrorStatusDescription(error.status) ||
Expand Down
11 changes: 11 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

"use strict";

const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require("path");
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -55,6 +56,16 @@ const config = {
},
],
},
plugins: [
new webpack.DefinePlugin({
SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN),
}),
sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: "codecov",
project: "vscode",
}),
],
};

module.exports = [config];

0 comments on commit a749f4a

Please sign in to comment.