testAI

Microsoft Application Insights JavaScript SDK - Dependencies Plugin

Dependencies Plugin for the Application Insights Javascript SDK

Configuration

ICorrelationConfig

Functions

Dependency Listeners

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 :-

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();

Dependency Initializers

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 :-

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();

Track Dependency

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'});

Sample

A sample is provided to show how to filter, modify, block and disable dependency data.