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(browser): Add http.response_delivery_type attribute to resource spans #14056

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ export interface ResourceEntry extends Record<string, unknown> {
encodedBodySize?: number;
decodedBodySize?: number;
renderBlockingStatus?: string;
deliveryType?: string;
}

/** Create resource-related spans */
Expand All @@ -539,6 +540,10 @@ export function _addResourceSpans(
setResourceEntrySizeData(attributes, entry, 'encodedBodySize', 'http.response_content_length');
setResourceEntrySizeData(attributes, entry, 'decodedBodySize', 'http.decoded_response_content_length');

if (entry.deliveryType != null) {
attributes['http.response_delivery_type'] = entry.deliveryType || 'default';
Copy link
Member Author

@Lms24 Lms24 Oct 23, 2024

Choose a reason for hiding this comment

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

I'm falling back to "default" here because it seems like we drop attributes with empty string values (which is the actual default of the property) during ingest. Ideally we wouldn't need to do this but I don't see a better way at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add an explaining comment to the code why this is needed

}

if ('renderBlockingStatus' in entry) {
attributes['resource.render_blocking_status'] = entry.renderBlockingStatus;
}
Expand Down
26 changes: 26 additions & 0 deletions packages/browser-utils/test/browser/browserMetrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,32 @@ describe('_addResourceSpans', () => {
});
});

// resource delivery types: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType
// i.e. better but not yet widely supported way to check for browser cache hit
it.each(['', 'cache', 'navigational-prefetch'])(
'attaches delivery type to resource spans if available',
deliveryType => {
const spans: Span[] = [];

getClient()?.on('spanEnd', span => {
spans.push(span);
});

const entry: ResourceEntry = {
initiatorType: 'css',
transferSize: 0,
encodedBodySize: 0,
decodedBodySize: 0,
deliveryType,
};

_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);

expect(spans).toHaveLength(1);
expect(spanToJSON(spans[0]!)).toEqual(expect.objectContaining({ 'http.response_delivery_type': deliveryType }));
},
);

const setGlobalLocation = (location: Location) => {
// @ts-expect-error need to delete this in order to set to new value
delete WINDOW.location;
Expand Down
Loading