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

ref(browser): Add protocol attributes to resource spans #15161

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

Zen-cronic
Copy link
Contributor

@Zen-cronic Zen-cronic commented Jan 26, 2025

Resolves #12395

Changes made:

  • Relocated extractNetworkProtocol util and its unit test to browser-utils.
  • Modified browserMetrics test to assert the new metadata.

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

@@ -131,6 +131,7 @@ describe('_addResourceSpans', () => {
encodedBodySize: 256,
decodedBodySize: 256,
renderBlockingStatus: 'non-blocking',
nextHopProtocol: 'http/1.1',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This prop is needed even if the metadata is not asserted, otherwise this line throws due to undefined value:

for (const char of nextHopProtocol) {

Copy link
Member

@Lms24 Lms24 Jan 27, 2025

Choose a reason for hiding this comment

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

Yeah I was a bit worried about this but I think it's okay. MDN classifies the nextHopProtocol prop as widely available and we previously treated it as such when adding timing info to fetch request spans. So it's okay to add this I think. If we get reports, we can still safeguard usage later.

@Lms24 Lms24 self-assigned this Jan 27, 2025
@Lms24 Lms24 self-requested a review January 27, 2025 09:25
@Lms24 Lms24 force-pushed the update/metadata-resource-span branch from 590a5ed to 857cc4b Compare January 27, 2025 10:43
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.

Hey @Zen-cronic, once again, thanks for contributing! :D

I took the liberty to refactor the unit tests a bit and make the integration test for resource spans a bit more robust (see comments).

@@ -131,6 +131,7 @@ describe('_addResourceSpans', () => {
encodedBodySize: 256,
decodedBodySize: 256,
renderBlockingStatus: 'non-blocking',
nextHopProtocol: 'http/1.1',
Copy link
Member

@Lms24 Lms24 Jan 27, 2025

Choose a reason for hiding this comment

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

Yeah I was a bit worried about this but I think it's okay. MDN classifies the nextHopProtocol prop as widely available and we previously treated it as such when adding timing info to fetch request spans. So it's okay to add this I think. If we get reports, we can still safeguard usage later.

['sip/2', { name: 'sip', version: '2' }],
['tds/8.0', { name: 'tds', version: '8.0' }],
['dicom', { name: 'dicom', version: 'unknown' }],
['', { name: '', version: 'unknown' }],
Copy link
Member

Choose a reason for hiding this comment

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

I added this last case here because according to MDN, nextHopProtocol will be empty for cross-origin resource requests where the responses don't contain a Timing-Allow-Origin header.

I was briefly debating changing the implementation to {name: 'unknown', version: 'unknown'} for consistency but then realized that this doesn't let us distinguish between the cross origin case and when we simply don't recognize the protocol. So let's leave it as-is for now.

Comment on lines 77 to 79
'network.protocol.name': 'unknown',
'network.protocol.version': 'unknown',
Copy link
Member

@Lms24 Lms24 Jan 27, 2025

Choose a reason for hiding this comment

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

I was hoping this would actually be populated but looks like PlayWright/Chromium Headless emits a '' despite me returning a Timing-Allow-Origin: * header. Same goes for the deliveryType property which follows a similar pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha, i tried asserting the network.protocol.name and version here as well. But they came out to be unkown. And the properties were more comprehensively tested in the unit test, so i didn't add them here.
thanks for updating the integration test for better coverage!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm also not super happy about this but it looks like some browser or playwright bugs might be responsible for the ''. Coincidentally, we opened #15164 where it seems like at least some changes were made to cross origin performance entry data. So maybe this actually solves itself.

@Zen-cronic
Copy link
Contributor Author

hey @Lms24 , anytime! I've been working on the graphqlClientIntegration for a while now, and i got somewhat familiar with the browser pkg. So, this fix seemed like a low-hanging fruit.
Appreciate that you digged into the mdn docs :)

@Lms24
Copy link
Member

Lms24 commented Jan 27, 2025

FYI, I'm waiting on #15164 before merging this to see if the integration tests need some adjustments afterwards.

Zen-cronic and others added 4 commits January 28, 2025 17:59
- Relocated `extractNetworkProtocol` util to `browser-utils`.
- Modified `browserMetrics` test to assert the new metadata.

Signed-off-by: Kaung Zin Hein <[email protected]>
@Lms24 Lms24 force-pushed the update/metadata-resource-span branch from d1323e9 to b75eb03 Compare January 28, 2025 16:59
@Lms24 Lms24 changed the title ref(browser): Add protocol metadata to resource spans ref(browser): Add protocol attributes to resource spans Jan 29, 2025
@Lms24 Lms24 merged commit 52c40fc into getsentry:develop Jan 29, 2025
104 checks passed
Lms24 added a commit that referenced this pull request Jan 29, 2025
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #15161

---------

Co-authored-by: Lms24 <[email protected]>
Co-authored-by: Lukas Stracke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add protocol metadata to resource fetch requests
2 participants