-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(browser): Run static beforeSendSpan for INP spans #22877
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
Open
logaretm
wants to merge
4
commits into
develop
Choose a base branch
from
feat/inp-static-before-send-span
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3a52992
feat(browser): Run static beforeSendSpan for INP spans
logaretm d9d9eee
fix(core): Run processSpan hooks for standalone spans with a static b…
logaretm f3d1a02
ref(core): Run processSpan hooks before the static beforeSendSpan for…
logaretm 2293bfc
fix(core): Preserve mutated top-level SpanJSON fields in v1 to v2 con…
logaretm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
.../browser-integration-tests/suites/tracing/metrics/web-vitals-inp-before-send-span/init.js
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [ | ||
| Sentry.browserTracingIntegration({ | ||
| idleTimeout: 4000, | ||
| enableLongTask: false, | ||
| enableInp: true, | ||
| instrumentPageLoad: false, | ||
| instrumentNavigation: false, | ||
| }), | ||
| ], | ||
| tracesSampleRate: 1, | ||
| // A plain (non-streamed) `beforeSendSpan` operates on the v1 `SpanJSON`. INP is sent as a v2 span, | ||
| // so this verifies the static callback still runs and its changes are carried into the v2 span. | ||
| beforeSendSpan: span => { | ||
| if (span.op === 'ui.interaction.click') { | ||
| span.description = 'scrubbed'; | ||
| span.data['custom.attribute'] = 'from-before-send-span'; | ||
| } | ||
|
|
||
| return span; | ||
| }, | ||
| debug: true, | ||
| }); | ||
|
|
||
| const client = Sentry.getClient(); | ||
|
|
||
| // Force page load transaction name to a testable value | ||
| Sentry.startBrowserTracingPageLoadSpan(client, { | ||
| name: 'test-url', | ||
| attributes: { | ||
| [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
| }, | ||
| }); |
20 changes: 20 additions & 0 deletions
20
...owser-integration-tests/suites/tracing/metrics/web-vitals-inp-before-send-span/subject.js
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const blockUI = | ||
| (delay = 70) => | ||
| e => { | ||
| const startTime = Date.now(); | ||
|
|
||
| function getElasped() { | ||
| const time = Date.now(); | ||
| return time - startTime; | ||
| } | ||
|
|
||
| while (getElasped() < delay) { | ||
| // | ||
| } | ||
|
|
||
| e.target.classList.add('clicked'); | ||
| }; | ||
|
|
||
| document.querySelector('[data-test-id=not-so-slow-button]').addEventListener('click', blockUI(300)); | ||
| document.querySelector('[data-test-id=slow-button]').addEventListener('click', blockUI(450)); | ||
| document.querySelector('[data-test-id=normal-button]').addEventListener('click', blockUI()); |
12 changes: 12 additions & 0 deletions
12
...er-integration-tests/suites/tracing/metrics/web-vitals-inp-before-send-span/template.html
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <div>Rendered Before Long Task</div> | ||
| <button data-test-id="slow-button" data-sentry-element="SlowButton">Slow</button> | ||
| <button data-test-id="not-so-slow-button" data-sentry-element="NotSoSlowButton">Not so slow</button> | ||
| <button data-test-id="normal-button" data-sentry-element="NormalButton">Click Me</button> | ||
| </body> | ||
| </html> |
44 changes: 44 additions & 0 deletions
44
.../browser-integration-tests/suites/tracing/metrics/web-vitals-inp-before-send-span/test.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { hidePage, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { getSpanOp, getSpansFromEnvelope, waitForStreamedSpanEnvelope } from '../../../../utils/spanUtils'; | ||
|
|
||
| // This app does not enable span streaming (`traceLifecycle: 'static'`) and defines a plain, non-streamed | ||
| // `beforeSendSpan` callback (operating on the v1 `SpanJSON`). INP is still emitted as a v2 span, so this | ||
| // verifies the static callback runs for INP and its modifications are carried into the v2 span. | ||
|
|
||
| sentryTest('runs a non-streamed `beforeSendSpan` for the INP span', async ({ browserName, getLocalTestUrl, page }) => { | ||
| const supportedBrowsers = ['chromium']; | ||
|
|
||
| if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const spanEnvelopePromise = waitForStreamedSpanEnvelope( | ||
| page, | ||
| env => !!getSpansFromEnvelope(env).find(s => getSpanOp(s) === 'ui.interaction.click'), | ||
| ); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| await page.locator('[data-test-id=normal-button]').click(); | ||
| await page.locator('.clicked[data-test-id=normal-button]').isVisible(); | ||
|
|
||
| await page.waitForTimeout(500); | ||
|
|
||
| // Page hide to trigger INP | ||
| await hidePage(page); | ||
|
|
||
| const spanEnvelope = await spanEnvelopePromise; | ||
| const inpSpan = getSpansFromEnvelope(spanEnvelope).find(s => getSpanOp(s) === 'ui.interaction.click')!; | ||
|
|
||
| // The callback rewrote the name and added a custom attribute. | ||
| expect(inpSpan.name).toBe('scrubbed'); | ||
| expect(inpSpan.attributes['custom.attribute']).toEqual({ value: 'from-before-send-span', type: 'string' }); | ||
|
|
||
| // The span is still a valid v2 INP span carrying its web vital value. | ||
| const inpValue = inpSpan.attributes['browser.web_vital.inp.value']?.value as number; | ||
| expect(inpValue).toBeGreaterThan(0); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.