Dependencies Plugin for the Application Insights Javascript SDK
addDependencyListener(dependencyListener: DependencyListenerFunction): IDependencyListenerHandler
A dependency listener is a callback function that allows you to perform additional manipulation of the request details before the request is performed.
This includes :-
input
and init
arguments.traceparent
header (traceId
, spanId,
traceFlags)public addDependencyListener(dependencyListener: (dependencyDetails: IDependencyListenerDetails) => void): IDependencyListenerHandler;
// Example Usage
let handler = appInsights.addDependencyListener((details) => {
// You have complete access to the xhr instance
// details.xhr: XMLHttpRequest;
// Or if a fetch request you have complete access to the input and init objects
// details.input: Request | string;
// details.init: RequestInit;
// Access or change the W3C traceId that will be added to the outbound request
details.traceId = "";
// Access or change the W3C spanId that will be added to the outbound request
details.spanId = "";
// Access or change the W3C traceflags that will be added to the outbound request
details.traceFlags = 1;
// Add additional context values (any) that can be used by other listeners and is
// also passed to any dependency initializers
details.context.someValue = 1234;
});
// [Optional] Remove the dependency initializer
handler.remove();
addDependencyInitializer(dependencyInitializer: DependencyInitializerFunction): IDependencyInitializerHandler
A Dependency Initializer is very similar to a Telemetry Initializer in that it allows you modify the contents of collected telemetry before being sent from the user’s browser. And you can also returning false
to cause the event to not be emitted.
The differences between a telemetry initializer and a dependency initializer are :-
false
to drop the event the event does NOT count against the maxAjaxCallsPerView
as this blocks the event call from being tracked, and while returning false
from a Telemetry Initializer will also stop the event from being reported because this is further down the processing pipeline the dependency event IS counted against the maxAjaxCallsPerView
limit.{ [key: string]: any }
object that is also available to the Dependency Listeners. This allows a listener to add additional details to the context (before the XHR/fetch request is sent), and the initializer will be called after the request has completed.public addDependencyInitializer(dependencyInitializer: (item: IDependencyInitializerDetails) => boolean | void): IDependencyInitializerHandler
// Example Usage
let handler = appInsights.addDependencyInitializer((details) => {
details.item.xxxx = ""; // item is the telemetry event "before" it's been processed
// [Optional] To stop any event from being reported you can
// return false;
});
// [Optional] Remove the dependency initializer
handler.remove();
trackDependencyData(dependency:
IDependencyTelemetry
, properties?: { [key: string]: any }): void
TrackDependencyData function allows you to manually log a dependency call.
appInsights.trackDependencyData({absoluteUrl: 'some url', responseCode: 200, method: 'GET', id: 'some id'});
A sample is provided to show how to filter, modify, block and disable dependency data.