Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { headers } from 'next/headers';
import { Suspense } from 'react';

// Above the pageload's 10 second wait for the trace meta tag, but short enough that the tag still
// arrives before the pageload ends.
const DELAY_MS = 10_500;

async function SlowContent() {
await headers();
await new Promise(resolve => setTimeout(resolve, DELAY_MS));
return <p id="slow-content">Slow content</p>;
}

export default function Page() {
return (
<Suspense fallback={<p>Loading...</p>}>
<SlowContent />
</Suspense>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,33 @@ test('keeps a navigation that starts while the pageload waits for the trace meta
expect(pageloadTx.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('cancelled');
expect(navigationTx.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout');
});

test('links the server request when its trace meta tag arrives after the pageload stopped waiting', async ({
page,
}) => {
test.skip(process.env.TEST_ENV !== 'production', 'Only a prerendered shell makes the trace meta tag arrive late');
test.setTimeout(60_000);

const pageloadTxPromise = waitForTransaction(APP, transactionEvent => {
return transactionEvent.transaction === '/slow-stream' && transactionEvent.contexts?.trace?.op === 'pageload';
});

await page.goto('/slow-stream', { waitUntil: 'commit' });
await expect(page.locator('#slow-content')).toBeVisible({ timeout: 20_000 });
const [requestTraceId, requestSpanId] = (await page
.locator('meta[name="sentry-trace"]')
.getAttribute('content'))!.split('-');

const pageloadTx = await pageloadTxPromise;

// The tag arrived after the pageload had started its own trace, so the pageload only links it.
expect(pageloadTx.contexts?.trace?.trace_id).not.toBe(requestTraceId);
expect(pageloadTx.contexts?.trace?.links).toEqual([
{
trace_id: requestTraceId,
span_id: requestSpanId,
sampled: true,
attributes: { [SENTRY_LINK_TYPE]: 'server_request' },
},
]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { headers } from 'next/headers';
import { Suspense } from 'react';

// Above the pageload's 10 second wait for the trace meta tag, but short enough that the tag still
// arrives before the pageload ends.
const DELAY_MS = 10_500;

async function SlowContent() {
await headers();
await new Promise(resolve => setTimeout(resolve, DELAY_MS));
return <p id="slow-content">Slow content</p>;
}

export default function Page() {
return (
<Suspense fallback={<p>Loading...</p>}>
<SlowContent />
</Suspense>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,33 @@ test('keeps a navigation that starts while the pageload waits for the trace meta
value: 'idleTimeout',
});
});

test('links the server request when its trace meta tag arrives after the pageload stopped waiting', async ({
page,
}) => {
test.skip(process.env.TEST_ENV !== 'production', 'Only a prerendered shell makes the trace meta tag arrive late');
test.setTimeout(60_000);

const pageloadSpanPromise = waitForStreamedSpan(APP, span => {
return span.name === '/slow-stream' && getSpanOp(span) === 'pageload' && span.is_segment;
});

await page.goto('/slow-stream', { waitUntil: 'commit' });
await expect(page.locator('#slow-content')).toBeVisible({ timeout: 20_000 });
const [requestTraceId, requestSpanId] = (await page
.locator('meta[name="sentry-trace"]')
.getAttribute('content'))!.split('-');

const pageloadSpan = await pageloadSpanPromise;

// The tag arrived after the pageload had started its own trace, so the pageload only links it.
expect(pageloadSpan.trace_id).not.toBe(requestTraceId);
expect(pageloadSpan.links).toEqual([
{
trace_id: requestTraceId,
span_id: requestSpanId,
sampled: true,
attributes: { [SENTRY_LINK_TYPE]: { type: 'string', value: 'server_request' } },
},
]);
});
Loading