Skip to content

Commit

Permalink
Use environment to determine cli vs. action in Sentry init
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhobbs committed Sep 13, 2024
1 parent e29e66e commit 2931f5b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
27 changes: 14 additions & 13 deletions action-src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import setup from '../node-src/errorMonitoring';
setup('action');
import '../node-src/errorMonitoring';

import { error, getInput, getMultilineInput, setFailed, setOutput } from '@actions/core';
import { context } from '@actions/github';
Expand All @@ -19,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 @@ -192,24 +191,26 @@ 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);
}).finally(() => Sentry.flush(1000));
run()
.catch((error_) => {
error(error_);
setFailed(error_.message);
})
.finally(() => Sentry.close(1000));
8 changes: 4 additions & 4 deletions bin-src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import setup from '../node-src/errorMonitoring';
setup('cli');
import '../node-src/errorMonitoring';

import { run } from '../node-src';
import * as Sentry from '@sentry/node';

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

export async function main(argv: string[]) {
try {
const { code } = await run({ argv });
process.exitCode = code;
} finally {
await Sentry.flush(1000);
await Sentry.close(1000);
}
}
26 changes: 12 additions & 14 deletions node-src/errorMonitoring.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as Sentry from '@sentry/node';

export default (environment: string) => {
Sentry.init({
dsn: 'https://4fa173db2ef3fb073b8ea153a5466d28@o4504181686599680.ingest.us.sentry.io/4507930289373184',
sampleRate: 1,
environment,
enabled: process.env.DISABLE_ERROR_MONITORING !== 'true',
enableTracing: false,
integrations: [],
initialScope: {
tags: {
version: process.env.npm_package_version,
},
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,
},
});
};
},
});

0 comments on commit 2931f5b

Please sign in to comment.