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(opentelemetry-web): capture decodedBodySize / http.response_content_length_uncompressed #2343

Merged
merged 2 commits into from
Jul 17, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export enum PerformanceTimingNames {
CONNECT_END = 'connectEnd',
CONNECT_START = 'connectStart',
DECODED_BODY_SIZE = 'decodedBodySize',
DOM_COMPLETE = 'domComplete',
DOM_CONTENT_LOADED_EVENT_END = 'domContentLoadedEventEnd',
DOM_CONTENT_LOADED_EVENT_START = 'domContentLoadedEventStart',
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { PerformanceTimingNames } from './enums/PerformanceTimingNames';
export type PerformanceEntries = {
[PerformanceTimingNames.CONNECT_END]?: number;
[PerformanceTimingNames.CONNECT_START]?: number;
[PerformanceTimingNames.DECODED_BODY_SIZE]?: number;
[PerformanceTimingNames.DOM_COMPLETE]?: number;
[PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END]?: number;
[PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START]?: number;
Expand Down
14 changes: 11 additions & 3 deletions packages/opentelemetry-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,19 @@ export function addSpanNetworkEvents(
addSpanNetworkEvent(span, PTN.REQUEST_START, resource);
addSpanNetworkEvent(span, PTN.RESPONSE_START, resource);
addSpanNetworkEvent(span, PTN.RESPONSE_END, resource);
const contentLength = resource[PTN.ENCODED_BODY_SIZE];
if (contentLength !== undefined) {
const encodedLength = resource[PTN.ENCODED_BODY_SIZE];
if (encodedLength !== undefined) {
span.setAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
contentLength
encodedLength
);
}
const decodedLength = resource[PTN.DECODED_BODY_SIZE];
// Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
if (decodedLength !== undefined && encodedLength !== decodedLength) {
span.setAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
decodedLength
);
}
}
Expand Down
22 changes: 21 additions & 1 deletion packages/opentelemetry-web/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,34 @@ describe('utils', () => {
[PTN.REQUEST_START]: 123,
[PTN.RESPONSE_START]: 123,
[PTN.RESPONSE_END]: 123,
[PTN.ENCODED_BODY_SIZE]: 123,
[PTN.DECODED_BODY_SIZE]: 123,
[PTN.ENCODED_BODY_SIZE]: 61,
} as PerformanceEntries;

assert.strictEqual(addEventSpy.callCount, 0);

addSpanNetworkEvents(span, entries);

assert.strictEqual(addEventSpy.callCount, 9);
assert.strictEqual(setAttributeSpy.callCount, 2);
});
it('should only include encoded size when content encoding is being used', () => {
const addEventSpy = sinon.spy();
const setAttributeSpy = sinon.spy();
const span = ({
addEvent: addEventSpy,
setAttribute: setAttributeSpy,
} as unknown) as tracing.Span;
const entries = {
[PTN.DECODED_BODY_SIZE]: 123,
[PTN.ENCODED_BODY_SIZE]: 123,
} as PerformanceEntries;

assert.strictEqual(setAttributeSpy.callCount, 0);

addSpanNetworkEvents(span, entries);

assert.strictEqual(addEventSpy.callCount, 0);
assert.strictEqual(setAttributeSpy.callCount, 1);
});
});
Expand Down