or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcontext-correlation.mdindex.mdinitialization.mdlegacy-api.mdtelemetry-client.mdtelemetry-types.md
tile.json

configuration.mddocs/

Configuration Management

Configuration class and methods for controlling automatic telemetry collection behaviors in Application Insights. The Configuration class provides a fluent API for enabling/disabling various auto-collection features and customizing telemetry behavior.

Capabilities

Configuration Class

Static configuration class for managing auto-collection settings and SDK behavior.

/**
 * The active configuration for global SDK behaviors, such as auto collection
 */
class Configuration {
  /**
   * Start automatic telemetry collection
   * @returns Configuration instance for chaining
   */
  static start(): Configuration;

  /**
   * Sets the distributed tracing mode
   * @param value - Distributed tracing mode (currently only W3C supported)
   * @returns Configuration instance for chaining
   */
  static setDistributedTracingMode(value: number): Configuration;

  /**
   * Sets the state of console and logger tracking
   * @param value - Enable logger activity tracking
   * @param collectConsoleLog - Include console.log calls (default false)
   * @returns Configuration instance for chaining
   */
  static setAutoCollectConsole(value: boolean, collectConsoleLog?: boolean): Configuration;

  /**
   * Sets the state of exception tracking
   * @param value - Enable automatic exception tracking (default true)
   * @returns Configuration instance for chaining
   */
  static setAutoCollectExceptions(value: boolean): Configuration;

  /**
   * Sets the state of performance tracking
   * @param value - Enable performance counter collection
   * @param collectExtendedMetrics - Enable extended metrics collection
   * @returns Configuration instance for chaining
   */
  static setAutoCollectPerformance(value: boolean, collectExtendedMetrics?: any): Configuration;

  /**
   * Sets the state of pre-aggregated metrics tracking
   * @param value - Enable pre-aggregated metrics collection
   * @returns Configuration instance for chaining
   */
  static setAutoCollectPreAggregatedMetrics(value: boolean): Configuration;

  /**
   * Sets the state of heartbeat tracking
   * @param value - Enable heartbeat metric collection every 15 minutes
   * @returns Configuration instance for chaining
   */
  static setAutoCollectHeartbeat(value: boolean): Configuration;

  /**
   * Sets the state of Web snippet injection
   * @param value - Enable Web snippet injection in server responses
   * @param webSnippetConnectionString - Connection string for Web snippet (optional)
   * @returns Configuration instance for chaining
   */
  static enableWebInstrumentation(value: boolean, webSnippetConnectionString?: string): Configuration;

  /**
   * Sets the state of request tracking
   * @param value - Enable automatic request tracking (default true)
   * @returns Configuration instance for chaining
   */
  static setAutoCollectRequests(value: boolean): Configuration;

  /**
   * Sets the state of dependency tracking
   * @param value - Enable automatic dependency tracking (default true)
   * @returns Configuration instance for chaining
   */
  static setAutoCollectDependencies(value: boolean): Configuration;

  /**
   * Sets the state of automatic dependency correlation
   * @param value - Enable dependency correlation with requests
   * @param useAsyncHooks - Force use of async_hooks module (optional)
   * @returns Configuration instance for chaining
   */
  static setAutoDependencyCorrelation(value: boolean, useAsyncHooks?: boolean): Configuration;

  /**
   * Enable or disable disk-backed retry caching
   * @param value - Enable disk-based caching for offline events
   * @param resendInterval - Wait interval for resending cached events
   * @param maxBytesOnDisk - Maximum cache directory size in bytes
   * @returns Configuration instance for chaining
   */
  static setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): Configuration;

  /**
   * Enables debug and warning logging for Application Insights
   * @param enableDebugLogger - Enable debug logging
   * @param enableWarningLogger - Enable warning logging
   * @returns Configuration instance for chaining
   */
  static setInternalLogging(enableDebugLogger?: boolean, enableWarningLogger?: boolean): Configuration;

  /**
   * Enable automatic incoming request tracking for Azure Functions
   * @param value - Enable auto collection of incoming requests
   * @returns Configuration instance for chaining
   */
  static setAutoCollectIncomingRequestAzureFunctions(value: boolean): Configuration;

  /**
   * Enables communication with Application Insights Live Metrics
   * @param enable - Enable live metrics communication
   * @returns Configuration instance for chaining
   */
  static setSendLiveMetrics(enable?: boolean): Configuration;

  /**
   * Set the options for Azure Monitor OpenTelemetry
   * @param value - Azure Monitor OpenTelemetry options
   * @returns Configuration instance for chaining
   */
  static setAzureMonitorOptions(value: AzureMonitorOpenTelemetryOptions): Configuration;
}

Request Tracking Configuration

Control automatic tracking of incoming HTTP requests.

/**
 * Sets the state of request tracking
 * @param value - Enable automatic request tracking (default true)
 * @returns Configuration instance for chaining
 */
static setAutoCollectRequests(value: boolean): Configuration;

Usage Examples:

const appInsights = require("applicationinsights");

// Enable request tracking (default behavior)
appInsights
  .setup()
  .setAutoCollectRequests(true)
  .start();

// Disable request tracking
appInsights
  .setup()
  .setAutoCollectRequests(false)
  .start();

Dependency Tracking Configuration

Control automatic tracking of outgoing dependency calls (HTTP, database, etc.).

/**
 * Sets the state of dependency tracking
 * @param value - Enable automatic dependency tracking (default true)
 * @returns Configuration instance for chaining
 */
static setAutoCollectDependencies(value: boolean): Configuration;

/**
 * Sets the state of automatic dependency correlation
 * @param value - Enable dependency correlation with requests
 * @param useAsyncHooks - Force use of async_hooks module for correlation
 * @returns Configuration instance for chaining
 */
static setAutoDependencyCorrelation(value: boolean, useAsyncHooks?: boolean): Configuration;

Usage Examples:

// Enable dependency tracking with correlation
appInsights
  .setup()
  .setAutoCollectDependencies(true)
  .setAutoDependencyCorrelation(true)
  .start();

// Disable dependency correlation but keep tracking
appInsights
  .setup()
  .setAutoCollectDependencies(true)
  .setAutoDependencyCorrelation(false)
  .start();

Exception Tracking Configuration

Control automatic tracking of unhandled exceptions.

/**
 * Sets the state of exception tracking
 * @param value - Enable automatic exception tracking (default true)
 * @returns Configuration instance for chaining
 */
static setAutoCollectExceptions(value: boolean): Configuration;

Usage Examples:

// Enable exception tracking (default)
appInsights
  .setup()
  .setAutoCollectExceptions(true)
  .start();

// Disable automatic exception tracking
appInsights
  .setup()
  .setAutoCollectExceptions(false)  
  .start();

Performance Counter Configuration

Control automatic collection of performance metrics and system counters.

/**
 * Sets the state of performance tracking
 * @param value - Enable performance counter collection
 * @param collectExtendedMetrics - Enable extended metrics collection
 * @returns Configuration instance for chaining
 */
static setAutoCollectPerformance(value: boolean, collectExtendedMetrics?: any): Configuration;

/**
 * Sets the state of pre-aggregated metrics tracking
 * @param value - Enable pre-aggregated metrics collection
 * @returns Configuration instance for chaining
 */
static setAutoCollectPreAggregatedMetrics(value: boolean): Configuration;

/**
 * Sets the state of heartbeat tracking
 * @param value - Enable heartbeat metric collection every 15 minutes
 * @returns Configuration instance for chaining
 */
static setAutoCollectHeartbeat(value: boolean): Configuration;

Usage Examples:

// Enable all performance tracking
appInsights
  .setup()
  .setAutoCollectPerformance(true, true) // Basic + extended metrics
  .setAutoCollectPreAggregatedMetrics(true)
  .setAutoCollectHeartbeat(true)
  .start();

// Minimal performance tracking
appInsights
  .setup()
  .setAutoCollectPerformance(true, false) // Basic metrics only
  .setAutoCollectPreAggregatedMetrics(false)
  .setAutoCollectHeartbeat(false)
  .start();

Console and Logger Configuration

Control automatic tracking of console and third-party logger output.

/**
 * Sets the state of console and logger tracking
 * @param value - Enable logger activity tracking
 * @param collectConsoleLog - Include console.log calls (default false)  
 * @returns Configuration instance for chaining
 */
static setAutoCollectConsole(value: boolean, collectConsoleLog?: boolean): Configuration;

Usage Examples:

// Track third-party loggers only (default)
appInsights
  .setup()
  .setAutoCollectConsole(true, false)
  .start();

// Track third-party loggers AND console.log
appInsights
  .setup()
  .setAutoCollectConsole(true, true)
  .start();

// Disable all console/logger tracking
appInsights
  .setup()
  .setAutoCollectConsole(false)
  .start();

Caching and Offline Configuration

Control disk-based retry caching for offline scenarios.

/**
 * Enable or disable disk-backed retry caching
 * @param value - Enable disk-based caching for offline events
 * @param resendInterval - Wait interval for resending cached events (ms)
 * @param maxBytesOnDisk - Maximum cache directory size in bytes
 * @returns Configuration instance for chaining
 */
static setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): Configuration;

Usage Examples:

// Enable disk caching with custom settings
appInsights
  .setup()
  .setUseDiskRetryCaching(
    true,           // Enable caching
    30000,          // Resend every 30 seconds
    50 * 1024 * 1024 // Max 50MB cache
  )
  .start();

// Disable disk caching
appInsights
  .setup()
  .setUseDiskRetryCaching(false)
  .start();

Live Metrics Configuration

Control real-time telemetry streaming to Application Insights Live Metrics.

/**
 * Enables communication with Application Insights Live Metrics
 * @param enable - Enable live metrics communication
 * @returns Configuration instance for chaining
 */
static setSendLiveMetrics(enable?: boolean): Configuration;

Usage Examples:

// Enable Live Metrics
appInsights
  .setup()
  .setSendLiveMetrics(true)
  .start();

// Disable Live Metrics (default)
appInsights
  .setup()
  .setSendLiveMetrics(false)
  .start();

Web Instrumentation Configuration

Control client-side JavaScript injection for web applications.

/**
 * Sets the state of Web snippet injection
 * @param value - Enable Web snippet injection in server responses
 * @param webSnippetConnectionString - Connection string for Web snippet (optional)
 * @returns Configuration instance for chaining
 */
static enableWebInstrumentation(value: boolean, webSnippetConnectionString?: string): Configuration;

Usage Examples:

// Enable web instrumentation with same connection string
appInsights
  .setup()
  .enableWebInstrumentation(true)
  .start();

// Enable web instrumentation with different connection string
appInsights
  .setup()
  .enableWebInstrumentation(
    true, 
    "InstrumentationKey=different-key;IngestionEndpoint=..."
  )
  .start();

Azure Functions Configuration

Special configuration for Azure Functions environments.

/**
 * Enable automatic incoming request tracking for Azure Functions
 * @param value - Enable auto collection of incoming requests
 * @returns Configuration instance for chaining
 */
static setAutoCollectIncomingRequestAzureFunctions(value: boolean): Configuration;

Usage Examples:

// Azure Functions specific configuration
appInsights
  .setup()
  .setAutoCollectIncomingRequestAzureFunctions(true)
  .setAutoCollectRequests(true)
  .start();

Complete Configuration Example

const appInsights = require("applicationinsights");

// Comprehensive configuration
appInsights
  .setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING)
  .setAutoCollectRequests(true)
  .setAutoCollectPerformance(true, true)
  .setAutoCollectExceptions(true)
  .setAutoCollectDependencies(true)
  .setAutoDependencyCorrelation(true, false)
  .setAutoCollectConsole(true, false)
  .setAutoCollectPreAggregatedMetrics(true)
  .setAutoCollectHeartbeat(true)
  .setUseDiskRetryCaching(true, 30000, 50 * 1024 * 1024)
  .setInternalLogging(false, true) // Warning logs only
  .setSendLiveMetrics(false)
  .enableWebInstrumentation(false)
  .start();

console.log("Application Insights configured and started");