applicationinsights
Version:
Microsoft Application Insights module for Node.js
1 lines • 17.6 kB
Source Map (JSON)
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../src/shim/applicationinsights.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,4CAA0E;AAE1E,2EAAwE;AACxE,mCAAoG;AAOhF,wGAPuB,+BAAuB,OAOvB;AAN3C,uDAAoD;AAMM,gGANjD,iCAAe,OAMiD;AALzE,uDAAuD;AAK9C,8BAAS;AAJlB,yCAAsC;AAYtC;;;;;;;;;GASG;AACH,SAAgB,KAAK,CAAC,WAAoB;IACtC,IAAI,CAAC,qBAAa,EAAE;QAChB,qBAAa,GAAG,IAAI,iCAAe,CAAC,WAAW,CAAC,CAAC;KACpD;SAAM;QACH,qBAAa,CAAC,gBAAgB,CAAC,iGAAiG,CAAC,CAAA;KACpI;IACD,OAAO,aAAa,CAAC;AACzB,CAAC;AAPD,sBAOC;AAED;;;;;GAKG;AACH,SAAgB,KAAK;IACjB,IAAI;QACA,IAAI,CAAC,qBAAa,EAAE;YAChB,UAAI,CAAC,SAAS,CAAC,IAAI,uBAAiB,EAAE,CAAC,CAAC;YACxC,UAAI,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;SAChF;aAAM;YACH,qBAAa,CAAC,UAAU,EAAE,CAAC;SAC9B;QACD,OAAO,aAAa,CAAC;KACxB;IAAC,OAAO,KAAK,EAAE;QACZ,UAAI,CAAC,IAAI,CAAC,mCAAmC,WAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;KACrF;AACL,CAAC;AAZD,sBAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,qBAAqB;IACjC,OAAO,qDAAyB,CAAC,iBAAiB,EAAE,CAAC;AACzD,CAAC;AAFD,sDAEC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAC1B,IAAmF,EACnF,IAA2B;IAE3B,OAAO,qDAAyB,CAAC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qBAAa,CAAC,MAAM,CAAC,yBAAyB,GAAG,KAAK,CAAC;YACvD,qBAAa,CAAC,MAAM,CAAC,oBAAoB,GAAG,cAAc,CAAC;YAC3D,qBAAa,CAAC,MAAM,CAAC,oBAAoB,GAAG,cAAc,CAAC;SAC9D;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,GAAG,KAAK,EAAE,mBAAmB,GAAG,IAAI;QAClF,IAAI,qBAAa,EAAE;YACf,qBAAa,CAAC,MAAM,CAAC,0BAA0B,GAAG,iBAAiB,CAAC;YACpE,qBAAa,CAAC,MAAM,CAAC,4BAA4B,GAAG,mBAAmB,CAAC;SAC3E;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,2CAA2C,CAAC,KAAc;QACpE,IAAI,qBAAa,EAAE;YACf,qBAAa,CAAC,MAAM,CAAC,8CAA8C,GAAG,KAAK,CAAC;SAC/E;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAG,KAAK;QAC3C,IAAI,qBAAa,EAAE;YACf,qBAAa,CAAC,MAAM,CAAC,qBAAqB,GAAG,MAAM,CAAC;SACvD;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;;AA1LL,sCA2LC;AA1LG,oDAAoD;AACtC,mBAAK,GAAG,KAAK,CAAC;AA2LhC;;GAEG;AACH,SAAgB,OAAO;IACnB,IAAI,qBAAa,EAAE;QACf,qBAAa,CAAC,QAAQ,EAAE,CAAC;KAC5B;IACD,qBAAa,GAAG,IAAI,CAAC;AACzB,CAAC;AALD,0BAKC","sourcesContent":["// Copyright (c) Microsoft Corporation.\r\n// Licensed under the MIT license.\r\n\r\nimport * as http from \"http\";\r\nimport { DiagConsoleLogger, SpanContext, diag } from \"@opentelemetry/api\";\r\nimport { Span } from \"@opentelemetry/sdk-trace-base\";\r\nimport { CorrelationContextManager } from \"./correlationContextManager\";\r\nimport { ICorrelationContext, HttpRequest, DistributedTracingModes, AzureFnContext } from \"./types\";\r\nimport { TelemetryClient } from \"./telemetryClient\";\r\nimport * as Contracts from \"../declarations/contracts\";\r\nimport { Util } from \"../shared/util\";\r\n\r\n// We export these imports so that SDK users may use these classes directly.\r\n// They're exposed using \"export import\" so that types are passed along as expected\r\nexport { Contracts, DistributedTracingModes, HttpRequest, TelemetryClient };\r\n\r\n/**\r\n * The default client, initialized when setup was called. To initialize a different client\r\n * with its own configuration, use `new TelemetryClient(instrumentationKey?)`.\r\n */\r\nexport let defaultClient: TelemetryClient;\r\n\r\n/**\r\n * Initializes the default client. Should be called after setting\r\n * configuration options.\r\n *\r\n * @param setupString the Connection String or Instrumentation Key to use. Optional, if\r\n * this is not specified, the value will be read from the environment\r\n * variable APPLICATIONINSIGHTS_CONNECTION_STRING or APPINSIGHTS_INSTRUMENTATIONKEY.\r\n * @returns {Configuration} the configuration class to initialize\r\n * and start the SDK.\r\n */\r\nexport function setup(setupString?: string) {\r\n if (!defaultClient) {\r\n defaultClient = new TelemetryClient(setupString);\r\n } else {\r\n defaultClient.pushWarningToLog(\"Setup has already been called once. To set up a new client, please use TelemetryClient instead.\")\r\n }\r\n return Configuration;\r\n}\r\n\r\n/**\r\n * Starts automatic collection of telemetry. Prior to calling start no\r\n * telemetry will be *automatically* collected, though manual collection\r\n * is enabled.\r\n * @returns {ApplicationInsights} this class\r\n */\r\nexport function start() {\r\n try {\r\n if (!defaultClient) {\r\n diag.setLogger(new DiagConsoleLogger());\r\n diag.warn(\"Start cannot be called before setup. Please call setup() first.\");\r\n } else {\r\n defaultClient.initialize();\r\n }\r\n return Configuration;\r\n } catch (error) {\r\n diag.warn(`Failed to start default client: ${Util.getInstance().dumpObj(error)}`);\r\n }\r\n}\r\n\r\n/**\r\n * Returns an object that is shared across all code handling a given request.\r\n * This can be used similarly to thread-local storage in other languages.\r\n * Properties set on this object will be available to telemetry processors.\r\n *\r\n * Do not store sensitive information here.\r\n * Custom properties set on this object can be exposed in a future SDK\r\n * release via outgoing HTTP headers.\r\n * This is to allow for correlating data cross-component.\r\n *\r\n * This method will return null if automatic dependency correlation is disabled.\r\n * @returns A plain object for request storage or null if automatic dependency correlation is disabled.\r\n */\r\nexport function getCorrelationContext(): ICorrelationContext {\r\n return CorrelationContextManager.getCurrentContext();\r\n}\r\n\r\n/**\r\n * **(Experimental!)**\r\n * Starts a fresh context or propagates the current internal one.\r\n */\r\nexport function startOperation(\r\n arg1: AzureFnContext | (http.IncomingMessage | AzureFnContext) | SpanContext | Span,\r\n arg2?: HttpRequest | string\r\n): ICorrelationContext | null {\r\n return CorrelationContextManager.startOperation(arg1, arg2);\r\n}\r\n\r\n/**\r\n * Returns a function that will get the same correlation context within its\r\n * function body as the code executing this function.\r\n * Use this method if automatic dependency correlation is not propagating\r\n * correctly to an asynchronous callback.\r\n */\r\nexport function wrapWithCorrelationContext<T>(fn: T, context?: ICorrelationContext): T {\r\n return CorrelationContextManager.wrapCallback<T>(fn, context);\r\n}\r\n\r\n/**\r\n * The active configuration for global SDK behaviors, such as auto collection.\r\n */\r\nexport class Configuration {\r\n // Convenience shortcut to ApplicationInsights.start\r\n public static start = start;\r\n\r\n /**\r\n * Only W3C traing mode is currently suppported so this method informs the user if they attempt to set the value.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public static setDistributedTracingMode(value: number) {\r\n if (defaultClient) {\r\n defaultClient.config.distributedTracingMode = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of console and logger tracking (enabled by default for third-party loggers only)\r\n * @param value if true logger activity will be sent to Application Insights\r\n * @param collectConsoleLog if true, logger autocollection will include console.log calls (default false)\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectConsole(value: boolean, collectConsoleLog = false) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectExternalLoggers = value;\r\n defaultClient.config.enableAutoCollectConsole = collectConsoleLog;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of exception tracking (enabled by default)\r\n * @param value if true uncaught exceptions will be sent to Application Insights\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectExceptions(value: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectExceptions = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of performance tracking (enabled by default)\r\n * @param value if true performance counters will be collected every second and sent to Application Insights\r\n * @param collectExtendedMetrics if true, extended metrics counters will be collected every minute and sent to Application Insights\r\n * @returns {Configuration} this class\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars \r\n public static setAutoCollectPerformance(value: boolean, collectExtendedMetrics: any) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectPerformance = value;\r\n defaultClient.config.enableAutoCollectExtendedMetrics = collectExtendedMetrics;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of pre aggregated metrics tracking (enabled by default)\r\n * @param value if true pre aggregated metrics will be collected every minute and sent to Application Insights\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectPreAggregatedMetrics(value: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectPreAggregatedMetrics = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of request tracking (enabled by default)\r\n * @param value if true HeartBeat metric data will be collected every 15 minutes and sent to Application Insights\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectHeartbeat(value: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectHeartbeat = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of Web snippet injection\r\n * @param value if true Web snippet will try to be injected in server response\r\n * @param WebSnippetConnectionString if provided, Web snippet injection will use this ConnectionString. Default to use the connectionString in Node.js app initialization.\r\n * @returns {Configuration} this class\r\n */\r\n public static enableWebInstrumentation(value: boolean, WebSnippetConnectionString?: string) {\r\n if (defaultClient) {\r\n defaultClient.config.enableWebInstrumentation = value;\r\n defaultClient.config.webInstrumentationConnectionString = WebSnippetConnectionString;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of request tracking (enabled by default)\r\n * @param value if true requests will be sent to Application Insights\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectRequests(value: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectRequests = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of dependency tracking (enabled by default)\r\n * @param value if true dependencies will be sent to Application Insights\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectDependencies(value: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectDependencies = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Sets the state of automatic dependency correlation (enabled by default)\r\n * @param value if true dependencies will be correlated with requests\r\n * @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.\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoDependencyCorrelation(value: boolean, useAsyncHooks?: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoDependencyCorrelation = value;\r\n defaultClient.config.enableUseAsyncHooks = useAsyncHooks;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default)\r\n * Note that this method only applies to the default client. Disk-backed retry caching is disabled by default for additional clients.\r\n * For enable for additional clients, use client.channel.setUseDiskRetryCaching(true).\r\n * These cached events are stored in your system or user's temporary directory and access restricted to your user when possible.\r\n * @param value if true events that occured while client is offline will be cached on disk\r\n * @param resendInterval The wait interval for resending cached events.\r\n * @param maxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.\r\n * @returns {Configuration} this class\r\n */\r\n public static setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number) {\r\n if (defaultClient) {\r\n defaultClient.config.enableUseDiskRetryCaching = value;\r\n defaultClient.config.enableResendInterval = resendInterval;\r\n defaultClient.config.enableMaxBytesOnDisk = maxBytesOnDisk;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Enables debug and warning Logger for AppInsights itself.\r\n * @param enableDebugLogger if true, enables debug Logger\r\n * @param enableWarningLogger if true, enables warning Logger\r\n * @returns {Configuration} this class\r\n */\r\n public static setInternalLogging(enableDebugLogger = false, enableWarningLogger = true) {\r\n if (defaultClient) {\r\n defaultClient.config.enableInternalDebugLogging = enableDebugLogger;\r\n defaultClient.config.enableInternalWarningLogging = enableWarningLogger;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Enable automatic incoming request tracking when using Azure Functions\r\n * @param value if true auto collection of incoming requests will be enabled\r\n * @returns {Configuration} this class\r\n */\r\n public static setAutoCollectIncomingRequestAzureFunctions(value: boolean) {\r\n if (defaultClient) {\r\n defaultClient.config.enableAutoCollectIncomingRequestAzureFunctions = value;\r\n }\r\n return Configuration;\r\n }\r\n\r\n /**\r\n * Enables communication with Application Insights Live Metrics.\r\n * @param enable if true, enables communication with the live metrics service\r\n */\r\n public static setSendLiveMetrics(enable = false) {\r\n if (defaultClient) {\r\n defaultClient.config.enableSendLiveMetrics = enable;\r\n }\r\n return Configuration;\r\n }\r\n}\r\n\r\n/**\r\n * Disposes the default client and all the auto collectors so they can be reinitialized with different configuration\r\n */\r\nexport function dispose() {\r\n if (defaultClient) {\r\n defaultClient.shutdown();\r\n }\r\n defaultClient = null;\r\n}\r\n"]}