applicationinsights
Version:
Microsoft Application Insights module for Node.js
1 lines • 16.4 kB
Source Map (JSON)
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/shim/types.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAQrB,QAAA,eAAe,GAAG,wKAAwK,CAAC;AACxM,IAAY,uBAUX;AAVD,WAAY,uBAAuB;IAC/B;;OAEG;IACH,iEAAM,CAAA;IAEN;;OAEG;IACH,iFAAU,CAAA;AACd,CAAC,EAVW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAUlC;AAkUD;;GAEG;AACH,IAAY,gBAQX;AARD,WAAY,gBAAgB;IACxB,uDAAQ,CAAA;IACR,mEAAc,CAAA;IACd,uEAAgB,CAAA;IAChB,mFAAsB,CAAA;IACtB,2DAAU,CAAA;IACV,wEAAiB,CAAA;IACjB,wDAAS,CAAA;AACb,CAAC,EARW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAQ3B;AAED;;GAEG;AACH,IAAY,wBASX;AATD,WAAY,wBAAwB;IAChC,uEAAQ,CAAA;IACR,mGAAsB,CAAA;IACtB,6EAAW,CAAA;IACX,yEAAS,CAAA;IACT,yEAAS,CAAA;IACT,gFAAa,CAAA;IACb,4EAAW,CAAA;IACX,8EAAY,CAAA;AAChB,CAAC,EATW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QASnC","sourcesContent":["// Copyright (c) Microsoft Corporation.\r\n// Licensed under the MIT license.\r\n\r\nimport { TokenCredential } from \"@azure/core-auth\";\r\nimport * as http from \"http\";\r\nimport https = require(\"https\");\r\nimport { Context as AzureFnV3Context, HttpRequest as AzureFnV3Request, TraceContext as AzureFnV3TraceContext } from \"@azure/functions-old\";\r\nimport { InvocationContext as AzureFnV4Context, HttpRequest as AzureFnV4Request } from \"@azure/functions\";\r\n\r\nexport 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.\";\r\nexport enum DistributedTracingModes {\r\n /**\r\n * Send Application Insights correlation headers\r\n */\r\n AI = 0,\r\n\r\n /**\r\n * (Default) Send both W3C Trace Context headers and back-compatibility Application Insights headers\r\n */\r\n AI_AND_W3C\r\n}\r\n\r\n/**\r\n * Interface which defines which specific extended metrics should be disabled\r\n *\r\n * @export\r\n * @interface IDisabledExtendedMetrics\r\n */\r\nexport interface IDisabledExtendedMetrics {\r\n gc?: boolean;\r\n heap?: boolean;\r\n loop?: boolean;\r\n}\r\n\r\n\r\nexport interface ITraceparent {\r\n legacyRootId: string;\r\n parentId: string;\r\n spanId: string;\r\n traceFlag: string;\r\n traceId: string;\r\n version: string;\r\n}\r\n\r\nexport interface ITracestate {\r\n fieldmap: string[];\r\n}\r\n\r\nexport interface ICorrelationContext {\r\n operation: {\r\n name: string;\r\n id: string;\r\n parentId: string; // Always used for dependencies, may be ignored in favor of incoming headers for requests\r\n traceparent?: ITraceparent; // w3c context trace\r\n tracestate?: ITracestate; // w3c context state\r\n };\r\n /** Do not store sensitive information here.\r\n * Properties here are exposed via outgoing HTTP headers for correlating data cross-component.\r\n */\r\n customProperties: ICustomProperties;\r\n}\r\n\r\nexport interface ICustomProperties {\r\n /**\r\n * Get a custom property from the correlation context\r\n */\r\n getProperty(key: string): string;\r\n /**\r\n * Store a custom property in the correlation context.\r\n * Do not store sensitive information here.\r\n * Properties stored here are exposed via outgoing HTTP headers for correlating data cross-component.\r\n * The characters ',' and '=' are disallowed within keys or values.\r\n */\r\n setProperty(key: string, value: string): void;\r\n}\r\n\r\n/**\r\n * The context object can be used for writing logs, reading data from bindings, setting outputs and using\r\n * the context.done callback when your exported function is synchronous. A context object is passed\r\n * to your function from the Azure Functions runtime on function invocation.\r\n */\r\nexport interface Context {\r\n traceContext: TraceContext;\r\n}\r\n\r\n/**\r\n * HTTP request object. Provided to your function when using HTTP Bindings.\r\n */\r\nexport interface HttpRequest {\r\n method: string | null;\r\n url: string;\r\n headers: {\r\n [key: string]: string;\r\n };\r\n}\r\n\r\n/**\r\n * TraceContext information to enable distributed tracing scenarios.\r\n */\r\nexport interface TraceContext {\r\n /** Describes the position of the incoming request in its trace graph in a portable, fixed-length format. */\r\n traceparent: string | null | undefined;\r\n /** Extends traceparent with vendor-specific data. */\r\n tracestate: string | null | undefined;\r\n /** Holds additional properties being sent as part of request telemetry. */\r\n attributes:\r\n | {\r\n [k: string]: string;\r\n }\r\n | null\r\n | undefined;\r\n}\r\n\r\n/**\r\n * Subset of Connection String fields which this SDK can parse. Lower-typecased to\r\n * allow for case-insensitivity across field names\r\n * @type ConnectionStringKey\r\n */\r\nexport interface ConnectionString {\r\n instrumentationkey?: string;\r\n ingestionendpoint?: string;\r\n liveendpoint?: string;\r\n location?: string;\r\n endpointsuffix?: string;\r\n\r\n // Note: this is a node types backcompat equivalent to\r\n // type ConnectionString = { [key in ConnectionStringKey]?: string }\r\n}\r\n\r\nexport type ConnectionStringKey = \"instrumentationkey\" | \"ingestionendpoint\" | \"liveendpoint\" | \"location\"| \"endpointsuffix\";\r\n\r\nexport type AzureFnContext = AzureFnV3Context | AzureFnV4Context;\r\n\r\nexport type AzureFnRequest = AzureFnV3Request | AzureFnV4Request;\r\n\r\nexport type AzureFnTraceContext = AzureFnV3TraceContext & AzureFnV4Context[\"traceContext\"];\r\n\r\nexport interface IBaseConfig {\r\n /** The ingestion endpoint to send telemetry payloads to */\r\n endpointUrl: string;\r\n /** The maximum number of telemetry items to include in a payload to the ingestion endpoint (Default 250) */\r\n maxBatchSize: number;\r\n /** The maximum amount of time to wait for a payload to reach maxBatchSize (Default 15000) */\r\n maxBatchIntervalMs: number;\r\n /** A flag indicating if telemetry transmission is disabled (Default false) */\r\n disableAppInsights: boolean;\r\n /** The percentage of telemetry items tracked that should be transmitted (Default 100) */\r\n samplingPercentage: number;\r\n /** A list of domains to exclude from cross-component header injection */\r\n correlationHeaderExcludedDomains: string[];\r\n /** A proxy server for SDK HTTP traffic (Optional, Default pulled from `http_proxy` environment variable) */\r\n proxyHttpUrl: string;\r\n /** A proxy server for SDK HTTPS traffic (Optional, Default pulled from `https_proxy` environment variable) */\r\n proxyHttpsUrl: string;\r\n /** Disable including legacy headers in outgoing requests, x-ms-request-id */\r\n ignoreLegacyHeaders: boolean;\r\n /**\r\n * Sets the distributed tracing modes. If W3C mode is enabled, W3C trace context\r\n * headers (traceparent/tracestate) will be parsed in all incoming requests, and included in outgoing\r\n * requests. In W3C mode, existing back-compatibility AI headers will also be parsed and included.\r\n * Enabling W3C mode will not break existing correlation with other Application Insights instrumented\r\n * services. Default=AI\r\n */\r\n distributedTracingMode: DistributedTracingModes;\r\n /**\r\n * Sets the state of console\r\n * if true logger activity will be sent to Application Insights\r\n */\r\n enableAutoCollectExternalLoggers: boolean;\r\n /**\r\n * Sets the state of logger tracking (enabled by default for third-party loggers only)\r\n * if true, logger autocollection will include console.log calls (default false)\r\n */\r\n enableAutoCollectConsole: boolean;\r\n /**\r\n * Sets tracking error logs from loggers (console, bunyan, winston) as traces. If true errors will be returned as traces\r\n */\r\n enableLoggerErrorToTrace: boolean;\r\n /**\r\n * Sets the state of exception tracking (enabled by default)\r\n * if true uncaught exceptions will be sent to Application Insights\r\n */\r\n enableAutoCollectExceptions: boolean;\r\n /**\r\n * Sets the state of performance tracking (enabled by default)\r\n * if true performance counters will be collected every second and sent to Application Insights\r\n */\r\n enableAutoCollectPerformance: boolean;\r\n /**\r\n * Sets the state of performance tracking (enabled by default)\r\n * if true, extended metrics counters will be collected every minute and sent to Application Insights\r\n */\r\n enableAutoCollectExtendedMetrics: boolean | IDisabledExtendedMetrics;\r\n /**\r\n * Sets the state of pre aggregated metrics tracking (enabled by default)\r\n * if true pre aggregated metrics will be collected every minute and sent to Application Insights\r\n */\r\n enableAutoCollectPreAggregatedMetrics: boolean;\r\n /**\r\n * Sets the state of request tracking (enabled by default)\r\n * if true HeartBeat metric data will be collected every 15 minutes and sent to Application Insights\r\n */\r\n enableAutoCollectHeartbeat: boolean;\r\n /**\r\n * Sets the state of request tracking (enabled by default)\r\n * if true requests will be sent to Application Insights\r\n */\r\n enableAutoCollectRequests: boolean;\r\n /**\r\n * Sets the state of dependency tracking (enabled by default)\r\n * if true dependencies will be sent to Application Insights\r\n */\r\n enableAutoCollectDependencies: boolean;\r\n /**\r\n * Sets the state of automatic dependency correlation (enabled by default)\r\n * if true dependencies will be correlated with requests\r\n */\r\n enableAutoDependencyCorrelation: boolean;\r\n /**\r\n * Sets the state of automatic dependency correlation (enabled by default)\r\n * 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 */\r\n enableUseAsyncHooks: boolean;\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 * enableUseDiskRetryCaching if true events that occured while client is offline will be cached on disk\r\n * enableResendInterval The wait interval for resending cached events.\r\n * enableMaxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.\r\n */\r\n enableUseDiskRetryCaching: boolean;\r\n enableResendInterval: number;\r\n enableMaxBytesOnDisk: number;\r\n /**\r\n * Enables debug and warning logging for AppInsights itself.\r\n * if true, enables debug logging\r\n */\r\n enableInternalDebugLogging: boolean;\r\n /**\r\n * Enables debug and warning logging for AppInsights itself.\r\n * if true, enables warning logging\r\n */\r\n enableInternalWarningLogging: boolean;\r\n /**\r\n * Enables communication with Application Insights Live Metrics.\r\n * if true, enables communication with the live metrics service\r\n */\r\n enableSendLiveMetrics: boolean;\r\n /**\r\n * Disable all environment variables set\r\n */\r\n disableAllExtendedMetrics: boolean;\r\n /**\r\n * Disable individual environment variables set. eg. \"extendedMetricDisablers\": \"...\"\r\n */\r\n extendedMetricDisablers: string;\r\n /**\r\n * Live Metrics custom host\r\n */\r\n quickPulseHost: string;\r\n /**\r\n * Enable web instrumentation and automatic monitoring, default to false\r\n */\r\n enableWebInstrumentation: boolean;\r\n /**\r\n * Enable automatic incoming request tracking when running in Azure Functions\r\n */\r\n enableAutoCollectIncomingRequestAzureFunctions: boolean;\r\n /**\r\n * Application Insights resource connection string for web instrumentation and automatic monitoring\r\n * Note: if no VALID connection string is provided here, web instrumentation will use the connection string during initializing Nodejs SDK\r\n */\r\n webInstrumentationConnectionString?: string;\r\n /**\r\n * Application Insights web Instrumentation config\r\n * NOTE: if no config is provided here, web instrumentation will use default values\r\n * IMPORTANT NOTE: please convert any functions and objects to double-quoted strings, otherwise they will be skipped.\r\n * For example: if you want to pass in a function: function() { return 'hi'; },\r\n * you SHOULD wrap it in double-quoted string: \"function () {\\n return \\\"hi\\\";\\n}\"\r\n * see more Application Insights web Instrumentation config details at: https://github.com/microsoft/ApplicationInsights-JS#configuration\r\n */\r\n webInstrumentationConfig?: IWebInstrumentationConfig[];\r\n /**\r\n * Application Insights web Instrumentation CDN url\r\n * NOTE: this config can be changed from env variable: APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_SOURCE or Json Config: webInstrumentationSrc\r\n * If no resouce is provided here, default CDN endpoint: https://js.monitor.azure.com/scripts/b/ai will be used\r\n * see more details at: https://github.com/microsoft/ApplicationInsights-JS\r\n */\r\n webInstrumentationSrc?: string;\r\n}\r\n\r\nexport interface IConfig extends IBaseConfig {\r\n /** AAD TokenCredential to use to authenticate the app */\r\n aadTokenCredential?: TokenCredential;\r\n\r\n /** An http.Agent to use for SDK HTTP traffic (Optional, Default undefined) */\r\n httpAgent: http.Agent;\r\n\r\n /** An https.Agent to use for SDK HTTPS traffic (Optional, Default undefined) */\r\n httpsAgent: https.Agent;\r\n}\r\n\r\nexport interface IEnvironmentConfig {\r\n /** Connection String used to send telemetry payloads to */\r\n connectionString: string;\r\n /**\r\n * In order to track context across asynchronous calls,\r\n * some changes are required in third party libraries such as mongodb and redis.\r\n * By default ApplicationInsights will use diagnostic-channel-publishers to monkey-patch some of these libraries.\r\n * This property is to disable the feature.\r\n * Note that by setting this flag, events may no longer be correctly associated with the right operation.\r\n */\r\n noDiagnosticChannel: boolean;\r\n /**\r\n * Disable individual monkey-patches.\r\n * Set `noPatchModules` to a comma separated list of packages to disable.\r\n * e.g. `\"noPatchModules\": \"console,redis\"` to avoid patching the console and redis packages.\r\n * The following modules are available: `azuresdk, bunyan, console, mongodb, mongodb-core, mysql, redis, winston, pg`, and `pg-pool`.\r\n */\r\n noPatchModules: string;\r\n /**\r\n * HTTPS without a passed in agent\r\n */\r\n noHttpAgentKeepAlive: boolean;\r\n}\r\n\r\nexport interface IJsonConfig extends IBaseConfig, IEnvironmentConfig { }\r\n\r\nexport interface IWebInstrumentationConfig {\r\n /**\r\n * Name of Application Insights web Instrumentation config to be changed\r\n * see more Application Insights web Instrumentation config details at: https://github.com/microsoft/ApplicationInsights-JS#configuration\r\n */\r\n name: string;\r\n /**\r\n * value provided to replace the default config value above\r\n */\r\n value: string | boolean | number;\r\n}\r\n\r\n/**\r\n * Statsbeat feature bit flags\r\n */\r\nexport enum StatsbeatFeature {\r\n NONE = 0,\r\n DISK_RETRY = 1,\r\n AAD_HANDLING = 2,\r\n BROWSER_SDK_LOADER = 4,\r\n DISTRO = 8,\r\n LIVE_METRICS = 16,\r\n SHIM = 32,\r\n}\r\n\r\n/**\r\n * Statsbeat instrumentation bit flags\r\n */\r\nexport enum StatsbeatInstrumentation {\r\n NONE = 0,\r\n AZURE_CORE_TRACING = 1,\r\n MONGODB = 2,\r\n MYSQL = 4,\r\n REDIS = 8,\r\n POSTGRES = 16,\r\n BUNYAN = 32,\r\n WINSTON = 64,\r\n}\r\n"]}