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