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 #1262

Merged
merged 11 commits into from
Jul 6, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export enum AttributeNames {
HTTP_URL = 'http.url',
HTTP_TARGET = 'http.target',
HTTP_USER_AGENT = 'http.user_agent',
TRANSFER_SIZE = 'transferSize',
johnbley marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 5 additions & 1 deletion packages/opentelemetry-plugin-fetch/test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,12 @@ describe('fetch', () => {
attributes[keys[7]] !== '',
`attributes ${AttributeNames.HTTP_USER_AGENT} is not defined`
);
assert.ok(
(attributes[keys[8]] as number) > 0,
`attributes ${AttributeNames.TRANSFER_SIZE} is <= 0`
);

assert.strictEqual(keys.length, 8, 'number of attributes is wrong');
assert.strictEqual(keys.length, 9, 'number of attributes is wrong');
});

it('span should have correct events', () => {
Expand Down
16 changes: 10 additions & 6 deletions packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,31 +290,35 @@ describe('xhr', () => {
url,
`attributes ${HttpAttribute.HTTP_URL} is wrong`
);
assert.ok(
(attributes[keys[2]] as number) > 0,
'attributes transferSize <= 0'
johnbley marked this conversation as resolved.
Show resolved Hide resolved
);
assert.strictEqual(
attributes[keys[2]],
attributes[keys[3]],
200,
`attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong`
);
assert.strictEqual(
attributes[keys[3]],
attributes[keys[4]],
'OK',
`attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong`
);
assert.strictEqual(
attributes[keys[4]],
attributes[keys[5]],
parseUrl(url).host,
`attributes ${HttpAttribute.HTTP_HOST} is wrong`
);
assert.ok(
attributes[keys[5]] === 'http' || attributes[keys[5]] === 'https',
attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https',
`attributes ${HttpAttribute.HTTP_SCHEME} is wrong`
);
assert.ok(
attributes[keys[6]] !== '',
attributes[keys[7]] !== '',
`attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined`
);

assert.strictEqual(keys.length, 7, 'number of attributes is wrong');
assert.strictEqual(keys.length, 8, 'number of attributes is wrong');
});

it('span should have correct events', () => {
Expand Down
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