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
Expand Up @@ -3,7 +3,6 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
import { shouldSkipTracingTest } from '../../../../utils/helpers';

type WindowWithSpan = Window & {
firstWaitingSpan: any;
Expand All @@ -19,8 +18,7 @@ sentryTest(
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);

const envelope = await getFirstSentryEnvelopeRequest<Event>(page);
expect(envelope).toBeDefined();
await page.waitForFunction(() => !!(window as unknown as WindowWithSpan).secondWaitingSpan);

const firstWaitingSpanValue = await page.evaluate(
() => (window as unknown as WindowWithSpan).firstWaitingSpan.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [
Sentry.browserTracingIntegration({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { SENTRY_STATUS_MESSAGE, SENTRY_CANCELLATION_REASON } from '@sentry/conventions/attributes';
import { expect } from '@playwright/test';
import type { StreamedSpanJSON } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../utils/helpers';

sentryTest('should finish a custom transaction when the page goes background', async ({ getLocalTestUrl, page }) => {
sentryTest('should finish a custom span when the page goes background', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
Expand Down Expand Up @@ -32,6 +33,6 @@ sentryTest('should finish a custom transaction when the page goes background', a
expect(name_after).toBe(name_before);
// a cancelled span is reported as `ok`, with the raw status kept as an attribute
expect(spanJsonAfter.status).toBe('ok');
expect(attributes_after['sentry.status.message']).toBeUndefined();
expect(attributes_after['sentry.cancellation_reason']).toBe('document.hidden');
expect(attributes_after[SENTRY_STATUS_MESSAGE]).toBeUndefined();
expect(attributes_after[SENTRY_CANCELLATION_REASON]).toBe('document.hidden');
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.browserTracingIntegration(), Sentry.spanStreamingIntegration()],
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PAGELOAD } from '@sentry/conventions/op';
import { SENTRY_CANCELLATION_REASON } from '@sentry/conventions/attributes';
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../utils/helpers';

sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });

const pageloadPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === PAGELOAD);

await page.goto(url);
await page.locator('#go-background').click();

const pageloadTransaction = envelopeRequestParser(await pageloadPromise);

expect(pageloadTransaction.contexts?.trace?.op).toBe(PAGELOAD);
expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled');
expect(pageloadTransaction.contexts?.trace?.data?.[SENTRY_CANCELLATION_REASON]).toBe('document.hidden');
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [
Sentry.browserTracingIntegration({ linkPreviousTrace: 'session-storage' }),
Sentry.spanStreamingIntegration(),
],
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { PAGELOAD } from '@sentry/conventions/op';
import { SENTRY_CANCELLATION_REASON } from '@sentry/conventions/attributes';
import { expect } from '@playwright/test';
import type { Event } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
import { shouldSkipTracingTest } from '../../../../utils/helpers';
import { getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils';

sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
sentryTest('finishes streamed pageload span when the page goes background', async ({ getLocalTestUrl, page }) => {
sentryTest.skip(shouldSkipTracingTest());
const url = await getLocalTestUrl({ testDir: __dirname });
const pageloadSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === PAGELOAD);

await page.goto(url);
await page.locator('#go-background').click();
const pageloadSpan = await pageloadSpanPromise;

const pageloadTransaction = await getFirstSentryEnvelopeRequest<Event>(page);

expect(pageloadTransaction.contexts?.trace?.op).toBe('pageload');
expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled');
expect(pageloadTransaction.contexts?.trace?.data?.['sentry.cancellation_reason']).toBe('document.hidden');
expect(getSpanOp(pageloadSpan)).toBe(PAGELOAD);
expect(pageloadSpan.status).toBe('ok');
expect(pageloadSpan.attributes[SENTRY_CANCELLATION_REASON]?.value).toBe('document.hidden');
});
Comment thread
sentry[bot] marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
import { PAGELOAD } from '@sentry/conventions/op';
import { URL_PATH } from '@sentry/conventions/attributes';
import { expect } from '@playwright/test';
import type { Event } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import {
getMultipleSentryEnvelopeRequests,
envelopeRequestParser,
waitForErrorRequest,
runScriptInSandbox,
shouldSkipTracingTest,
} from '../../../../utils/helpers';
import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils';

sentryTest(
'should put the pageload transaction name onto an error event caught during pageload',
'puts the page path onto an error caught during pageload',
async ({ getLocalTestUrl, page, browserName }) => {
if (browserName === 'webkit') {
// This test fails on Webkit as errors thrown from `runScriptInSandbox` are Script Errors and skipped by Sentry
sentryTest.skip();
}

if (shouldSkipTracingTest()) {
sentryTest.skip();
}

// WebKit treats errors from runScriptInSandbox as Script Errors, which Sentry skips.
sentryTest.skip(shouldSkipTracingTest() || browserName === 'webkit');
const url = await getLocalTestUrl({ testDir: __dirname });

const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);

const spans = collectStreamedSpans(page);
const pageloadPromise = waitForStreamedSpan(page, span => getSpanOp(span) === PAGELOAD);
const errorPromise = waitForErrorRequest(page);
await page.goto(url);

await runScriptInSandbox(page, {
content: `
throw new Error('Error during pageload');
`,
});

const [e1, e2] = await errorEventsPromise;

const pageloadTxnEvent = e1.type === 'transaction' ? e1 : e2;
const errorEvent = e1.type === 'transaction' ? e2 : e1;

expect(pageloadTxnEvent.contexts?.trace?.op).toEqual('pageload');
expect(pageloadTxnEvent.spans?.length).toBeGreaterThan(0);
expect(errorEvent.exception?.values?.[0]).toBeDefined();

expect(pageloadTxnEvent.transaction?.endsWith('index.html')).toBe(true);

expect(errorEvent.transaction).toEqual(pageloadTxnEvent.transaction);
await runScriptInSandbox(page, { content: "throw new Error('Error during pageload');" });
const [pageload, errorRequest] = await Promise.all([pageloadPromise, errorPromise]);
await page.evaluate(() => (window as any).Sentry.flush());
expect(getSpanOp(pageload)).toBe(PAGELOAD);
expect(spans.filter(span => !span.is_segment)).not.toHaveLength(0);
const error = envelopeRequestParser<Event>(errorRequest);
expect(error.exception?.values?.[0]).toBeDefined();
expect(pageload.name).toBe('Pageload');
expect(error.transaction).toBe('/index.html');
expect(error.transaction).toBe(pageload.attributes[URL_PATH]?.value);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [
Sentry.browserTracingIntegration({
_experiments: {
enableHTTPTimings: true,
},
}),
Sentry.spanStreamingIntegration(),
],
tracesSampleRate: 1,
traceLifecycle: 'stream',
debug: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { PAGELOAD, HTTP_CLIENT } from '@sentry/conventions/op';
import {
HTTP_REQUEST_REDIRECT_START,
HTTP_REQUEST_REDIRECT_END,
HTTP_REQUEST_WORKER_START,
HTTP_REQUEST_FETCH_START,
HTTP_REQUEST_DOMAIN_LOOKUP_START,
HTTP_REQUEST_DOMAIN_LOOKUP_END,
HTTP_REQUEST_CONNECT_START,
HTTP_REQUEST_SECURE_CONNECTION_START,
HTTP_REQUEST_CONNECTION_END,
HTTP_REQUEST_REQUEST_START,
HTTP_REQUEST_RESPONSE_START,
HTTP_REQUEST_RESPONSE_END,
HTTP_REQUEST_TIME_TO_FIRST_BYTE,
NETWORK_PROTOCOL_VERSION,
} from '@sentry/conventions/attributes';
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../utils/helpers';

sentryTest('creates fetch spans with http timing', async ({ browserName, getLocalTestUrl, page }) => {
const supportedBrowsers = ['chromium', 'firefox'];

if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) {
sentryTest.skip();
}
await page.route('http://sentry-test-site.example/*', async route => {
const request = route.request();
const postData = await request.postDataJSON();

await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(Object.assign({ id: 1 }, postData)),
});
});

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

const pageloadPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === PAGELOAD);
await page.goto(url);
const tracingEvent = envelopeRequestParser(await pageloadPromise);

const requestSpans = tracingEvent.spans?.filter(({ op }) => op === HTTP_CLIENT);

expect(requestSpans).toHaveLength(3);

requestSpans?.forEach((span, index) =>
expect(span).toMatchObject({
description: `GET http://sentry-test-site.example/${index}`,
parent_span_id: tracingEvent.contexts?.trace?.span_id,
span_id: expect.stringMatching(/[a-f\d]{16}/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
trace_id: tracingEvent.contexts?.trace?.trace_id,
data: expect.objectContaining({
[HTTP_REQUEST_REDIRECT_START]: expect.any(Number),
[HTTP_REQUEST_REDIRECT_END]: expect.any(Number),
[HTTP_REQUEST_WORKER_START]: expect.any(Number),
[HTTP_REQUEST_FETCH_START]: expect.any(Number),
[HTTP_REQUEST_DOMAIN_LOOKUP_START]: expect.any(Number),
[HTTP_REQUEST_DOMAIN_LOOKUP_END]: expect.any(Number),
[HTTP_REQUEST_CONNECT_START]: expect.any(Number),
[HTTP_REQUEST_SECURE_CONNECTION_START]: expect.any(Number),
[HTTP_REQUEST_CONNECTION_END]: expect.any(Number),
[HTTP_REQUEST_REQUEST_START]: expect.any(Number),
[HTTP_REQUEST_RESPONSE_START]: expect.any(Number),
[HTTP_REQUEST_RESPONSE_END]: expect.any(Number),
[HTTP_REQUEST_TIME_TO_FIRST_BYTE]: expect.any(Number),
[NETWORK_PROTOCOL_VERSION]: expect.any(String),
}),
}),
);
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [
Sentry.browserTracingIntegration({
Expand Down
Loading
Loading