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 4 commits
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| enableAutoRouteTracking | false | Automatically track route changes in Single Page Applications (SPA). If true, each route change will send a new Pageview to Application Insights. Hash route changes changes (`example.com/foo#bar`) are also recorded as new page views.
| enableRequestHeaderTracking | false | If true, AJAX & Fetch request headers is tracked, default is false.
| enableResponseHeaderTracking | false | If true, AJAX & Fetch request's response headers is tracked, default is false.
| disableAjaxErrorStatusText | false | Default false, include response error data text in dependency event on failed AJAX requests. If true, disable this track.
| distributedTracingMode | `DistributedTracingModes.AI` | Sets the distributed tracing mode. If AI_AND_W3C mode or W3C mode is set, W3C trace context headers (traceparent/tracestate) will be generated and included in all outgoing requests. AI_AND_W3C is provided for back-compatibility with any legacy Application Insights instrumented services.
| enableUnhandledPromiseRejectionTracking | false | If true, unhandled promise rejections will be autocollected and reported as a javascript error. When disableExceptionTracking is true (dont track exceptions) the config value will be ignored and unhandled promise rejections will not be reported.
## Single Page Applications
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 disableAjaxErrorStatusText flag is false",
test: () => {
let ajaxMonitor = new AjaxMonitor();
let appInsightsCore = new AppInsightsCore();
let coreConfig: IConfiguration & IConfig = { instrumentationKey: "abc", disableAjaxTracking: false, disableAjaxErrorStatusText: false };
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.responseText, "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,
disableAjaxErrorStatusText: 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,
disableAjaxErrorStatusText: undefined
}
}

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

if (!_self._config.disableAjaxErrorStatusText && xhr.status >= 400) {
dependency.properties = dependency.properties || {};
dependency.properties.responseText = xhr.statusText + " - " + xhr.responseText;
}

_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
*/
disableAjaxErrorStatusText?: 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;
disableAjaxErrorStatusText?: boolean;

correlationHeaderDomains?: string[]
}