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

Add statusCode and exceptionType Fields to Network Statsbeat #1007

Merged
merged 10 commits into from
Sep 12, 2022

Conversation

JacksonWeber
Copy link
Contributor

This adds the statusCode and exceptionType fields to the appropriate network StatsBeat metrics per the spec https://github.com/microsoft/Telemetry-Collection-Spec/blob/main/ApplicationInsights/statsbeat.md

@JacksonWeber JacksonWeber changed the title Add statusCode and exceptionType Fields to Network Statsbeat [Draft]Add statusCode and exceptionType Fields to Network Statsbeat Sep 7, 2022
@JacksonWeber JacksonWeber changed the title [Draft]Add statusCode and exceptionType Fields to Network Statsbeat Add statusCode and exceptionType Fields to Network Statsbeat Sep 8, 2022
this._statbeatMetrics.push({
name: Constants.StatsbeatCounter.REQUEST_FAILURE,
value: currentCounter.count,
properties: properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you using currentCounter.statusCode?, I can see you have an accurate count but I'm not sure where are you actually adding it to the Statsbeat properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now. Added it to the properties in each counter where it's relevant per the spec.

statsBeat.countRetry(0, "test", 206);
statsBeat.countRetry(0, "test", 206);
statsBeat.countThrottle(0, "test", 206);
statsBeat.countException(0, "test", "Statsbeat Exception");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add assert checking this exception type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests to determine the exceptionType field is populated correctly on the metric.

statsBeat.countRequest(0, "test", 1, false, 200);
statsBeat.countRequest(0, "test", 1, false, 200);
statsBeat.countRetry(0, "test", 206);
statsBeat.countRetry(0, "test", 206);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here we want to validate you count multiple failed requests, retry and throttle and multiple Statsbeat are generated with the properties part of them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some new tests that should ensure we're creating multiple metrics per statusCode now.

statsBeat.countRetry(0, "test");
statsBeat.countThrottle(0, "test");
statsBeat.countException(0, "test");
statsBeat.countRequest(0, "test", 1, true, 200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StatusCode should be optional parameter if is not used all the time, like in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make this parameter optional are we ok with creating entries in the request counter like { statusCode: undefined, count: <currentCount> }?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to do that, successful count is only a number

@@ -118,43 +118,63 @@ class Statsbeat {
this._instrumentation &= ~instrumentation;
}

public countRequest(endpoint: number, host: string, duration: number, success: boolean) {
public countRequest(endpoint: number, host: string, duration: number, success: boolean, statusCode?: number) {
if (!this.isEnabled()) {
return;
}
let counter: Network.NetworkStatsbeat = this._getNetworkStatsbeatCounter(endpoint, host);
counter.totalRequestCount++;
counter.intervalRequestExecutionTime += duration;
if (success === false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add check for statusCode here as well or you will create a null statusCode counter if this code path is ever triggered

Copy link
Member

@hectorhdzg hectorhdzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JacksonWeber JacksonWeber merged commit 225fad5 into develop Sep 12, 2022
@hectorhdzg hectorhdzg deleted the jacksonweber/add-status-code-statsbeat branch November 9, 2022 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants