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

include response error data #1161

Merged
merged 6 commits into from
Jan 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AISKU/Tests/applicationinsights.e2e.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class ApplicationInsightsTests extends TestClass {
disableFetchTracking: false,
enableRequestHeaderTracking: true,
enableResponseHeaderTracking: true,
includeResponseErrorData: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be renamed to disableAjaxErrorStatusText since it seems like something we would want to enable by default.

maxBatchInterval: 2500,
disableExceptionTracking: false,
namePrefix: this.sessionPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ export class AjaxTests extends TestClass {
}
});

this.testCase({
name: "Ajax: xhr respond error data is tracked as part C data when includeResponseErrorData flag is true",
test: () => {
let ajaxMonitor = new AjaxMonitor();
let appInsightsCore = new AppInsightsCore();
let coreConfig: IConfiguration & IConfig = { instrumentationKey: "abc", disableAjaxTracking: false, includeResponseErrorData: true };
appInsightsCore.initialize(coreConfig, [ajaxMonitor, new TestChannelPlugin()]);

var trackStub = this.sandbox.stub(ajaxMonitor, "trackDependencyDataInternal");

// act
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://microsoft.com");
xhr.send();

// Emulate response
(<any>xhr).respond(403, {}, "error data with status code 403");

// assert
Assert.ok(trackStub.calledOnce, "trackDependencyDataInternal is called");
Assert.equal("Ajax", trackStub.args[0][0].type, "request is Ajax type");
Assert.notEqual(undefined, trackStub.args[0][0].properties.responseError, "xhr request's reponse error is stored in part C");
}
});


this.testCase({
name: "Fetch: fetch with disabled flag isn't tracked",
test: () => {
Expand Down
11 changes: 9 additions & 2 deletions extensions/applicationinsights-dependencies-js/src/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
appId: undefined,
enableCorsCorrelation: false,
enableRequestHeaderTracking: false,
enableResponseHeaderTracking: false
enableResponseHeaderTracking: false,
includeResponseErrorData: false
}
return config;
}
Expand All @@ -66,7 +67,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
enableCorsCorrelation: undefined,
correlationHeaderDomains: undefined,
enableRequestHeaderTracking: undefined,
enableResponseHeaderTracking: undefined
enableResponseHeaderTracking: undefined,
includeResponseErrorData: undefined
}
}

Expand Down Expand Up @@ -557,6 +559,11 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
}
}

if (_self._config.includeResponseErrorData && xhr.status !== 200) {
Copy link
Member

Choose a reason for hiding this comment

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

_self._config.includeResponseErrorData && xhr.status !== 200 [](start = 16, length = 60)

Do we want to do this for all !=200 status codes or should we just check >=400 ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 we should only do this for status >= 400

As any response from 200 -> 299 is considered to be a success response, a common response is 204 == No Content.
And 300-> 399 are redirects

dependency.properties = dependency.properties || {};
dependency.properties.responseError = xhr.statusText + " - " + xhr.responseText;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rename to responseMessage or responseText, to convey string type instead of Error.

}

_self.trackDependencyDataInternal(dependency);

xhr.ajaxData = null;
Expand Down
8 changes: 8 additions & 0 deletions shared/AppInsightsCommon/src/Interfaces/IConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ export interface IConfig {
*/
enableResponseHeaderTracking?: boolean;

/**
* @description An optional value that will track Resonse Error data through trackDependency function.
Copy link

Choose a reason for hiding this comment

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

Small typo in description Resonse

* @type {boolean}
* @memberof IConfig
* @defaultValue false
*/
includeResponseErrorData?: boolean;

/**
* @description Default false. when tab is closed, the SDK will send all remaining telemetry using the [Beacon API](https://www.w3.org/TR/beacon)
* @type {boolean}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ICorrelationConfig {
appId?: string;
enableRequestHeaderTracking?: boolean;
enableResponseHeaderTracking?: boolean;
includeResponseErrorData?: boolean;

correlationHeaderDomains?: string[]
}