UNPKG

14.6 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { TokenCredential } from "@azure/core-auth";
4import * as http from "http";
5import https = require("https");
6import { Context as AzureFnV3Context, HttpRequest as AzureFnV3Request, TraceContext as AzureFnV3TraceContext } from "@azure/functions-old";
7import { InvocationContext as AzureFnV4Context, HttpRequest as AzureFnV4Request } from "@azure/functions";
8export declare const UNSUPPORTED_MSG = "Please reference the Azure Monitor OpenTelemetry Migration Doc for more information. If this functionality is required, please revert to Application Insights 2.X SDK.";
9export declare enum DistributedTracingModes {
10 /**
11 * Send Application Insights correlation headers
12 */
13 AI = 0,
14 /**
15 * (Default) Send both W3C Trace Context headers and back-compatibility Application Insights headers
16 */
17 AI_AND_W3C = 1
18}
19/**
20 * Interface which defines which specific extended metrics should be disabled
21 *
22 * @export
23 * @interface IDisabledExtendedMetrics
24 */
25export interface IDisabledExtendedMetrics {
26 gc?: boolean;
27 heap?: boolean;
28 loop?: boolean;
29}
30export interface ITraceparent {
31 legacyRootId: string;
32 parentId: string;
33 spanId: string;
34 traceFlag: string;
35 traceId: string;
36 version: string;
37}
38export interface ITracestate {
39 fieldmap: string[];
40}
41export interface ICorrelationContext {
42 operation: {
43 name: string;
44 id: string;
45 parentId: string;
46 traceparent?: ITraceparent;
47 tracestate?: ITracestate;
48 };
49 /** Do not store sensitive information here.
50 * Properties here are exposed via outgoing HTTP headers for correlating data cross-component.
51 */
52 customProperties: ICustomProperties;
53}
54export interface ICustomProperties {
55 /**
56 * Get a custom property from the correlation context
57 */
58 getProperty(key: string): string;
59 /**
60 * Store a custom property in the correlation context.
61 * Do not store sensitive information here.
62 * Properties stored here are exposed via outgoing HTTP headers for correlating data cross-component.
63 * The characters ',' and '=' are disallowed within keys or values.
64 */
65 setProperty(key: string, value: string): void;
66}
67/**
68 * The context object can be used for writing logs, reading data from bindings, setting outputs and using
69 * the context.done callback when your exported function is synchronous. A context object is passed
70 * to your function from the Azure Functions runtime on function invocation.
71 */
72export interface Context {
73 traceContext: TraceContext;
74}
75/**
76 * HTTP request object. Provided to your function when using HTTP Bindings.
77 */
78export interface HttpRequest {
79 method: string | null;
80 url: string;
81 headers: {
82 [key: string]: string;
83 };
84}
85/**
86 * TraceContext information to enable distributed tracing scenarios.
87 */
88export interface TraceContext {
89 /** Describes the position of the incoming request in its trace graph in a portable, fixed-length format. */
90 traceparent: string | null | undefined;
91 /** Extends traceparent with vendor-specific data. */
92 tracestate: string | null | undefined;
93 /** Holds additional properties being sent as part of request telemetry. */
94 attributes: {
95 [k: string]: string;
96 } | null | undefined;
97}
98/**
99 * Subset of Connection String fields which this SDK can parse. Lower-typecased to
100 * allow for case-insensitivity across field names
101 * @type ConnectionStringKey
102 */
103export interface ConnectionString {
104 instrumentationkey?: string;
105 ingestionendpoint?: string;
106 liveendpoint?: string;
107 location?: string;
108 endpointsuffix?: string;
109}
110export declare type ConnectionStringKey = "instrumentationkey" | "ingestionendpoint" | "liveendpoint" | "location" | "endpointsuffix";
111export declare type AzureFnContext = AzureFnV3Context | AzureFnV4Context;
112export declare type AzureFnRequest = AzureFnV3Request | AzureFnV4Request;
113export declare type AzureFnTraceContext = AzureFnV3TraceContext & AzureFnV4Context["traceContext"];
114export interface IBaseConfig {
115 /** The ingestion endpoint to send telemetry payloads to */
116 endpointUrl: string;
117 /** The maximum number of telemetry items to include in a payload to the ingestion endpoint (Default 250) */
118 maxBatchSize: number;
119 /** The maximum amount of time to wait for a payload to reach maxBatchSize (Default 15000) */
120 maxBatchIntervalMs: number;
121 /** A flag indicating if telemetry transmission is disabled (Default false) */
122 disableAppInsights: boolean;
123 /** The percentage of telemetry items tracked that should be transmitted (Default 100) */
124 samplingPercentage: number;
125 /** A list of domains to exclude from cross-component header injection */
126 correlationHeaderExcludedDomains: string[];
127 /** A proxy server for SDK HTTP traffic (Optional, Default pulled from `http_proxy` environment variable) */
128 proxyHttpUrl: string;
129 /** A proxy server for SDK HTTPS traffic (Optional, Default pulled from `https_proxy` environment variable) */
130 proxyHttpsUrl: string;
131 /** Disable including legacy headers in outgoing requests, x-ms-request-id */
132 ignoreLegacyHeaders: boolean;
133 /**
134 * Sets the distributed tracing modes. If W3C mode is enabled, W3C trace context
135 * headers (traceparent/tracestate) will be parsed in all incoming requests, and included in outgoing
136 * requests. In W3C mode, existing back-compatibility AI headers will also be parsed and included.
137 * Enabling W3C mode will not break existing correlation with other Application Insights instrumented
138 * services. Default=AI
139 */
140 distributedTracingMode: DistributedTracingModes;
141 /**
142 * Sets the state of console
143 * if true logger activity will be sent to Application Insights
144 */
145 enableAutoCollectExternalLoggers: boolean;
146 /**
147 * Sets the state of logger tracking (enabled by default for third-party loggers only)
148 * if true, logger autocollection will include console.log calls (default false)
149 */
150 enableAutoCollectConsole: boolean;
151 /**
152 * Sets tracking error logs from loggers (console, bunyan, winston) as traces. If true errors will be returned as traces
153 */
154 enableLoggerErrorToTrace: boolean;
155 /**
156 * Sets the state of exception tracking (enabled by default)
157 * if true uncaught exceptions will be sent to Application Insights
158 */
159 enableAutoCollectExceptions: boolean;
160 /**
161 * Sets the state of performance tracking (enabled by default)
162 * if true performance counters will be collected every second and sent to Application Insights
163 */
164 enableAutoCollectPerformance: boolean;
165 /**
166 * Sets the state of performance tracking (enabled by default)
167 * if true, extended metrics counters will be collected every minute and sent to Application Insights
168 */
169 enableAutoCollectExtendedMetrics: boolean | IDisabledExtendedMetrics;
170 /**
171 * Sets the state of pre aggregated metrics tracking (enabled by default)
172 * if true pre aggregated metrics will be collected every minute and sent to Application Insights
173 */
174 enableAutoCollectPreAggregatedMetrics: boolean;
175 /**
176 * Sets the state of request tracking (enabled by default)
177 * if true HeartBeat metric data will be collected every 15 minutes and sent to Application Insights
178 */
179 enableAutoCollectHeartbeat: boolean;
180 /**
181 * Sets the state of request tracking (enabled by default)
182 * if true requests will be sent to Application Insights
183 */
184 enableAutoCollectRequests: boolean;
185 /**
186 * Sets the state of dependency tracking (enabled by default)
187 * if true dependencies will be sent to Application Insights
188 */
189 enableAutoCollectDependencies: boolean;
190 /**
191 * Sets the state of automatic dependency correlation (enabled by default)
192 * if true dependencies will be correlated with requests
193 */
194 enableAutoDependencyCorrelation: boolean;
195 /**
196 * Sets the state of automatic dependency correlation (enabled by default)
197 * 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.
198 */
199 enableUseAsyncHooks: boolean;
200 /**
201 * Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default)
202 * Note that this method only applies to the default client. Disk-backed retry caching is disabled by default for additional clients.
203 * For enable for additional clients, use client.channel.setUseDiskRetryCaching(true).
204 * These cached events are stored in your system or user's temporary directory and access restricted to your user when possible.
205 * enableUseDiskRetryCaching if true events that occured while client is offline will be cached on disk
206 * enableResendInterval The wait interval for resending cached events.
207 * enableMaxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.
208 */
209 enableUseDiskRetryCaching: boolean;
210 enableResendInterval: number;
211 enableMaxBytesOnDisk: number;
212 /**
213 * Enables debug and warning logging for AppInsights itself.
214 * if true, enables debug logging
215 */
216 enableInternalDebugLogging: boolean;
217 /**
218 * Enables debug and warning logging for AppInsights itself.
219 * if true, enables warning logging
220 */
221 enableInternalWarningLogging: boolean;
222 /**
223 * Enables communication with Application Insights Live Metrics.
224 * if true, enables communication with the live metrics service
225 */
226 enableSendLiveMetrics: boolean;
227 /**
228 * Disable all environment variables set
229 */
230 disableAllExtendedMetrics: boolean;
231 /**
232 * Disable individual environment variables set. eg. "extendedMetricDisablers": "..."
233 */
234 extendedMetricDisablers: string;
235 /**
236 * Live Metrics custom host
237 */
238 quickPulseHost: string;
239 /**
240 * Enable web instrumentation and automatic monitoring, default to false
241 */
242 enableWebInstrumentation: boolean;
243 /**
244 * Enable automatic incoming request tracking when running in Azure Functions
245 */
246 enableAutoCollectIncomingRequestAzureFunctions: boolean;
247 /**
248 * Application Insights resource connection string for web instrumentation and automatic monitoring
249 * Note: if no VALID connection string is provided here, web instrumentation will use the connection string during initializing Nodejs SDK
250 */
251 webInstrumentationConnectionString?: string;
252 /**
253 * Application Insights web Instrumentation config
254 * NOTE: if no config is provided here, web instrumentation will use default values
255 * IMPORTANT NOTE: please convert any functions and objects to double-quoted strings, otherwise they will be skipped.
256 * For example: if you want to pass in a function: function() { return 'hi'; },
257 * you SHOULD wrap it in double-quoted string: "function () {\n return \"hi\";\n}"
258 * see more Application Insights web Instrumentation config details at: https://github.com/microsoft/ApplicationInsights-JS#configuration
259 */
260 webInstrumentationConfig?: IWebInstrumentationConfig[];
261 /**
262 * Application Insights web Instrumentation CDN url
263 * NOTE: this config can be changed from env variable: APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_SOURCE or Json Config: webInstrumentationSrc
264 * If no resouce is provided here, default CDN endpoint: https://js.monitor.azure.com/scripts/b/ai will be used
265 * see more details at: https://github.com/microsoft/ApplicationInsights-JS
266 */
267 webInstrumentationSrc?: string;
268}
269export interface IConfig extends IBaseConfig {
270 /** AAD TokenCredential to use to authenticate the app */
271 aadTokenCredential?: TokenCredential;
272 /** An http.Agent to use for SDK HTTP traffic (Optional, Default undefined) */
273 httpAgent: http.Agent;
274 /** An https.Agent to use for SDK HTTPS traffic (Optional, Default undefined) */
275 httpsAgent: https.Agent;
276}
277export interface IEnvironmentConfig {
278 /** Connection String used to send telemetry payloads to */
279 connectionString: string;
280 /**
281 * In order to track context across asynchronous calls,
282 * some changes are required in third party libraries such as mongodb and redis.
283 * By default ApplicationInsights will use diagnostic-channel-publishers to monkey-patch some of these libraries.
284 * This property is to disable the feature.
285 * Note that by setting this flag, events may no longer be correctly associated with the right operation.
286 */
287 noDiagnosticChannel: boolean;
288 /**
289 * Disable individual monkey-patches.
290 * Set `noPatchModules` to a comma separated list of packages to disable.
291 * e.g. `"noPatchModules": "console,redis"` to avoid patching the console and redis packages.
292 * The following modules are available: `azuresdk, bunyan, console, mongodb, mongodb-core, mysql, redis, winston, pg`, and `pg-pool`.
293 */
294 noPatchModules: string;
295 /**
296 * HTTPS without a passed in agent
297 */
298 noHttpAgentKeepAlive: boolean;
299}
300export interface IJsonConfig extends IBaseConfig, IEnvironmentConfig {
301}
302export interface IWebInstrumentationConfig {
303 /**
304 * Name of Application Insights web Instrumentation config to be changed
305 * see more Application Insights web Instrumentation config details at: https://github.com/microsoft/ApplicationInsights-JS#configuration
306 */
307 name: string;
308 /**
309 * value provided to replace the default config value above
310 */
311 value: string | boolean | number;
312}
313/**
314 * Statsbeat feature bit flags
315 */
316export declare enum StatsbeatFeature {
317 NONE = 0,
318 DISK_RETRY = 1,
319 AAD_HANDLING = 2,
320 BROWSER_SDK_LOADER = 4,
321 DISTRO = 8,
322 LIVE_METRICS = 16,
323 SHIM = 32
324}
325/**
326 * Statsbeat instrumentation bit flags
327 */
328export declare enum StatsbeatInstrumentation {
329 NONE = 0,
330 AZURE_CORE_TRACING = 1,
331 MONGODB = 2,
332 MYSQL = 4,
333 REDIS = 8,
334 POSTGRES = 16,
335 BUNYAN = 32,
336 WINSTON = 64
337}