UNPKG

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