Skip to content

Commit

Permalink
Merge pull request #1036 from chromaui/jmhobbs/cap-2191-add-basic-sen…
Browse files Browse the repository at this point in the history
…try-integration-to-cli

Add basic sentry integration to cli
  • Loading branch information
jmhobbs authored Oct 1, 2024
2 parents 6fe6065 + d6f1e9d commit 980e0c1
Show file tree
Hide file tree
Showing 7 changed files with 763 additions and 16 deletions.
29 changes: 18 additions & 11 deletions action-src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import '../node-src/errorMonitoring';

import { error, getInput, getMultilineInput, setFailed, setOutput } from '@actions/core';
import { context } from '@actions/github';
import * as Sentry from '@sentry/node';
import path from 'path';

import { run as runNode } from '../node-src';
Expand All @@ -15,7 +18,7 @@ const maybe = (a: string | string[], b: any = undefined) => {

try {
return JSON.parse(a);
} catch (_err) {
} catch {
return a;
}
};
Expand Down Expand Up @@ -188,23 +191,27 @@ async function run() {
},
});

Object.entries(output).forEach(([key, value]) => setOutput(key, String(value)));
for (const [key, value] of Object.entries(output)) setOutput(key, String(value));

if (output.code !== 0) {
setFailed('non-zero exit code');
}

process.exit(output.code);
} catch (e) {
if (e.message) error(e.message);
if (e.stack) error(e.stack);
if (e.description) error(e.description);
} catch (error_) {
if (error_.message) error(error_.message);
if (error_.stack) error(error_.stack);
if (error_.description) error(error_.description);

setFailed(e.message);
setFailed(error_.message);
process.exit(1);
}
}
run().catch((e) => {
error(e);
setFailed(e.message);
});

run()
.catch((runError) => {
error(runError);
setFailed(runError.message);
Sentry.captureException(runError);
})
.finally(() => Sentry.flush(2500).finally(() => process.exit()));
16 changes: 13 additions & 3 deletions bin-src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import '../node-src/errorMonitoring';

import * as Sentry from '@sentry/node';

import { run } from '../node-src';

/**
Expand All @@ -6,7 +10,13 @@ import { run } from '../node-src';
* @param argv A list of arguments passed.
*/
export async function main(argv: string[]) {
const { code } = await run({ argv });

process.exit(code);
try {
const { code } = await run({ argv });
process.exitCode = code;
} catch (err) {
Sentry.captureException(err);
} finally {
await Sentry.flush(2500);
process.exit();
}
}
15 changes: 15 additions & 0 deletions node-src/errorMonitoring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://4fa173db2ef3fb073b8ea153a5466d28@o4504181686599680.ingest.us.sentry.io/4507930289373184',
sampleRate: 1,
environment: process.env.CI && process.env.GITHUB_RUN_ID ? 'action' : 'cli',
enabled: process.env.DISABLE_ERROR_MONITORING !== 'true',
enableTracing: false,
integrations: [],
initialScope: {
tags: {
version: process.env.npm_package_version,
},
},
});
3 changes: 3 additions & 0 deletions node-src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'any-observable/register/zen';

import * as Sentry from '@sentry/node';
import Listr from 'listr';
import readPkgUp from 'read-pkg-up';
import { v4 as uuid } from 'uuid';
Expand Down Expand Up @@ -161,6 +162,7 @@ export async function runAll(ctx: InitialContext) {
ctx.log.info('');

const onError = (err: Error | Error[]) => {
Sentry.captureException(err);
ctx.log.info('');
ctx.log.error(fatalError(ctx, [err].flat()));
ctx.extraOptions?.experimental_onTaskError?.(ctx, {
Expand Down Expand Up @@ -232,6 +234,7 @@ async function runBuild(ctx: Context) {
await new Listr(getTasks(ctx.options), options).run(ctx);
ctx.log.debug('Tasks completed');
} catch (err) {
Sentry.captureException(err);
endActivity(ctx);
if (err.code === 'ECONNREFUSED' || err.name === 'StatusCodeError') {
setExitCode(ctx, exitCodes.FETCH_ERROR);
Expand Down
2 changes: 2 additions & 0 deletions node-src/lib/checkForUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/node';
import semver from 'semver';
import { hasYarn } from 'yarn-or-npm';

Expand Down Expand Up @@ -45,6 +46,7 @@ export default async function checkForUpdates(ctx: Context) {
}
latestVersion = distributionTags.latest;
} catch (err) {
Sentry.captureException(err);
ctx.log.warn(`Could not retrieve package info from registry; skipping update check`);
ctx.log.warn(err);
return;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@auto-it/slack": "^11.1.6",
"@discoveryjs/json-ext": "^0.5.7",
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@sentry/node": "^8.30.0",
"@storybook/addon-essentials": "^8.1.5",
"@storybook/addon-webpack5-compiler-swc": "^1.0.3",
"@storybook/csf-tools": "^8.1.5",
Expand Down
Loading

0 comments on commit 980e0c1

Please sign in to comment.