Skip to content

Commit

Permalink
Merge pull request #1069 from chromaui/jmhobbs/cap-2194-annotate-sent…
Browse files Browse the repository at this point in the history
…ry-with-tags

Annotate Sentry events
  • Loading branch information
jmhobbs authored Oct 2, 2024
2 parents ab380a0 + 3c893f4 commit 2fb4c35
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions node-src/errorMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Sentry.init({
tags: {
entrypoint: process.env.CI && process.env.GITHUB_RUN_ID ? 'action' : 'cli',
version: process.env.npm_package_version,
index_url: process.env.CHROMATIC_INDEX_URL,
},
},
beforeSend: filterErrorEvent,
Expand Down
7 changes: 6 additions & 1 deletion node-src/tasks/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ describe('announceBuild', () => {
};

it('creates a build on the index and puts it on context', async () => {
const build = { number: 1, status: 'ANNOUNCED' };
const build = {
number: 1,
status: 'ANNOUNCED',
id: 'announced-build-id',
app: { id: 'announced-build-app-id' },
};
const client = { runQuery: vi.fn() };
client.runQuery.mockReturnValue({ announceBuild: build });

Expand Down
8 changes: 8 additions & 0 deletions node-src/tasks/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/node';

import { emailHash } from '../lib/emailHash';
import { getPackageManagerName, getPackageManagerVersion } from '../lib/getPackageManager';
import { createTask, transitionTo } from '../lib/tasks';
Expand Down Expand Up @@ -52,8 +54,11 @@ export const setRuntimeMetadata = async (ctx: Context) => {
try {
const packageManager = await getPackageManagerName();
ctx.runtimeMetadata.packageManager = packageManager as any;
Sentry.setTag('packageManager', packageManager);

const packageManagerVersion = await getPackageManagerVersion(packageManager);
ctx.runtimeMetadata.packageManagerVersion = packageManagerVersion;
Sentry.setTag('packageManagerVersion', packageManagerVersion);
} catch (err) {
ctx.log.debug(`Failed to set runtime metadata: ${err.message}`);
}
Expand Down Expand Up @@ -101,6 +106,9 @@ export const announceBuild = async (ctx: Context) => {
{ retries: 3 }
);

Sentry.setTag('app_id', announcedBuild.app.id);
Sentry.setContext('build', { id: announcedBuild.id });

ctx.announcedBuild = announcedBuild;
ctx.isOnboarding =
announcedBuild.number === 1 || (announcedBuild.autoAcceptChanges && !autoAcceptChanges);
Expand Down
12 changes: 12 additions & 0 deletions node-src/tasks/storybookInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import * as Sentry from '@sentry/node';

import getStorybookInfo from '../lib/getStorybookInfo';
import { createTask, transitionTo } from '../lib/tasks';
import { Context } from '../types';
import { initial, pending, success } from '../ui/tasks/storybookInfo';

export const setStorybookInfo = async (ctx: Context) => {
ctx.storybook = (await getStorybookInfo(ctx)) as Context['storybook'];

if (ctx.storybook) {
if (ctx.storybook.version) {
Sentry.setTag('storybookVersion', ctx.storybook.version);
}
if (ctx.storybook.viewLayer) {
Sentry.setTag('storybookViewLayer', ctx.storybook.viewLayer);
}
Sentry.setContext('storybook', ctx.storybook);
}
};

export default createTask({
Expand Down

0 comments on commit 2fb4c35

Please sign in to comment.