Skip to content

Commit

Permalink
feat(opentelemetry-web): capture transferSize from PerformanceResourc…
Browse files Browse the repository at this point in the history
…eTiming
  • Loading branch information
johnbley committed Jun 30, 2020
1 parent 5aa851a commit 3852bd0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
1 change: 1 addition & 0 deletions packages/opentelemetry-web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-web/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -150,13 +152,15 @@ 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);

addSpanNetworkEvents(span, entries);

assert.strictEqual(addEventSpy.callCount, 9);
assert.strictEqual(setAttributeSpy.callCount, 1);
});
});
describe('addSpanNetworkEvent', () => {
Expand Down

0 comments on commit 3852bd0

Please sign in to comment.