question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] App Insights initialization setting 'enableAjaxErrorStatusText' is not working

See original GitHub issue

Description/Screenshot I was excited that I could replace my own workaround version to log failed ajax issues by retrieving also response body from XHR. #1156

However I tested this new setting enableAjaxErrorStatusText and I could not get it to work. Instead I get an exception when remote dependency data is being logged.

Exception I found:

“Failed to monitor XMLHttpRequest ‘readystatechange’ event handler, monitoring data for this ajax call may be incorrect.” Failed to read the ‘responseText’ property from ‘XMLHttpRequest’: The value is only accessible if the object’s ‘responseType’ is ‘’ or ‘text’ (was ‘json’).

Steps to Reproduce

  • lunch application with app-insights turned on
  • trigger any remote dependency where the response code for AJAX call is not successful.
  • check application insights tracking information in Network Tab and in Azure Portal
  • Instead of network dependency an exception is logged instead
import { AppInsightsEventNames } from '../../constants';
import {
  ApplicationInsights,
  IConfiguration,
  IConfig,
} from '@microsoft/applicationinsights-web';
import { ReactPlugin } from '@microsoft/applicationinsights-react-js';
import { isDevEnvironment } from '../../utils/utils';

class TelemetryService {
  reactPlugin: ReactPlugin;
  appInsights!: ApplicationInsights;

  constructor() {
    this.reactPlugin = new ReactPlugin();
  }

  initialize(instrumentationKey: string) {
    const config = {
      instrumentationKey,
      maxBatchInterval: 0,
      enableRequestHeaderTracking: true,
      enableResponseHeaderTracking: true,
      enableAjaxErrorStatusText: true,
      enableDebugExceptions: isDevEnvironment(),
    } as IConfiguration & IConfig;

    this.appInsights = new ApplicationInsights({
      config: { ...config, extensions: [this.reactPlugin] },
    });

    this.appInsights.loadAppInsights();

    this.appInsights.trackEvent(
      { name: AppInsightsEventNames.AppInsightsInitialized },
      { instrumentationKey }
    );
  }
}

export default new TelemetryService();
// init ai
import ai from '../middleware/telemetry/TelemetryService';
// ...
await ai.initialize('<environment_appinsights_instrumentation_key>');

Expected behavior

  • remote dependency data is logged to app insights in Azure Portal
  • logged telemetry item has custom property responseText with XHR response body information

Additional context This is the exception I get when I turn on setting enableDebugExceptions to true.

“AI (Internal): 16 message:“Failed to monitor XMLHttpRequest ‘readystatechange’ event handler, monitoring data for this ajax call may be incorrect.” props:”{ajaxDiagnosticsMessage:(url: ‘url removed’),exception:[object DOMException]{\stack:\Error: Failed to read the ‘responseText’ property from ‘XMLHttpRequest’: The value is only accessible if the object’s ‘responseType’ is ‘’ or ‘text’ (was ‘json’).\n at AjaxMonitor.onAjaxComplete (http://localhost:55867/static/js/2.chunk.js:19633:75)\n at XMLHttpRequest.<anonymous> (http://localhost:55867/static/js/2.chunk.js:19551:33)}}“” URL removed as it contains sensitive URL param image

image

Request body for https://dc.services.visualstudio.com/v2/track call:

 {
  "time": "2020-02-07T12:05:01.983Z",
  "iKey": "<removed>",
  "name": "Microsoft.ApplicationInsights.<removed>.Exception",
  "tags": {
    "ai.user.id": "<removed>",
    "ai.session.id": "<removed>",
    "ai.device.id": "browser",
    "ai.device.type": "Browser",
    "ai.operation.name": "<removed>",
    "ai.operation.id": "<removed>",
    "ai.internal.sdkVersion": "javascript:2.4.4"
  },
  "data": {
    "baseType": "ExceptionData",
    "baseData": {
      "ver": 2,
      "exceptions": [
        {
          "typeName": "Error",
          "message": "Uncaught [object Object]",
          "hasFullStack": true,
          "stack": "window.onerror@http://localhost:55867/static/js/2.chunk.js:18083:7",
          "parsedStack": [
            {
              "level": 0,
              "method": "window.onerror",
              "assembly": "window.onerror@http://localhost:55867/static/js/2.chunk.js:18083:7",
              "fileName": "http://localhost:55867/static/js/2.chunk.js",
              "line": 18083
            }
          ]
        }
      ],
      "severityLevel": 3
    }
  }
}

Removed any ID data.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MSNevcommented, Mar 11, 2020

Version 2.5.2 is now fully deployed to the CDN, closing as this should address this issue.

0reactions
github-actions[bot]commented, Aug 15, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot no data in Application Insights for .NET - Azure
This article provides troubleshooting information to help resolve issues when data is missing or doesn't appear when you're using Application ...
Read more >
microsoft/applicationinsights-properties-js - Yarn
Getting Started. Create an Application Insights resource in Azure by following these instructions. Grab the Instrumentation Key (aka "ikey") from the resource ...
Read more >
@microsoft/applicationinsights-common: Versions | Openbase
#1217 [BUG] App Insights fails when the XHR object is not extensible (or frozen); #1186 [BUG] App Insights initialization setting 'enableAjaxErrorStatusText ...
Read more >
Application Insights setting user in RequestTelemetry context ...
It should work. We are investigating the issue. I created an issue here: https://github.com/Microsoft/ApplicationInsights-dotnet/issues/111.
Read more >
@sigao/ng-application-insights - npm
Start using @sigao/ng-application-insights in your project by running `npm i ... There are no other projects in the npm registry using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found