6 FAQ
Kamil Szostak редактировал(а) эту страницу 2017-10-30 10:33:33 -07:00

What is ai.0.js?

This file contains a minified JavaScript SDK script. The snippet that you put on your website has a very limited functionality to keep it as small as possible. The snippet will queue all events and download the full SDK script (ai.0.js). Once the full script is downloaded, it will replace the window.appInsights object and send all queued telemetry.

Can I use a local copy of ai.0.js?

We recommend downloading it from a default location (https://az416426.vo.msecnd.net/scripts/a/ai.0.js), which leverages Azure CDN to deliver the script fast. But it is possible to use a local copy, see url config. Please keep in mind that you will need to update it manually if you want to receive the latest features.

How do I exclude parts of telemetry from sending?

The easiest way is to write your own telemetryInitializer which will modify your data. TelemetryInitializer can also block data from sending.

Something weird is going on... How do I debug the JS SDK?

To make the debugging process easier you can enableDebug mode and turn on the verboseLogging (see config).

You can also use an un-minified version of the JS SDK script ai.js. The easiest way to use it is to temporarily change snippet to load the ai.js file instead of ai.0.js (you can change the URL in the snippet).

When I debug the SDK a lot of methods of the appInsights object are missing

Most likely you hit a breakpoint before the full SDK was downloaded and you're only seeing methods defined in the snippet. The snippet only defines stubs of all track*() and [set|clear]AuthenticatedUserContext functions and records if they were invoked. When the full library is downloaded (ai.0.js) all those stubs are replaced with real methods and all previously recorded methods are actually invoked and processed.

I'm seeing a lot of Uncaught [object Object] errors in Application Insights in Azure Portal

The JS SDK is using a message field from the Error object as an error message. If you throw something which is not an Error it will call toString and use that as an error message.

throw { a: '1', b: '2' };                           // "Uncaught [object Object]"
throw { a: '1', b: '2', toString: () => 'a + b' };  // "Uncaught a + b"

What information is the SDK storing in cookies?

The JS SDK is storing the following information in cookies:

Name Purpose Expiration Retires
ai_session Session tracking 30 minutes End of session
ai_user User tracking 365 days Never
ai_authUser User tracking 365 days When user logs out

You can tell the SDK not to use cookies by setting isCookieUseDisabled: true in the config. Please keep in mind that session and user tracking will by disabled and some charts will have limited data in Azure Portal.

How to set a custom cloud_rolename?

To set a customer cloud_rolename you need to write a telemetryInitializer function and set an ai.device.roleName tag on each envelope. For a full list of tags check ContextTagKeys.ts.

AppInsights.queue.push(() => {
    AppInsights.context.addTelemetryInitializer((envelope: Microsoft.ApplicationInsights.IEnvelope) => {
                    envelope.tags['ai.device.roleName'] = "MyClientApp";
                });
});