-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): Track PerformanceObserver interactions as spans (#7331)
Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
- Loading branch information
1 parent
295ea3d
commit 361c5a4
Showing
7 changed files
with
100 additions
and
22 deletions.
There are no files selected for viewing
10 changes: 7 additions & 3 deletions
10
packages/integration-tests/suites/tracing/browsertracing/interactions/assets/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
(() => { | ||
const delay = e => { | ||
const startTime = Date.now(); | ||
|
||
function getElasped() { | ||
const time = Date.now(); | ||
return time - startTime; | ||
} | ||
|
||
while (getElasped() < 105) { | ||
while (getElasped() < 70) { | ||
// | ||
} | ||
})(); | ||
|
||
e.target.classList.add('clicked'); | ||
}; | ||
|
||
document.querySelector('[data-test-id=interaction-button]').addEventListener('click', delay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 53 additions & 17 deletions
70
packages/integration-tests/suites/tracing/browsertracing/interactions/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,73 @@ | ||
import type { Route } from '@playwright/test'; | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
import type { Event, Span, SpanContext, Transaction } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest, getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers'; | ||
|
||
type TransactionJSON = ReturnType<Transaction['toJSON']> & { | ||
spans: ReturnType<Span['toJSON']>[]; | ||
contexts: SpanContext; | ||
platform: string; | ||
type: string; | ||
}; | ||
|
||
const wait = (time: number) => new Promise(res => setTimeout(res, time)); | ||
|
||
sentryTest('should capture interaction transaction.', async ({ browserName, getLocalTestPath, page }) => { | ||
if (browserName !== 'chromium') { | ||
const supportedBrowsers = ['chromium', 'firefox']; | ||
|
||
if (!supportedBrowsers.includes(browserName)) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('**/path/to/script.js', (route: Route) => route.fulfill({ path: `${__dirname}/assets/script.js` })); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
await page.goto(url); | ||
await getFirstSentryEnvelopeRequest<Event>(page); | ||
|
||
await page.locator('[data-test-id=interaction-button]').click(); | ||
await page.locator('.clicked[data-test-id=interaction-button]').isVisible(); | ||
|
||
const envelopes = await getMultipleSentryEnvelopeRequests<TransactionJSON>(page, 1); | ||
expect(envelopes).toHaveLength(1); | ||
|
||
const envelopes = await getMultipleSentryEnvelopeRequests<Event>(page, 1); | ||
const eventData = envelopes[0]; | ||
|
||
expect(eventData).toEqual( | ||
expect.objectContaining({ | ||
contexts: expect.objectContaining({ | ||
trace: expect.objectContaining({ | ||
op: 'ui.action.click', | ||
}), | ||
}), | ||
platform: 'javascript', | ||
spans: [], | ||
tags: {}, | ||
type: 'transaction', | ||
}), | ||
); | ||
expect(eventData.contexts).toMatchObject({ trace: { op: 'ui.action.click' } }); | ||
expect(eventData.platform).toBe('javascript'); | ||
expect(eventData.type).toBe('transaction'); | ||
expect(eventData.spans).toHaveLength(1); | ||
|
||
const interactionSpan = eventData.spans![0]; | ||
expect(interactionSpan.op).toBe('ui.interaction.click'); | ||
expect(interactionSpan.description).toBe('body > button.clicked'); | ||
expect(interactionSpan.timestamp).toBeDefined(); | ||
|
||
const interactionSpanDuration = (interactionSpan.timestamp! - interactionSpan.start_timestamp) * 1000; | ||
expect(interactionSpanDuration).toBeGreaterThan(70); | ||
expect(interactionSpanDuration).toBeLessThan(200); | ||
}); | ||
|
||
sentryTest('should create only one transaction per interaction', async ({ browserName, getLocalTestPath, page }) => { | ||
const supportedBrowsers = ['chromium', 'firefox']; | ||
|
||
if (!supportedBrowsers.includes(browserName)) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('**/path/to/script.js', (route: Route) => route.fulfill({ path: `${__dirname}/assets/script.js` })); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
await getFirstSentryEnvelopeRequest<Event>(page); | ||
|
||
for (let i = 0; i < 4; i++) { | ||
await wait(100); | ||
await page.locator('[data-test-id=interaction-button]').click(); | ||
const envelope = await getMultipleSentryEnvelopeRequests<Event>(page, 1); | ||
expect(envelope[0].spans).toHaveLength(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters