Skip to content

test(e2e): Add E2E test for sourcemap processing pipeline with debug IDs #9243

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

Merged
merged 2 commits into from
Oct 13, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ jobs:
'create-next-app',
'create-remix-app',
'create-remix-app-v2',
'debug-id-sourcemaps',
'nextjs-app-dir',
'react-create-hash-router',
'react-router-6-use-routes',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://localhost:4873
@sentry-internal:registry=http://localhost:4873
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "debug-id-sourcemaps",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "rollup --config rollup.config.mjs",
"test": "vitest run",
"clean": "npx rimraf node_modules,pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm test"
},
"dependencies": {
"@sentry/node": "latest || *"
},
"devDependencies": {
"rollup": "^4.0.2",
"vitest": "^0.34.6",
"@sentry/rollup-plugin": "2.8.0"
},
"volta": {
"extends": "../../package.json"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'rollup';
import { sentryRollupPlugin } from '@sentry/rollup-plugin';

export default defineConfig({
input: './src/app.js',
external: ['@sentry/node'],
plugins: [
sentryRollupPlugin({
org: process.env.E2E_TEST_SENTRY_ORG_SLUG,
project: process.env.E2E_TEST_SENTRY_TEST_PROJECT,
authToken: process.env.E2E_TEST_AUTH_TOKEN,
}),
],
output: {
file: './dist/app.js',
compact: true,
format: 'cjs',
sourcemap: 'hidden',
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
});

const eventId = Sentry.captureException(new Error('Sentry Debug ID E2E Test Error'));

process.stdout.write(eventId);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Find symbolicated event on sentry 1`] = `
{
"colno": 41,
"contextLine": "const eventId = Sentry.captureException(new Error('Sentry Debug ID E2E Test Error'));",
"lineno": 8,
"postContext": [
"",
"process.stdout.write(eventId);",
],
"preContext": [
"Sentry.init({",
" environment: 'qa', // dynamic sampling bias to keep transactions",
" dsn: process.env.E2E_TEST_DSN,",
"});",
"",
],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { test } from 'vitest';
import childProcess from 'child_process';
import path from 'path';

const authToken = process.env.E2E_TEST_AUTH_TOKEN;
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
const sentryTestProject = process.env.E2E_TEST_SENTRY_TEST_PROJECT;
const EVENT_POLLING_TIMEOUT = 30_000;

test(
'Find symbolicated event on sentry',
async ({ expect }) => {
const eventId = childProcess.execSync(`node ${path.join(__dirname, '..', 'dist', 'app.js')}`, {
encoding: 'utf-8',
});

console.log(`Polling for error eventId: ${eventId}`);

let timedOut = false;
setTimeout(() => {
timedOut = true;
}, EVENT_POLLING_TIMEOUT);

while (!timedOut) {
await new Promise(resolve => setTimeout(resolve, 2000)); // poll every two seconds
const response = await fetch(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${eventId}/json/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

// Only allow ok responses or 404
if (!response.ok) {
expect(response.status).toBe(404);
continue;
}

const eventPayload = await response.json();
const frames = eventPayload.exception?.values?.[0]?.stacktrace?.frames;
const topFrame = frames[frames.length - 1];
expect({
preContext: topFrame?.pre_context,
contextLine: topFrame?.context_line,
postContext: topFrame?.post_context,
lineno: topFrame?.lineno,
colno: topFrame?.colno,
}).toMatchSnapshot();
return;
}

throw new Error('Test timed out');
},
{ timeout: EVENT_POLLING_TIMEOUT },
);