Skip to content
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

fix: XHR req method capture #1527

Merged
merged 7 commits into from
Nov 15, 2024
Merged

fix: XHR req method capture #1527

merged 7 commits into from
Nov 15, 2024

Conversation

pauldambra
Copy link
Member

We were using req.method before the request was used and so XHR was always captured as "GET"

Copy link

vercel bot commented Nov 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Nov 15, 2024 10:36am

@@ -280,6 +280,62 @@ describe('Session recording', () => {
)
})
})

it('it captures XHR method correctly', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests have a lot of duplication now, but I want to get this fix out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is pretty convincing, how would it have failed before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method = POST assertion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep... it was always GET before (or at least overwhelmingly GET I didn't check which)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and for clarity I validated the test failed before the change 😊

@@ -386,7 +386,7 @@ function prepareRequest({
timeOrigin,
timestamp,
method: method,
initiatorType: entry ? (entry.initiatorType as InitiatorType) : initiatorType,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flips the choice here... if we're providing an initiator we should use it in preference to the detected one

they should always match

@@ -309,7 +309,7 @@ function initXhrObserver(cb: networkCallback, win: IWindow, options: Required<Ne
.then((entry) => {
const requests = prepareRequest({
entry,
method: req.method,
method: method,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix... the method is provided to the XHR function when it is called so we should use it

@pauldambra pauldambra added the bump patch Bump patch version when this PR gets merged label Nov 15, 2024
Copy link

github-actions bot commented Nov 15, 2024

Size Change: +21 B (0%)

Total Size: 3.11 MB

Filename Size Change
dist/all-external-dependencies.js 204 kB +3 B (0%)
dist/array.full.js 356 kB +3 B (0%)
dist/array.full.no-external.js 355 kB +3 B (0%)
dist/module.full.js 356 kB +3 B (0%)
dist/module.full.no-external.js 355 kB +3 B (0%)
dist/recorder-v2.js 113 kB +3 B (0%)
dist/recorder.js 113 kB +3 B (0%)
ℹ️ View Unchanged
Filename Size
dist/array.full.es5.js 254 kB
dist/array.js 171 kB
dist/array.no-external.js 170 kB
dist/dead-clicks-autocapture.js 13 kB
dist/exception-autocapture.js 8.8 kB
dist/external-scripts-loader.js 2.19 kB
dist/main.js 172 kB
dist/module.js 171 kB
dist/module.no-external.js 170 kB
dist/surveys-preview.js 56.7 kB
dist/surveys.js 62.1 kB
dist/tracing-headers.js 1.33 kB
dist/web-vitals.js 10.3 kB

compressed-size-action

Copy link
Contributor

@robbie-c robbie-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're deep within code I haven't looked at before so with that caveat:

  • The bug itself makes sense
  • The fix for it makes sense
  • The test looks good

👍 👍 👍

@pauldambra pauldambra merged commit 8d420c7 into main Nov 15, 2024
13 checks passed
@pauldambra pauldambra deleted the fix/network-attribution-take1 branch November 15, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants