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

feat(replay): Capture request & response headers #7816

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Apr 12, 2023

We will capture the following headers by default:

  • content-type
  • accept
  • content-length

Additional headers can be opted in via _experiments.captureRequestHeaders and _experiments.captureResponseHeaders, which take an array of strings as arguments.

While at this, I also refactored the integration tests to be grouped by test type - this grew a bit out of hand for the network stuff. Now we have a single test file for request/response bodies, headers, sizes.

Closes #7495

@mydea mydea added the Package: replay Issues related to the Sentry Replay SDK label Apr 12, 2023
@mydea mydea requested review from billyvg and Lms24 April 12, 2023 07:30
@mydea mydea self-assigned this Apr 12, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 12, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.98 KB (+0.02% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 65.56 KB (+0.03% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.53 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 58.01 KB (+0.03% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.13 KB (+0.03% 🔺)
@sentry/browser - Webpack (minified) 68.96 KB (+0.02% 🔺)
@sentry/react - Webpack (gzipped + minified) 21.15 KB (+0.03% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.01 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.55 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.79 KB (+0.02% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 45.3 KB (+0.84% 🔺)
@sentry/replay - Webpack (gzipped + minified) 39.28 KB (+1.01% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 64.23 KB (+0.6% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 57.22 KB (+0.63% 🔺)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Nice work! Really like the restructuring of the integration tests!
Just had a few comments but looks good to go from my PoV.

Comment on lines +42 to +56
await page.evaluate(() => {
/* eslint-disable */
const xhr = new XMLHttpRequest();

xhr.open('GET', 'http://localhost:7654/foo');
xhr.send();

xhr.addEventListener('readystatechange', function () {
if (xhr.readyState === 4) {
// @ts-ignore Sentry is a global
setTimeout(() => Sentry.captureException('test error', 0));
}
});
/* eslint-enable */
});
Copy link
Member

Choose a reason for hiding this comment

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

(Not particular relevant for this test but more for all tests)
Good idea to use page.evaluate instead of subject.ts files! Out of curiosity - did this reduce flakiness or improve other aspects of the tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's IMHO just easier to read for such small things, as you see right in the test what's happening. Def. not for all cases, but here it's fine I'd say!

Comment on lines +883 to +884
requestHeaders: [...defaultHeaders, ...requestHeaders.map(header => header.toLowerCase())],
responseHeaders: [...defaultHeaders, ...responseHeaders.map(header => header.toLowerCase())],
Copy link
Member

Choose a reason for hiding this comment

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

I'm just wondering (disregard if you already talked about this with the replay team) if there'd be a reason for users to actively disable sending the default headers?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine for now to always include these headers.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can always adjust this later IMHO and reduce the defaults, but I think these should be pretty safe for all use cases?

Comment on lines 237 to 242
Object.keys(headers).forEach(key => {
const normalizedKey = key.toLowerCase();
if (allowedHeaders.includes(normalizedKey)) {
filteredHeaders[normalizedKey] = headers[key];
}
});
Copy link
Member

Choose a reason for hiding this comment

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

l: Seems to me like we're doing the same thing here as in XHR but a little differently. Wdyt about either using reduce in both cases or forEach? Or could we even use getAllowedHeaders for both? Might make things a little more unified overall. But logaf-l so feel free to leave it as is!

Copy link
Member Author

Choose a reason for hiding this comment

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

good point!

Copy link
Member

@billyvg billyvg left a comment

Choose a reason for hiding this comment

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

🚢 🚢 🚢

Comment on lines +883 to +884
requestHeaders: [...defaultHeaders, ...requestHeaders.map(header => header.toLowerCase())],
responseHeaders: [...defaultHeaders, ...responseHeaders.map(header => header.toLowerCase())],
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine for now to always include these headers.

@mydea mydea force-pushed the fn/replay-network-req-headers branch from 642c4a0 to 8afccf9 Compare April 13, 2023 13:35
@mydea mydea force-pushed the fn/replay-network-req-headers branch from 8afccf9 to d805b1a Compare April 13, 2023 13:58
@mydea mydea merged commit d54ff78 into develop Apr 13, 2023
@mydea mydea deleted the fn/replay-network-req-headers branch April 13, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture request/response headers for outgoing requests in Replay
3 participants