UNPKG

9.34 kBTypeScriptView Raw
1/// <reference types="node" />
2import CorrelationContextManager = require("./AutoCollection/CorrelationContextManager");
3import QuickPulseClient = require("./Library/QuickPulseStateManager");
4import { IncomingMessage } from "http";
5import { SpanContext } from "@opentelemetry/api";
6import { IDisabledExtendedMetrics } from "./AutoCollection/NativePerformance";
7export import TelemetryClient = require("./Library/NodeClient");
8export import Contracts = require("./Declarations/Contracts");
9export import azureFunctionsTypes = require("./Library/Functions");
10export declare enum DistributedTracingModes {
11 /**
12 * (Default) Send Application Insights correlation headers
13 */
14 AI = 0,
15 /**
16 * Send both W3C Trace Context headers and back-compatibility Application Insights headers
17 */
18 AI_AND_W3C = 1
19}
20/**
21* The default client, initialized when setup was called. To initialize a different client
22* with its own configuration, use `new TelemetryClient(instrumentationKey?)`.
23*/
24export declare let defaultClient: TelemetryClient;
25export declare let liveMetricsClient: QuickPulseClient;
26/**
27 * Initializes the default client. Should be called after setting
28 * configuration options.
29 *
30 * @param setupString the Connection String or Instrumentation Key to use. Optional, if
31 * this is not specified, the value will be read from the environment
32 * variable APPLICATIONINSIGHTS_CONNECTION_STRING or APPINSIGHTS_INSTRUMENTATIONKEY.
33 * @returns {Configuration} the configuration class to initialize
34 * and start the SDK.
35 */
36export declare function setup(setupString?: string): typeof Configuration;
37/**
38 * Starts automatic collection of telemetry. Prior to calling start no
39 * telemetry will be *automatically* collected, though manual collection
40 * is enabled.
41 * @returns {ApplicationInsights} this class
42 */
43export declare function start(): typeof Configuration;
44/**
45 * Returns an object that is shared across all code handling a given request.
46 * This can be used similarly to thread-local storage in other languages.
47 * Properties set on this object will be available to telemetry processors.
48 *
49 * Do not store sensitive information here.
50 * Custom properties set on this object can be exposed in a future SDK
51 * release via outgoing HTTP headers.
52 * This is to allow for correlating data cross-component.
53 *
54 * This method will return null if automatic dependency correlation is disabled.
55 * @returns A plain object for request storage or null if automatic dependency correlation is disabled.
56 */
57export declare function getCorrelationContext(): CorrelationContextManager.CorrelationContext;
58/**
59 * **(Experimental!)**
60 * Starts a fresh context or propagates the current internal one.
61 */
62export declare function startOperation(context: SpanContext, name: string): CorrelationContextManager.CorrelationContext | null;
63export declare function startOperation(context: azureFunctionsTypes.Context, request: azureFunctionsTypes.HttpRequest): CorrelationContextManager.CorrelationContext | null;
64export declare function startOperation(context: azureFunctionsTypes.Context, name: string): CorrelationContextManager.CorrelationContext | null;
65export declare function startOperation(context: IncomingMessage | azureFunctionsTypes.HttpRequest, request?: never): CorrelationContextManager.CorrelationContext | null;
66/**
67 * Returns a function that will get the same correlation context within its
68 * function body as the code executing this function.
69 * Use this method if automatic dependency correlation is not propagating
70 * correctly to an asynchronous callback.
71 */
72export declare function wrapWithCorrelationContext<T extends Function>(fn: T, context?: CorrelationContextManager.CorrelationContext): T;
73/**
74 * The active configuration for global SDK behaviors, such as autocollection.
75 */
76export declare class Configuration {
77 static start: typeof start;
78 /**
79 * Sets the distributed tracing modes. If W3C mode is enabled, W3C trace context
80 * headers (traceparent/tracestate) will be parsed in all incoming requests, and included in outgoing
81 * requests. In W3C mode, existing back-compatibility AI headers will also be parsed and included.
82 * Enabling W3C mode will not break existing correlation with other Application Insights instrumented
83 * services. Default=AI
84 */
85 static setDistributedTracingMode(value: DistributedTracingModes): typeof Configuration;
86 /**
87 * Sets the state of console and logger tracking (enabled by default for third-party loggers only)
88 * @param value if true logger activity will be sent to Application Insights
89 * @param collectConsoleLog if true, logger autocollection will include console.log calls (default false)
90 * @returns {Configuration} this class
91 */
92 static setAutoCollectConsole(value: boolean, collectConsoleLog?: boolean): typeof Configuration;
93 /**
94 * Sets the state of exception tracking (enabled by default)
95 * @param value if true uncaught exceptions will be sent to Application Insights
96 * @returns {Configuration} this class
97 */
98 static setAutoCollectExceptions(value: boolean): typeof Configuration;
99 /**
100 * Sets the state of performance tracking (enabled by default)
101 * @param value if true performance counters will be collected every second and sent to Application Insights
102 * @param collectExtendedMetrics if true, extended metrics counters will be collected every minute and sent to Application Insights
103 * @returns {Configuration} this class
104 */
105 static setAutoCollectPerformance(value: boolean, collectExtendedMetrics?: boolean | IDisabledExtendedMetrics): typeof Configuration;
106 /**
107 * Sets the state of pre aggregated metrics tracking (enabled by default)
108 * @param value if true pre aggregated metrics will be collected every minute and sent to Application Insights
109 * @returns {Configuration} this class
110 */
111 static setAutoCollectPreAggregatedMetrics(value: boolean): typeof Configuration;
112 /**
113 * Sets the state of request tracking (enabled by default)
114 * @param value if true HeartBeat metric data will be collected every 15 mintues and sent to Application Insights
115 * @returns {Configuration} this class
116 */
117 static setAutoCollectHeartbeat(value: boolean): typeof Configuration;
118 /**
119 * Sets the state of request tracking (enabled by default)
120 * @param value if true requests will be sent to Application Insights
121 * @returns {Configuration} this class
122 */
123 static setAutoCollectRequests(value: boolean): typeof Configuration;
124 /**
125 * Sets the state of dependency tracking (enabled by default)
126 * @param value if true dependencies will be sent to Application Insights
127 * @returns {Configuration} this class
128 */
129 static setAutoCollectDependencies(value: boolean): typeof Configuration;
130 /**
131 * Sets the state of automatic dependency correlation (enabled by default)
132 * @param value if true dependencies will be correlated with requests
133 * @param 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.
134 * @returns {Configuration} this class
135 */
136 static setAutoDependencyCorrelation(value: boolean, useAsyncHooks?: boolean): typeof Configuration;
137 /**
138 * Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default)
139 * Note that this method only applies to the default client. Disk-backed retry caching is disabled by default for additional clients.
140 * For enable for additional clients, use client.channel.setUseDiskRetryCaching(true).
141 * These cached events are stored in your system or user's temporary directory and access restricted to your user when possible.
142 * @param value if true events that occured while client is offline will be cached on disk
143 * @param resendInterval The wait interval for resending cached events.
144 * @param maxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.
145 * @returns {Configuration} this class
146 */
147 static setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): typeof Configuration;
148 /**
149 * Enables debug and warning logging for AppInsights itself.
150 * @param enableDebugLogging if true, enables debug logging
151 * @param enableWarningLogging if true, enables warning logging
152 * @returns {Configuration} this class
153 */
154 static setInternalLogging(enableDebugLogging?: boolean, enableWarningLogging?: boolean): typeof Configuration;
155 /**
156 * Enables communication with Application Insights Live Metrics.
157 * @param enable if true, enables communication with the live metrics service
158 */
159 static setSendLiveMetrics(enable?: boolean): typeof Configuration;
160}
161/**
162 * Disposes the default client and all the auto collectors so they can be reinitialized with different configuration
163*/
164export declare function dispose(): void;