Skip to content

Commit

Permalink
Add ErrorBoundary propagation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed May 20, 2024
1 parent b29123d commit 81e86d3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { useSearchParams } from '@remix-run/react';
import * as Sentry from '@sentry/remix';

import { useState } from 'react';

export default function ErrorBoundaryCapture() {
const [searchParams] = useSearchParams();

if (searchParams.get('tag')) {
Sentry.setTags({
sentry_test: searchParams.get('tag'),
});
}

const [count, setCount] = useState(0);

if (count > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,52 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
expect(pageLoadParentSpanId).toEqual(loaderSpanId);
expect(pageLoadSpanId).not.toEqual(httpServerSpanId);
});

test.only('Propagates trace when ErrorBoundary is triggered', async ({ page }) => {
// We use this to identify the transactions
const testTag = uuid4();

const httpServerTransactionPromise = waitForTransaction('create-remix-app-express', transactionEvent => {
return (
transactionEvent.type === 'transaction' &&
transactionEvent.contexts?.trace?.op === 'http' &&
transactionEvent.tags?.['sentry_test'] === testTag
);
});

const pageLoadTransactionPromise = waitForTransaction('create-remix-app-express', transactionEvent => {
return (
transactionEvent.type === 'transaction' &&
transactionEvent.contexts?.trace?.op === 'pageload' &&
transactionEvent.tags?.['sentry_test'] === testTag
);
});

page.goto(`/client-error?tag=${testTag}`);

const pageloadTransaction = await pageLoadTransactionPromise;
const httpServerTransaction = await httpServerTransactionPromise;

expect(pageloadTransaction).toBeDefined();
expect(httpServerTransaction).toBeDefined();

const httpServerTraceId = httpServerTransaction.contexts?.trace?.trace_id;
const httpServerSpanId = httpServerTransaction.contexts?.trace?.span_id;
const loaderSpanId = httpServerTransaction.spans.find(
span => span.data && span.data['code.function'] === 'loader',
)?.span_id;

const pageLoadTraceId = pageloadTransaction.contexts?.trace?.trace_id;
const pageLoadSpanId = pageloadTransaction.contexts?.trace?.span_id;
const pageLoadParentSpanId = pageloadTransaction.contexts?.trace?.parent_span_id;

expect(httpServerTransaction.transaction).toBe('GET client-error');
expect(pageloadTransaction.transaction).toBe('routes/client-error');

expect(httpServerTraceId).toBeDefined();
expect(httpServerSpanId).toBeDefined();

expect(pageLoadTraceId).toEqual(httpServerTraceId);
expect(pageLoadParentSpanId).toEqual(loaderSpanId);
expect(pageLoadSpanId).not.toEqual(httpServerSpanId);
});

0 comments on commit 81e86d3

Please sign in to comment.