Skip to content

Commit

Permalink
Use inspect and .txt. ext for Sentry server events
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Apr 27, 2024
1 parent 60ba722 commit 849e6fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
@@ -1,5 +1,6 @@
import * as Sentry from '@sentry/remix';
import fsp from 'node:fs/promises';
import util from 'node:util';

Sentry.init({
tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
Expand All @@ -8,10 +9,7 @@ Sentry.init({
beforeSendTransaction: async e => {
if (process.env.SNAPSHOT_SERVER_EVENTS) {
// Snapshot events for inspections and e2e tests purposes.
// Note how we are giving those events a `.json` extension when dumping then.
// This is just for the sake of formatter support which make further visual
// inspection easier.
await fsp.writeFile(`tests/events/${e.event_id}.json`, JSON.stringify(e));
await fsp.writeFile(`tests/events/${e.event_id}.txt`, util.inspect(e, false, null));
}
return e;
},
Expand Down
Expand Up @@ -11,16 +11,6 @@ interface Tag {
}

test('Sends two linked transactions (server & client) to Sentry', async ({ page }, testInfo) => {
// this warm up turned out to be needed when using 'beforeSendTransaction' the trick (see
// the Sentry init setup in `entry.server.ts`); after this we can navigate to any route and
// be sure that the transaction events are being dumped to disk as expected;
//
// note, that to perform this "warp up" we could actually navigate to any other route including
// non-existant, but going to non-existant will pollute the console with something like
// ' Error: No route matches URL "/whatever"', which will _not_ prevent the test from passing
// but simply not very pleasant.
await page.goto("/navigate");

// We will be utilizing `testId` provided by the test runner to correlate
// this test instance with the events we are going to send to Sentry.
// See `Sentry.setTag` in `app/routes/_index.tsx`.
Expand Down Expand Up @@ -72,7 +62,7 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
await expect.poll(async () => {
const files = await readEventsDir();
if (files.length !== 0) {
serverEventIds = files.map(f => path.basename(f, ".json"));
serverEventIds = files.map(f => path.basename(f, ".txt"));
return true;
}
return false;
Expand Down

0 comments on commit 849e6fd

Please sign in to comment.