ulteam-scripts AzureLogger

AzureLogger class

Work with Azure Application Insights

Sample

import { AzureLogger } from "../../log/AzureLogger";


export class TestAzureLogger {
  public static Test() {

    /** create logger instance */
    const logger: AzureLogger = new AzureLogger(
      /** Application Insights instrumentation key */
      "c7310ee5-8c8f-4c26-87b5-f166c9c4e8a8",
      /** user authentification id */
      "user@sample.com",
      /** project name */
      "ulteam.scripts",
      /** main list item id */
      { itemId: 123 }
    );

    const pageTrackingFilters = [ "localhost" ];

    /** Initialize Application Insights scripts */
    logger.init(true, pageTrackingFilters);
    /** type logger.init(false) if you don't need tracking Page View */

    /** add custom event */
    logger.trackEvent("Start.TestAzureLogger"); 

    try {
      /** exception example */
      throw new Error("JavaScript error message");
    }
    catch (e) {
      logger.trackException(e);
    }

    /** add custom event */
    logger.trackEvent("Finish");
  }
}

Constructors

Name Description
new AzureLogger(instrumentationKey: string, authenticatedUserId: string, projectName: string, commonProperties: undefined | { [key: string]: any }) Set configuration
instrumentationKey: Azure Application Insight App instrumentation key
authenticatedUserId: The authenticated user id. A unique and persistent string that represents each authenticated user in the service.
It should not contain commas, semi-colons, equal signs, spaces, or vertical-bars
If userEmail is not undefined then Sets the autheticated user id and the account id in this session (setAuthenticatedUserContext API method).

projectName: Your project name. Name should be contain only english letters and ‘dot’ char. For example: ‘SampleCompany’
commonProperties: There are properties associated to all events, like ListItem.Id. This properties will be added to Event Custom Properties.

Properties

Name Static Description
authenticatedUserId: string   The authenticated user id. A unique and persistent string that represents each authenticated user in the service.
commonProperties: { [key: string]: any }   There are properties associated to all events.
context: ApplicationInsights   Context of Application Insights.
projectName: string   Your project name.

Methods

Name Returns Static Description
init(addPageTracking: undefined | false | true, pageTrackingFilter: string[]) void   Download full Application Insights script from CDN and initialize it with instrumentation key.
addPageTracking: Activate page tracking by calling trackPageView method. Default value is true.
pageTrackingFilter: Filter your Network by parts of url.
If url has one of this filters then it will be added to Application Insights Remote Dependencies
trackEvent(eventName: string, properties: undefined | { [key: string]: any }) void   Add custom event (log line).
In Azure Application Insights App search this event by this template: ‘{projectName}.JS.{eventName}’.
eventName: Custom event name.
It should contains only english letters without spaces.

properties: There are properties associated only to this event. This properties will be added to Event Custom Properties.
trackException(exception: Error, properties: undefined | { [key: string]: any }) void   Add exception.
In Azure Application Insights App search this event by this template: ‘{projectName}.JS.Exception’.
exception: JS/TS exception.
properties: There are properties associated only to this event. This properties will be added to Event Custom Properties.
trackPageView(pageTrackingFilter: string[], properties: undefined | { [key: string]: any }) void   Logs user session info about browser, network requests, etc.
In Azure Application Insights App search this event by this template: ‘{projectName}.JS.PageView’.
pageTrackingFilter: Filter your Network by parts of url.
If url has one of this filters then it will be added to Application Insights Remote Dependencies

properties: There are properties associated only to this event. This properties will be added to Event Custom Properties.

Updated: