|
3 | 3 | * the auto-collection behavior of the application insights module.
|
4 | 4 | */
|
5 | 5 | declare module ApplicationInsights {
|
6 |
| - var client: any; |
| 6 | + |
7 | 7 | /**
|
8 |
| - * Initializes a client with the given instrumentation key, if this is not specified, the value will be |
9 |
| - * read from the environment variable APPINSIGHTS_INSTRUMENTATIONKEY |
10 |
| - * @returns {ApplicationInsights/Client} a new client |
11 |
| - */ |
12 |
| - function getClient(instrumentationKey?: string): any /*Client*/; |
| 8 | + * The default client, initialized when setup was called. To initialize a different client |
| 9 | + * with its own configuration, use `new TelemetryClient(instrumentationKey?)`. |
| 10 | + */ |
| 11 | + var defaultClient: TelemetryClient; |
13 | 12 | /**
|
14 |
| - * Initializes the default client of the client and sets the default configuration |
15 |
| - * @param instrumentationKey the instrumentation key to use. Optional, if this is not specified, the value will be |
16 |
| - * read from the environment variable APPINSIGHTS_INSTRUMENTATIONKEY |
17 |
| - * @returns {ApplicationInsights} this class |
| 13 | + * Initializes the default client. Should be called after setting |
| 14 | + * configuration options. |
| 15 | + * |
| 16 | + * @param instrumentationKey the instrumentation key to use. Optional, if |
| 17 | + * this is not specified, the value will be read from the environment |
| 18 | + * variable APPINSIGHTS_INSTRUMENTATIONKEY. |
| 19 | + * @returns {Configuration} the configuration class to initialize |
| 20 | + * and start the SDK. |
18 | 21 | */
|
19 |
| - function setup(instrumentationKey?: string): typeof ApplicationInsights; |
| 22 | + function setup(instrumentationKey?: string): typeof Configuration; |
20 | 23 | /**
|
21 |
| - * Starts automatic collection of telemetry. Prior to calling start no telemetry will be collected |
| 24 | + * Starts automatic collection of telemetry. Prior to calling start no |
| 25 | + * telemetry will be *automatically* collected, though manual collection |
| 26 | + * is enabled. |
22 | 27 | * @returns {ApplicationInsights} this class
|
23 | 28 | */
|
24 |
| - function start(): typeof ApplicationInsights; |
| 29 | + function start(): typeof Configuration; |
25 | 30 | /**
|
26 |
| - * Sets the state of console tracking (enabled by default) |
27 |
| - * @param value if true console activity will be sent to Application Insights |
28 |
| - * @returns {ApplicationInsights} this class |
| 31 | + * The active configuration for global SDK behaviors, such as autocollection. |
29 | 32 | */
|
30 |
| - function setAutoCollectConsole(value: boolean): typeof ApplicationInsights; |
| 33 | + class Configuration { |
| 34 | + static start: typeof start; |
| 35 | + /** |
| 36 | + * Sets the state of console and logger tracking (enabled by default for third-party loggers only) |
| 37 | + * @param value if true logger activity will be sent to Application Insights |
| 38 | + * @param collectConsoleLog if true, logger autocollection will include console.log calls (default false) |
| 39 | + * @returns {Configuration} this class |
| 40 | + */ |
| 41 | + static setAutoCollectConsole(value: boolean, collectConsoleLog?: boolean): typeof Configuration; |
| 42 | + /** |
| 43 | + * Sets the state of exception tracking (enabled by default) |
| 44 | + * @param value if true uncaught exceptions will be sent to Application Insights |
| 45 | + * @returns {Configuration} this class |
| 46 | + */ |
| 47 | + static setAutoCollectExceptions(value: boolean): typeof Configuration; |
| 48 | + /** |
| 49 | + * Sets the state of performance tracking (enabled by default) |
| 50 | + * @param value if true performance counters will be collected every second and sent to Application Insights |
| 51 | + * @returns {Configuration} this class |
| 52 | + */ |
| 53 | + static setAutoCollectPerformance(value: boolean): typeof Configuration; |
| 54 | + /** |
| 55 | + * Sets the state of request tracking (enabled by default) |
| 56 | + * @param value if true requests will be sent to Application Insights |
| 57 | + * @returns {Configuration} this class |
| 58 | + */ |
| 59 | + static setAutoCollectRequests(value: boolean): typeof Configuration; |
| 60 | + /** |
| 61 | + * Sets the state of dependency tracking (enabled by default) |
| 62 | + * @param value if true dependencies will be sent to Application Insights |
| 63 | + * @returns {Configuration} this class |
| 64 | + */ |
| 65 | + static setAutoCollectDependencies(value: boolean): typeof Configuration; |
| 66 | + /** |
| 67 | + * Sets the state of automatic dependency correlation (enabled by default) |
| 68 | + * @param value if true dependencies will be correlated with requests |
| 69 | + * @returns {Configuration} this class |
| 70 | + */ |
| 71 | + static setAutoDependencyCorrelation(value: boolean): typeof Configuration; |
| 72 | + /** |
| 73 | + * Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default) |
| 74 | + * Note that this method only applies to the default client. Disk-backed retry caching is disabled by default for additional clients. |
| 75 | + * For enable for additional clients, use client.channel.setUseDiskRetryCaching(true). |
| 76 | + * These cached events are stored in your system or user's temporary directory and access restricted to your user when possible. |
| 77 | + * @param value if true events that occured while client is offline will be cached on disk |
| 78 | + * @param resendInterval The wait interval for resending cached events. |
| 79 | + * @param maxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled. |
| 80 | + * @returns {Configuration} this class |
| 81 | + */ |
| 82 | + static setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): typeof Configuration; |
| 83 | + /** |
| 84 | + * Enables debug and warning logging for AppInsights itself. |
| 85 | + * @param enableDebugLogging if true, enables debug logging |
| 86 | + * @param enableWarningLogging if true, enables warning logging |
| 87 | + * @returns {Configuration} this class |
| 88 | + */ |
| 89 | + static setInternalLogging(enableDebugLogging?: boolean, enableWarningLogging?: boolean): typeof Configuration; |
| 90 | + } |
31 | 91 | /**
|
32 |
| - * Sets the state of exception tracking (enabled by default) |
33 |
| - * @param value if true uncaught exceptions will be sent to Application Insights |
34 |
| - * @returns {ApplicationInsights} this class |
35 |
| - */ |
36 |
| - function setAutoCollectExceptions(value: boolean): typeof ApplicationInsights; |
37 |
| - /** |
38 |
| - * Sets the state of performance tracking (enabled by default) |
39 |
| - * @param value if true performance counters will be collected every second and sent to Application Insights |
40 |
| - * @returns {ApplicationInsights} this class |
41 |
| - */ |
42 |
| - function setAutoCollectPerformance(value: boolean): typeof ApplicationInsights; |
| 92 | + * Disposes the default client and all the auto collectors so they can be reinitialized with different configuration |
| 93 | + */ |
| 94 | + function dispose(): void; |
| 95 | + |
| 96 | + interface ITelemetryClient { |
| 97 | + config: Config; |
| 98 | + channel: Channel; |
| 99 | + /** |
| 100 | + * Log a user action or other occurrence. |
| 101 | + * @param telemetry Object encapsulating tracking options |
| 102 | + */ |
| 103 | + trackEvent(telemetry: EventTelemetry): void; |
| 104 | + /** |
| 105 | + * Immediately send all queued telemetry. |
| 106 | + * @param options Flush options, including indicator whether app is crashing and callback |
| 107 | + */ |
| 108 | + flush(options?: FlushOptions): void; |
| 109 | + |
| 110 | + } |
| 111 | + |
| 112 | + class TelemetryClient implements ITelemetryClient { |
| 113 | + config: Config; |
| 114 | + channel: Channel; |
| 115 | + /** |
| 116 | + * Constructs a new client of the client |
| 117 | + * @param iKey the instrumentation key to use (read from environment variable if not specified) |
| 118 | + */ |
| 119 | + constructor(iKey?: string); |
| 120 | + /** |
| 121 | + * Log a user action or other occurrence. |
| 122 | + * @param telemetry Object encapsulating tracking options |
| 123 | + */ |
| 124 | + trackEvent(telemetry: EventTelemetry): void; |
| 125 | + /** |
| 126 | + * Immediately send all queued telemetry. |
| 127 | + * @param options Flush options, including indicator whether app is crashing and callback |
| 128 | + */ |
| 129 | + flush(options?: FlushOptions): void; |
| 130 | + |
| 131 | + } |
| 132 | + |
| 133 | + class Config { |
| 134 | + static ENV_azurePrefix: string; |
| 135 | + static ENV_iKey: string; |
| 136 | + static legacy_ENV_iKey: string; |
| 137 | + static ENV_profileQueryEndpoint: string; |
| 138 | + static ENV_http_proxy: string; |
| 139 | + static ENV_https_proxy: string; |
| 140 | + /** An identifier for your Application Insights resource */ |
| 141 | + instrumentationKey: string; |
| 142 | + /** The id for cross-component correlation. READ ONLY. */ |
| 143 | + correlationId: string; |
| 144 | + /** The ingestion endpoint to send telemetry payloads to */ |
| 145 | + endpointUrl: string; |
| 146 | + /** The maximum number of telemetry items to include in a payload to the ingestion endpoint (Default 250) */ |
| 147 | + maxBatchSize: number; |
| 148 | + /** The maximum amount of time to wait for a payload to reach maxBatchSize (Default 15000) */ |
| 149 | + maxBatchIntervalMs: number; |
| 150 | + /** A flag indicating if telemetry transmission is disabled (Default false) */ |
| 151 | + disableAppInsights: boolean; |
| 152 | + /** The percentage of telemetry items tracked that should be transmitted (Default 100) */ |
| 153 | + samplingPercentage: number; |
| 154 | + /** The time to wait before retrying to retrieve the id for cross-component correlation (Default 30000) */ |
| 155 | + correlationIdRetryIntervalMs: number; |
| 156 | + /** A list of domains to exclude from cross-component header injection */ |
| 157 | + correlationHeaderExcludedDomains: string[]; |
| 158 | + /** A proxy server for SDK HTTP traffic (Optional, Default pulled from `http_proxy` environment variable) */ |
| 159 | + proxyHttpUrl: string; |
| 160 | + /** A proxy server for SDK HTTPS traffic (Optional, Default pulled from `https_proxy` environment variable) */ |
| 161 | + proxyHttpsUrl: string; |
| 162 | + } |
| 163 | + |
| 164 | + interface Channel { |
| 165 | + /** |
| 166 | + * Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default) |
| 167 | + * These cached events are stored in your system or user's temporary directory and access restricted to your user when possible. |
| 168 | + * @param value if true events that occured while client is offline will be cached on disk |
| 169 | + * @param resendInterval The wait interval for resending cached events. |
| 170 | + * @param maxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled. |
| 171 | + * @returns {Configuration} this class |
| 172 | + */ |
| 173 | + setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): void; |
| 174 | + } |
| 175 | + |
43 | 176 | /**
|
44 |
| - * Sets the state of request tracking (enabled by default) |
45 |
| - * @param value if true requests will be sent to Application Insights |
46 |
| - * @returns {ApplicationInsights} this class |
| 177 | + * Telemetry about the custom event of interest, such application workflow event, business logic event (purchase) and anything that |
| 178 | + * you would like to track and aggregate by count. Event can contain measurements such as purchase amount associated with purchase event |
47 | 179 | */
|
48 |
| - function setAutoCollectRequests(value: boolean): typeof ApplicationInsights; |
| 180 | + interface EventTelemetry { |
| 181 | + /** |
| 182 | + * Name of the event |
| 183 | + */ |
| 184 | + name: string; |
| 185 | + /** |
| 186 | + * Metrics associated with this event, displayed in Metrics Explorer on the portal. |
| 187 | + */ |
| 188 | + measurements?: { |
| 189 | + [key: string]: number; |
| 190 | + }; |
| 191 | + /** |
| 192 | + * Additional data used to filter events and metrics in the portal. Defaults to empty. |
| 193 | + */ |
| 194 | + properties?: { |
| 195 | + [key: string]: string; |
| 196 | + }; |
| 197 | + } |
49 | 198 |
|
50 |
| - /** |
51 |
| - * Sets the state of enabling offline mode to cache event when client is offline (disabled by default) |
52 |
| - * @param value if true events that happen while client is offline will be cahced on disk, |
53 |
| - * client will retry to send events when back online |
54 |
| - * @returns {ApplicationInsights} this class |
55 |
| - */ |
56 |
| - function setOfflineMode(value: boolean): typeof ApplicationInsights; |
57 | 199 | /**
|
58 |
| - * Enables verbose debug logging |
59 |
| - * @returns {ApplicationInsights} this class |
| 200 | + * Encapsulates options passed into client.flush() function |
60 | 201 | */
|
61 |
| - function enableVerboseLogging(): typeof ApplicationInsights; |
| 202 | + interface FlushOptions { |
| 203 | + /** |
| 204 | + * Flag indicating whether application is crashing. When this flag is set to true |
| 205 | + * and storing data locally is enabled, Node.JS SDK will attempt to store data on disk |
| 206 | + */ |
| 207 | + isAppCrashing?: boolean; |
| 208 | + /** |
| 209 | + * Callback that will be invoked with the response from server, in case of isAppCrashing set to true, |
| 210 | + * with immediate notification that data was stored |
| 211 | + */ |
| 212 | + callback?: (v: string) => void; |
| 213 | + } |
62 | 214 | }
|
63 | 215 |
|
64 | 216 | declare module 'applicationinsights' {
|
65 |
| - export = ApplicationInsights; |
| 217 | + export = ApplicationInsights; |
66 | 218 | }
|
0 commit comments