ApplicationInsights-JS icon indicating copy to clipboard operation
ApplicationInsights-JS copied to clipboard

[BUG] Application Insights Duration is incorrect for Dynamics CRM Page On load and On Save

Open harshnagb opened this issue 3 years ago • 2 comments

Description/Screenshot

  1. We are implement the custom logic in Dynamics CRM for Page on load and on save to capture the performance in application insight telemetry.
  2. But Duration values are incorrect when compare with Dynamics CRM Monitor tools
  3. We had implemented code using GitHub sample code.
  4. Application Insights Value is 22 Sec and Dynamics CRM Monitor Value is 6 Sec Sample Code URL: https://github.com/Microsoft/ApplicationInsights-JS#snippet-setup-ignore-if-using-npm-setup

Steps to Reproduce

  1. Create a ts or js file
  2. Execute on load or on save of Dynamics CRM form
  3. Go to application insights and check the duration
  • OS/Browser: Edge, Chrome
  • SDK Version [e.g. 22]: 2.0
  • How you initialized the SDK: it is typescript file -import { ApplicationInsights, IPageViewTelemetry, PageView, RemoteDependencyData } from "@microsoft/applicationinsights-web";

Expected behavior

  1. Both Application Insights and CRM Monitor tools values should be same

From: Harsh

  • Please contact me ASAP : +91 8121909225 or +91 9966784569
  • Alternative Email Address: [email protected]
  • This issue happened in PROD Instance.

harshnagb avatar Aug 12 '22 11:08 harshnagb

The duration reported by the SDK is based on several factors, but can basically be broken down to

  • The time between when the browser starts page navigation and when the "page load" event is fired; AND the SDK script has been loaded from the CDN AND it finishes initialization and reports the event (this last step is when the "end time" is taken as a snapshot), it does not use the browser reported "time" that is part of the Page View Performance metrics and the times reported are generally network related and not event (execution) driven.

Generally, the ApplicationInsights SDK "pageLoad" duration is a more consistent representation of the actual user experience as this more closely tracks the point at which the page generally becomes "usable" by the user (because all of the scripts have been loaded and initialized).

So, when the browser takes a long time to fetch and run the SDK from the CDN (due to network performance, client network connectivity, a large number scripts queued/loaded before the SDK or they are just large in size (consuming the available bandwidth) this will delay the point to which the SDK is initialized which will affect the reported value for page load.

So while, I'm not familiar with what the exact values reported by the "Dynamics CRM Monitor tools" it sounds like one or more of the events above occurred.

A fiddler or http archive (F12 dev console) would be one possible way to investigate and identify which specific issue(s) may be causing the delay (assuming it's reproducible).

Key points

  • The ai.2.min.js script MUST be downloaded from the CDN
  • The browser must execute (run) the script (scripts are generally executed in the order they are appear on the HTML doc, so even if the browser has "downloaded" the script it may not be executed until after other scripts (included in the <head /> of the HTML document) have also been downloaded and executed.
  • The page load event does not fire effectively until ALL of the scripts defined in the <head /> of the page are loaded and run as well as any defined "dependent" resources.

MSNev avatar Aug 12 '22 19:08 MSNev

@MSNev

  • we are already using CDN files only.
  • we can not added the DOM element in Dynamics CRM Application

harshnagb avatar Aug 23 '22 11:08 harshnagb

This Issue will be closed in 30 days. Please remove the "Stale" label or comment to avoid closure with no action.

github-actions[bot] avatar Jun 20 '23 07:06 github-actions[bot]