angular-application-insights icon indicating copy to clipboard operation
angular-application-insights copied to clipboard

i wanted to make a heartbeat in my angular application

Open mostafa-raafat opened this issue 5 years ago • 1 comments

when the application go offline i want to get an alert or i can know from azure Monitoring dashboard. also i can't finish any reference to use TrackRequest ?

Screen Shot 2019-05-27 at 4 16 08 PM

mostafa-raafat avatar May 27 '19 14:05 mostafa-raafat

My understanding from using ApplicationInsights is that Requests are typically for the server-side logging of requests made to an API. Typically all the interactions from the client-side (i.e. the Angular SPA), are through PageViews, Events, etc.

For your use-case, I would consider using TrackEvent instead.

// app-insight.service.ts (this package)
// https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackevent
  /**
   * Log a user action or other occurrence.
   * @param   name    A string to identify this event in the portal.
   * @param   properties  map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
   * @param   measurements    map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
   */
  trackEvent(eventName: string, eventProperties?: { [name: string]: string }, metricProperty?: { [name: string]: number }) {
    try {
      AppInsights.trackEvent(eventName, eventProperties, metricProperty);
    } catch (ex) {
      console.warn('Angular application insights Error [trackEvent]: ', ex);
    }
  }

You could then construct an Azure Logs query that would figure out the frequency that your application is losing internet connection and display a graph. For example:

customEvents
| summarize num_events = count() by bin(timestamp, 5min)
| render timechart

jonathankretzmer avatar Jun 13 '19 06:06 jonathankretzmer