Skip to content

test(browser-integration-test): Add tests to check trace lifetime in user feedback events #11626

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

Closed
Closed
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
Expand Up @@ -4,7 +4,7 @@ window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.browserTracingIntegration()],
integrations: [Sentry.browserTracingIntegration(), Sentry.feedbackIntegration()],
tracePropagationTargets: ['http://example.com'],
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sentryTest('error during navigation has new navigation traceId', async ({ getLoc

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

// ensure navigation transaction is finished
// ensure pageload transaction is finished
await getFirstSentryEnvelopeRequest<Event>(page, url);

const envelopeRequestsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
Expand Down Expand Up @@ -112,7 +112,7 @@ sentryTest(

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

// ensure navigation transaction is finished
// ensure pageload transaction is finished
await getFirstSentryEnvelopeRequest<Event>(page, url);

const navigationEvent = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);
Expand Down Expand Up @@ -148,7 +148,7 @@ sentryTest(

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

// ensure navigation transaction is finished
// ensure pageload transaction is finished
await getFirstSentryEnvelopeRequest<Event>(page, url);

const navigationEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
Expand Down Expand Up @@ -185,7 +185,7 @@ sentryTest(

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

// ensure navigation transaction is finished
// ensure pageload transaction is finished
await getFirstSentryEnvelopeRequest<Event>(page, url);

const navigationEvent = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);
Expand Down Expand Up @@ -221,7 +221,7 @@ sentryTest(

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

// ensure navigation transaction is finished
// ensure pageload transaction is finished
await getFirstSentryEnvelopeRequest<Event>(page, url);

const navigationEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
Expand All @@ -247,3 +247,45 @@ sentryTest(
);
},
);

sentryTest(
'user feedback event after navigation has navigation traceId in headers',
async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

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

// ensure pageload transaction is finished
await getFirstSentryEnvelopeRequest<Event>(page, url);

const navigationEvent = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);

const navigationTraceContext = navigationEvent.contexts?.trace;
expect(navigationTraceContext).toMatchObject({
op: 'navigation',
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});
expect(navigationTraceContext).not.toHaveProperty('parent_span_id');

const feedbackEventPromise = getFirstSentryEnvelopeRequest<Event>(page);

await page.getByText('Report a Bug').click();
expect(await page.locator(':visible:text-is("Report a Bug")').count()).toEqual(1);
await page.locator('[name="name"]').fill('Jane Doe');
await page.locator('[name="email"]').fill('[email protected]');
await page.locator('[name="message"]').fill('my example feedback');
await page.locator('[data-sentry-feedback] .btn--primary').click();

const feedbackEvent = await feedbackEventPromise;
const feedbackTraceContext = feedbackEvent.contexts?.trace;

expect(feedbackTraceContext).toMatchObject({
op: 'navigation',
trace_id: navigationTraceContext?.trace_id,
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,40 @@ sentryTest(
expect(headers['baggage']).toBe(META_TAG_BAGGAGE);
},
);

sentryTest('user feedback event after pageload has pageload traceId in headers', async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

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

const pageloadEvent = await getFirstSentryEnvelopeRequest<Event>(page, url);
const pageloadTraceContext = pageloadEvent.contexts?.trace;

expect(pageloadTraceContext).toMatchObject({
op: 'pageload',
trace_id: META_TAG_TRACE_ID,
parent_span_id: META_TAG_PARENT_SPAN_ID,
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});

const feedbackEventPromise = getFirstSentryEnvelopeRequest<Event>(page);

await page.getByText('Report a Bug').click();
expect(await page.locator(':visible:text-is("Report a Bug")').count()).toEqual(1);
await page.locator('[name="name"]').fill('Jane Doe');
await page.locator('[name="email"]').fill('[email protected]');
await page.locator('[name="message"]').fill('my example feedback');
await page.locator('[data-sentry-feedback] .btn--primary').click();

const feedbackEvent = await feedbackEventPromise;
const feedbackTraceContext = feedbackEvent.contexts?.trace;

expect(feedbackTraceContext).toMatchObject({
op: 'pageload',
trace_id: META_TAG_TRACE_ID,
parent_span_id: META_TAG_PARENT_SPAN_ID,
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,39 @@ sentryTest(
);
},
);

sentryTest('user feedback event after pageload has pageload traceId in headers', async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

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

const pageloadEvent = await getFirstSentryEnvelopeRequest<Event>(page, url);
const pageloadTraceContext = pageloadEvent.contexts?.trace;

expect(pageloadTraceContext).toMatchObject({
op: 'pageload',
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/),
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});
expect(pageloadTraceContext).not.toHaveProperty('parent_span_id');

const feedbackEventPromise = getFirstSentryEnvelopeRequest<Event>(page);

await page.getByText('Report a Bug').click();
expect(await page.locator(':visible:text-is("Report a Bug")').count()).toEqual(1);
await page.locator('[name="name"]').fill('Jane Doe');
await page.locator('[name="email"]').fill('[email protected]');
await page.locator('[name="message"]').fill('my example feedback');
await page.locator('[data-sentry-feedback] .btn--primary').click();

const feedbackEvent = await feedbackEventPromise;
const feedbackTraceContext = feedbackEvent.contexts?.trace;

expect(feedbackTraceContext).toMatchObject({
op: 'pageload',
trace_id: pageloadTraceContext?.trace_id,
span_id: expect.stringMatching(/^[0-9a-f]{16}$/),
});
});
Loading