-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(browser): Extract and send frontend component name when available #9855
Closed
Closed
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9f52710
Iterate on method for retrieving component names and send it in bread…
0Calories 4b1418a
Add componentName in breadcrumb data
0Calories 4fb6c09
Track data-sentry-component attribute for replay breadcrumbs
0Calories 9a2e53c
Document the function
0Calories 3fe57fa
Add component name to interaction span databag
0Calories 873820f
Add component names to react profiler span databag
0Calories 665fd79
Add return type to getComponentName
0Calories 6fe6746
Run Biome formatter
0Calories ca37bcc
Add HTMLElement type to tests
0Calories 526c67d
Adjust tests to work with the new iteration
0Calories 41d9889
Adjust React profiler tests
0Calories 62eb261
Add integration test for replays
0Calories 365f24d
remove unnecessary null assignment
0Calories 0507f8c
Merge branch 'develop' into feat/component-names
0Calories 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
There are no files selected for viewing
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
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
17 changes: 17 additions & 0 deletions
17
packages/browser-integration-tests/suites/replay/captureComponentName/init.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
minReplayDuration: 0, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/browser-integration-tests/suites/replay/captureComponentName/template.html
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button data-sentry-component="MyCoolButton" id="button">😎</button> | ||
<input data-sentry-component="MyCoolInput" id="input" /> | ||
</body> | ||
</html> |
83 changes: 83 additions & 0 deletions
83
packages/browser-integration-tests/suites/replay/captureComponentName/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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getCustomRecordingEvents, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers'; | ||
|
||
sentryTest('captures component name attribute when available', async ({ forceFlushReplay, getLocalTestPath, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await reqPromise0; | ||
await forceFlushReplay(); | ||
|
||
const reqPromise1 = waitForReplayRequest(page, (event, res) => { | ||
return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click'); | ||
}); | ||
const reqPromise2 = waitForReplayRequest(page, (event, res) => { | ||
return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.input'); | ||
}); | ||
|
||
await page.locator('#button').click(); | ||
|
||
await page.locator('#input').focus(); | ||
await page.keyboard.press('Control+A'); | ||
await page.keyboard.type('Hello', { delay: 10 }); | ||
|
||
await forceFlushReplay(); | ||
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); | ||
const { breadcrumbs: breadcrumbs2 } = getCustomRecordingEvents(await reqPromise2); | ||
|
||
// Combine the two together | ||
breadcrumbs2.forEach(breadcrumb => { | ||
if (!breadcrumbs.some(b => b.category === breadcrumb.category && b.timestamp === breadcrumb.timestamp)) { | ||
breadcrumbs.push(breadcrumb); | ||
} | ||
}); | ||
|
||
expect(breadcrumbs).toEqual([ | ||
{ | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
category: 'ui.click', | ||
message: 'body > MyCoolButton', | ||
data: { | ||
nodeId: expect.any(Number), | ||
node: { | ||
attributes: { id: 'button', 'data-sentry-component': 'MyCoolButton' }, | ||
id: expect.any(Number), | ||
tagName: 'button', | ||
textContent: '**', | ||
}, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
category: 'ui.input', | ||
message: 'body > MyCoolInput', | ||
data: { | ||
nodeId: expect.any(Number), | ||
node: { | ||
attributes: { id: 'input', 'data-sentry-component': 'MyCoolInput' }, | ||
id: expect.any(Number), | ||
tagName: 'input', | ||
textContent: '', | ||
}, | ||
}, | ||
}, | ||
]); | ||
}); |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is unnecessary