Skip to content

Commit 16b21ce

Browse files
committed
feat(browser): Add http.response_delivery_type attribute to resource spans
1 parent eb17d62 commit 16b21ce

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/browser-utils/src/metrics/browserMetrics.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export interface ResourceEntry extends Record<string, unknown> {
513513
encodedBodySize?: number;
514514
decodedBodySize?: number;
515515
renderBlockingStatus?: string;
516+
deliveryType?: string;
516517
}
517518

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

543+
if (entry.deliveryType != null) {
544+
attributes['http.response_delivery_type'] = entry.deliveryType || 'default';
545+
}
546+
542547
if ('renderBlockingStatus' in entry) {
543548
attributes['resource.render_blocking_status'] = entry.renderBlockingStatus;
544549
}

packages/browser-utils/test/browser/browserMetrics.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,32 @@ describe('_addResourceSpans', () => {
340340
});
341341
});
342342

343+
// resource delivery types: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/deliveryType
344+
// i.e. better but not yet widely supported way to check for browser cache hit
345+
it.each(['', 'cache', 'navigational-prefetch'])(
346+
'attaches delivery type to resource spans if available',
347+
deliveryType => {
348+
const spans: Span[] = [];
349+
350+
getClient()?.on('spanEnd', span => {
351+
spans.push(span);
352+
});
353+
354+
const entry: ResourceEntry = {
355+
initiatorType: 'css',
356+
transferSize: 0,
357+
encodedBodySize: 0,
358+
decodedBodySize: 0,
359+
deliveryType,
360+
};
361+
362+
_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);
363+
364+
expect(spans).toHaveLength(1);
365+
expect(spanToJSON(spans[0]!)).toEqual(expect.objectContaining({ 'http.response_delivery_type': deliveryType }));
366+
},
367+
);
368+
343369
const setGlobalLocation = (location: Location) => {
344370
// @ts-expect-error need to delete this in order to set to new value
345371
delete WINDOW.location;

0 commit comments

Comments
 (0)