-
-
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(feedback): Flush replays when feedback form opens #10567
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c45d03f
feat(feedback): Auto start buffering replays if enabled and flush on …
billyvg 13f8a47
remove auto-start buffering
billyvg 04fe1fd
Merge branch 'develop' into feat-feedback-flush-replay-on-form-open
billyvg 5420b93
remove dev deps
billyvg df47d95
remove noSampling tests
billyvg 9053bcf
lint
billyvg fd6cbd6
fix types
billyvg 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
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
...es/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/hasSampling/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,107 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { envelopeRequestParser, getEnvelopeType } from '../../../../utils/helpers'; | ||
import { getCustomRecordingEvents, getReplayEvent, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest( | ||
'should capture feedback (@sentry-internal/feedback import)', | ||
async ({ forceFlushReplay, getLocalTestPath, page }) => { | ||
if (process.env.PW_BUNDLE) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
const reqPromise1 = waitForReplayRequest(page, 1); | ||
const reqPromise2 = waitForReplayRequest(page, 2); | ||
const feedbackRequestPromise = page.waitForResponse(res => { | ||
const req = res.request(); | ||
|
||
const postData = req.postData(); | ||
if (!postData) { | ||
return false; | ||
} | ||
|
||
try { | ||
return getEnvelopeType(req) === 'feedback'; | ||
} catch (err) { | ||
return false; | ||
} | ||
}); | ||
|
||
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 }); | ||
|
||
const [, , replayReq0] = await Promise.all([page.goto(url), page.getByText('Report a Bug').click(), reqPromise0]); | ||
|
||
// Inputs are slow, these need to be serial | ||
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'); | ||
|
||
// Force flush here, as inputs are slow and can cause click event to be in unpredictable segments | ||
await Promise.all([forceFlushReplay(), reqPromise1]); | ||
|
||
const [, feedbackResp, replayReq2] = await Promise.all([ | ||
page.getByLabel('Send Bug Report').click(), | ||
feedbackRequestPromise, | ||
reqPromise2, | ||
]); | ||
|
||
const feedbackEvent = envelopeRequestParser(feedbackResp.request()); | ||
const replayEvent = getReplayEvent(replayReq0); | ||
// Feedback breadcrumb is on second segment because we flush when "Report a Bug" is clicked | ||
// And then the breadcrumb is sent when feedback form is submitted | ||
const { breadcrumbs } = getCustomRecordingEvents(replayReq2); | ||
|
||
expect(breadcrumbs).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
category: 'sentry.feedback', | ||
data: { feedbackId: expect.any(String) }, | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
}), | ||
]), | ||
); | ||
|
||
expect(feedbackEvent).toEqual({ | ||
type: 'feedback', | ||
breadcrumbs: expect.any(Array), | ||
contexts: { | ||
feedback: { | ||
contact_email: '[email protected]', | ||
message: 'my example feedback', | ||
name: 'Jane Doe', | ||
replay_id: replayEvent.event_id, | ||
source: 'widget', | ||
url: expect.stringContaining('/dist/index.html'), | ||
}, | ||
}, | ||
level: 'info', | ||
timestamp: expect.any(Number), | ||
event_id: expect.stringMatching(/\w{32}/), | ||
environment: 'production', | ||
sdk: { | ||
integrations: expect.arrayContaining(['Feedback']), | ||
version: expect.any(String), | ||
name: 'sentry.javascript.browser', | ||
packages: expect.anything(), | ||
}, | ||
request: { | ||
url: expect.stringContaining('/dist/index.html'), | ||
headers: { | ||
'User-Agent': expect.stringContaining(''), | ||
}, | ||
}, | ||
platform: 'javascript', | ||
}); | ||
}, | ||
); |
18 changes: 18 additions & 0 deletions
18
...ges/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/noSampling/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,18 @@ | ||
import { Feedback } from '@sentry-internal/feedback'; | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
replaysOnErrorSampleRate: 0, | ||
replaysSessionSampleRate: 0, | ||
integrations: [ | ||
new Sentry.Replay({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
minReplayDuration: 0, | ||
}), | ||
new Feedback(), | ||
], | ||
}); |
30 changes: 30 additions & 0 deletions
30
...ges/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/noSampling/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,30 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getReplayEvent, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest( | ||
'should capture feedback with no replay sampling when Form opens (@sentry-internal/feedback import)', | ||
async ({ getLocalTestPath, page }) => { | ||
if (process.env.PW_BUNDLE) { | ||
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 }); | ||
|
||
const [, , replayReq] = await Promise.all([page.goto(url), page.getByText('Report a Bug').click(), reqPromise0]); | ||
|
||
const replayEvent = getReplayEvent(replayReq); | ||
expect(replayEvent.segment_id).toBe(0); | ||
expect(replayEvent.replay_type).toBe('buffer'); | ||
}, | ||
); |
91 changes: 0 additions & 91 deletions
91
dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/test.ts
This file was deleted.
Oops, something went wrong.
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.
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.
let's not use this syntax, but
import type {}
- I've read that this is better/easier to treeshake!Also, generally, I'd say maybe we should avoid this - we have this as devDependency only for the type here, which is not really correct from a bundling perspective 😬 I'd rather we just inline the relevant type here (or if really needed put some interface type in
@sentry/types
that both packages can use)?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.
Wouldn't inlining defeat the purpose of typechecking against replay interface? (in this case, it probably wouldn't matter too much, but just trying to think of a good general solution).
I guess the best solution here is to extract it into
types
, but it's still a bit annoying having to duplicate the typeThere 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.
yeah, that's always the problem with the types stuff and the circular dependency stuff 😬
So I'd go with one of these approaches - no strong feelings:
class Replay implements ReplayIntegrationInterface
or something like this 🤔