diff --git a/packages/opentelemetry-web/src/enums/PerformanceTimingNames.ts b/packages/opentelemetry-web/src/enums/PerformanceTimingNames.ts index 846a9ba967e..979b832d9a5 100644 --- a/packages/opentelemetry-web/src/enums/PerformanceTimingNames.ts +++ b/packages/opentelemetry-web/src/enums/PerformanceTimingNames.ts @@ -32,6 +32,7 @@ export enum PerformanceTimingNames { RESPONSE_END = 'responseEnd', RESPONSE_START = 'responseStart', SECURE_CONNECTION_START = 'secureConnectionStart', + TRANSFER_SIZE = 'transferSize', UNLOAD_EVENT_END = 'unloadEventEnd', UNLOAD_EVENT_START = 'unloadEventStart', } diff --git a/packages/opentelemetry-web/src/types.ts b/packages/opentelemetry-web/src/types.ts index 10ee04f14ec..0e11312c1e3 100644 --- a/packages/opentelemetry-web/src/types.ts +++ b/packages/opentelemetry-web/src/types.ts @@ -33,6 +33,7 @@ export type PerformanceEntries = { [PerformanceTimingNames.RESPONSE_END]?: number; [PerformanceTimingNames.RESPONSE_START]?: number; [PerformanceTimingNames.SECURE_CONNECTION_START]?: number; + [PerformanceTimingNames.TRANSFER_SIZE]?: number; [PerformanceTimingNames.UNLOAD_EVENT_END]?: number; [PerformanceTimingNames.UNLOAD_EVENT_START]?: number; }; diff --git a/packages/opentelemetry-web/src/utils.ts b/packages/opentelemetry-web/src/utils.ts index aa3dd320b69..55f2606a230 100644 --- a/packages/opentelemetry-web/src/utils.ts +++ b/packages/opentelemetry-web/src/utils.ts @@ -81,6 +81,9 @@ export function addSpanNetworkEvents( addSpanNetworkEvent(span, PTN.REQUEST_START, resource); addSpanNetworkEvent(span, PTN.RESPONSE_START, resource); addSpanNetworkEvent(span, PTN.RESPONSE_END, resource); + if (resource.transferSize) { + span.setAttribute('transferSize', resource.transferSize); + } } /** diff --git a/packages/opentelemetry-web/test/utils.test.ts b/packages/opentelemetry-web/test/utils.test.ts index 805986de71e..c9ea9822474 100644 --- a/packages/opentelemetry-web/test/utils.test.ts +++ b/packages/opentelemetry-web/test/utils.test.ts @@ -137,8 +137,10 @@ describe('utils', () => { describe('addSpanNetworkEvents', () => { it('should add all network events to span', () => { const addEventSpy = sinon.spy(); + const setAttributeSpy = sinon.spy(); const span = ({ addEvent: addEventSpy, + setAttribute: setAttributeSpy, } as unknown) as tracing.Span; const entries = { [PTN.FETCH_START]: 123, @@ -150,6 +152,7 @@ describe('utils', () => { [PTN.REQUEST_START]: 123, [PTN.RESPONSE_START]: 123, [PTN.RESPONSE_END]: 123, + [PTN.TRANSFER_SIZE]: 123, } as PerformanceEntries; assert.strictEqual(addEventSpy.callCount, 0); @@ -157,6 +160,7 @@ describe('utils', () => { addSpanNetworkEvents(span, entries); assert.strictEqual(addEventSpy.callCount, 9); + assert.strictEqual(setAttributeSpy.callCount, 1); }); }); describe('addSpanNetworkEvent', () => {