applicationinsights

  • Version 2.1.6
  • Published
  • 1.2 MB
  • 8 dependencies
  • MIT license

Install

npm i applicationinsights
yarn add applicationinsights
pnpm add applicationinsights

Overview

Microsoft Application Insights module for Node.js

Index

Variables

variable defaultClient

let defaultClient: TelemetryClient;
  • The default client, initialized when setup was called. To initialize a different client with its own configuration, use new TelemetryClient(instrumentationKey?).

variable liveMetricsClient

let liveMetricsClient: QuickPulseClient;

    Functions

    function dispose

    dispose: () => void;
    • Disposes the default client and all the auto collectors so they can be reinitialized with different configuration

    function getCorrelationContext

    getCorrelationContext: () => CorrelationContextManager.CorrelationContext;
    • Returns an object that is shared across all code handling a given request. This can be used similarly to thread-local storage in other languages. Properties set on this object will be available to telemetry processors.

      Do not store sensitive information here. Custom properties set on this object can be exposed in a future SDK release via outgoing HTTP headers. This is to allow for correlating data cross-component.

      This method will return null if automatic dependency correlation is disabled.

      Returns

      A plain object for request storage or null if automatic dependency correlation is disabled.

    function setup

    setup: (setupString?: string) => typeof Configuration;
    • Initializes the default client. Should be called after setting configuration options.

      Parameter setupString

      the Connection String or Instrumentation Key to use. Optional, if this is not specified, the value will be read from the environment variable APPLICATIONINSIGHTS_CONNECTION_STRING or APPINSIGHTS_INSTRUMENTATIONKEY.

      Returns

      {Configuration} the configuration class to initialize and start the SDK.

    function start

    start: () => typeof Configuration;
    • Starts automatic collection of telemetry. Prior to calling start no telemetry will be *automatically* collected, though manual collection is enabled.

      Returns

      {ApplicationInsights} this class

    function startOperation

    startOperation: {
    (
    context: any,
    name: string
    ): CorrelationContextManager.CorrelationContext | null;
    (
    context: azureFunctionsTypes.Context,
    request: azureFunctionsTypes.HttpRequest
    ): CorrelationContextManager.CorrelationContext;
    (
    context: azureFunctionsTypes.Context,
    name: string
    ): CorrelationContextManager.CorrelationContext;
    (context: any, request?: never): CorrelationContextManager.CorrelationContext;
    };
    • **(Experimental!)** Starts a fresh context or propagates the current internal one.

    function wrapWithCorrelationContext

    wrapWithCorrelationContext: <T extends Function>(
    fn: T,
    context?: CorrelationContextManager.CorrelationContext
    ) => T;
    • Returns a function that will get the same correlation context within its function body as the code executing this function. Use this method if automatic dependency correlation is not propagating correctly to an asynchronous callback.

    Classes

    class Configuration

    class Configuration {}
    • The active configuration for global SDK behaviors, such as autocollection.

    property start

    static start: () => typeof Configuration;

      method setAutoCollectConsole

      static setAutoCollectConsole: (
      value: boolean,
      collectConsoleLog?: boolean
      ) => typeof Configuration;
      • Sets the state of console and logger tracking (enabled by default for third-party loggers only)

        Parameter value

        if true logger activity will be sent to Application Insights

        Parameter collectConsoleLog

        if true, logger autocollection will include console.log calls (default false)

        Returns

        {Configuration} this class

      method setAutoCollectDependencies

      static setAutoCollectDependencies: (value: boolean) => typeof Configuration;
      • Sets the state of dependency tracking (enabled by default)

        Parameter value

        if true dependencies will be sent to Application Insights

        Returns

        {Configuration} this class

      method setAutoCollectExceptions

      static setAutoCollectExceptions: (value: boolean) => typeof Configuration;
      • Sets the state of exception tracking (enabled by default)

        Parameter value

        if true uncaught exceptions will be sent to Application Insights

        Returns

        {Configuration} this class

      method setAutoCollectHeartbeat

      static setAutoCollectHeartbeat: (value: boolean) => typeof Configuration;
      • Sets the state of request tracking (enabled by default)

        Parameter value

        if true HeartBeat metric data will be collected every 15 mintues and sent to Application Insights

        Returns

        {Configuration} this class

      method setAutoCollectPerformance

      static setAutoCollectPerformance: (
      value: boolean,
      collectExtendedMetrics?: boolean | IDisabledExtendedMetrics
      ) => typeof Configuration;
      • Sets the state of performance tracking (enabled by default)

        Parameter value

        if true performance counters will be collected every second and sent to Application Insights

        Parameter collectExtendedMetrics

        if true, extended metrics counters will be collected every minute and sent to Application Insights

        Returns

        {Configuration} this class

      method setAutoCollectPreAggregatedMetrics

      static setAutoCollectPreAggregatedMetrics: (
      value: boolean
      ) => typeof Configuration;
      • Sets the state of pre aggregated metrics tracking (enabled by default)

        Parameter value

        if true pre aggregated metrics will be collected every minute and sent to Application Insights

        Returns

        {Configuration} this class

      method setAutoCollectRequests

      static setAutoCollectRequests: (value: boolean) => typeof Configuration;
      • Sets the state of request tracking (enabled by default)

        Parameter value

        if true requests will be sent to Application Insights

        Returns

        {Configuration} this class

      method setAutoDependencyCorrelation

      static setAutoDependencyCorrelation: (
      value: boolean,
      useAsyncHooks?: boolean
      ) => typeof Configuration;
      • Sets the state of automatic dependency correlation (enabled by default)

        Parameter value

        if true dependencies will be correlated with requests

        Parameter useAsyncHooks

        if true, forces use of experimental async_hooks module to provide correlation. If false, instead uses only patching-based techniques. If left blank, the best option is chosen for you based on your version of Node.js.

        Returns

        {Configuration} this class

      method setDistributedTracingMode

      static setDistributedTracingMode: (
      value: DistributedTracingModes
      ) => typeof Configuration;
      • Sets the distributed tracing modes. If W3C mode is enabled, W3C trace context headers (traceparent/tracestate) will be parsed in all incoming requests, and included in outgoing requests. In W3C mode, existing back-compatibility AI headers will also be parsed and included. Enabling W3C mode will not break existing correlation with other Application Insights instrumented services. Default=AI

      method setInternalLogging

      static setInternalLogging: (
      enableDebugLogging?: boolean,
      enableWarningLogging?: boolean
      ) => typeof Configuration;
      • Enables debug and warning logging for AppInsights itself.

        Parameter enableDebugLogging

        if true, enables debug logging

        Parameter enableWarningLogging

        if true, enables warning logging

        Returns

        {Configuration} this class

      method setSendLiveMetrics

      static setSendLiveMetrics: (enable?: boolean) => typeof Configuration;
      • Enables communication with Application Insights Live Metrics.

        Parameter enable

        if true, enables communication with the live metrics service

      method setUseDiskRetryCaching

      static setUseDiskRetryCaching: (
      value: boolean,
      resendInterval?: number,
      maxBytesOnDisk?: number
      ) => typeof Configuration;
      • Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default) Note that this method only applies to the default client. Disk-backed retry caching is disabled by default for additional clients. For enable for additional clients, use client.channel.setUseDiskRetryCaching(true). These cached events are stored in your system or user's temporary directory and access restricted to your user when possible.

        Parameter value

        if true events that occured while client is offline will be cached on disk

        Parameter resendInterval

        The wait interval for resending cached events.

        Parameter maxBytesOnDisk

        The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.

        Returns

        {Configuration} this class

      Enums

      enum DistributedTracingModes

      enum DistributedTracingModes {
      AI = 0,
      AI_AND_W3C = 1,
      }

        member AI

        AI = 0
        • (Default) Send Application Insights correlation headers

        member AI_AND_W3C

        AI_AND_W3C = 1
        • Send both W3C Trace Context headers and back-compatibility Application Insights headers

        Package Files (1)

        Dependencies (8)

        Dev Dependencies (10)

        Peer Dependencies (0)

        No peer dependencies.

        Badge

        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/applicationinsights.

        • Markdown
          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/applicationinsights)
        • HTML
          <a href="https://www.jsdocs.io/package/applicationinsights"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>