Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,13 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
tracesSampleRate: 1,
integrations: [
Sentry.browserTracingIntegration({
_experiments: { enableInteractions: true },
}),
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Clicking the navigate button will push a new history state, triggering navigation
document.querySelector('[data-test-id=navigate-button]').addEventListener('click', () => {
const loc = window.location;
const url = loc.href.includes('#nav') ? loc.pathname : `${loc.pathname}#nav`;

history.pushState({}, '', url);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<button data-test-id="navigate-button">Navigate</button>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@playwright/test';
import type { Event as SentryEvent } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import {
envelopeRequestParser,
getFirstSentryEnvelopeRequest,
shouldSkipTracingTest,
waitForTransactionRequest,
} from '../../../../utils/helpers';

sentryTest(
'click-triggered navigation should produce a root navigation transaction',
async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

const url = await getLocalTestUrl({ testDir: __dirname });

await page.goto(url);
await getFirstSentryEnvelopeRequest<SentryEvent>(page);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: can we use waitForTransactionRequest here, too? (I just think it's better practise to wait for transaction events rather than any event).


const interactionRequestPromise = waitForTransactionRequest(
page,
evt => evt.contexts?.trace?.op === 'ui.action.click',
);
const navigationRequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'navigation');

await page.locator('[data-test-id=navigate-button]').click();

const interactionEvent = envelopeRequestParser(await interactionRequestPromise);
const navigationEvent = envelopeRequestParser(await navigationRequestPromise);

// Navigation is root span, not a child span on the interaction
expect(interactionEvent.contexts?.trace?.op).toBe('ui.action.click');
expect(navigationEvent.contexts?.trace?.op).toBe('navigation');

expect(interactionEvent.contexts?.trace?.trace_id).not.toEqual(navigationEvent.contexts?.trace?.trace_id);

// does not contain a child navigation span
const interactionSpans = interactionEvent.spans || [];
const hasNavigationChild = interactionSpans.some(span => span.op === 'navigation' || span.op === 'http.server');
expect(hasNavigationChild).toBeFalsy();
},
);
3 changes: 3 additions & 0 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
_createRouteSpan(client, {
op: 'navigation',
...startSpanOptions,
// Navigation starts a new trace and is NOT parented under any active interaction (e.g. ui.action.click)
parentSpan: null,
forceTransaction: true,
});
});

Expand Down
Loading