applicationinsights
Version:
Microsoft Application Insights module for Node.js
1 lines • 14.9 kB
Source Map (JSON)
{"version":3,"file":"shim-jsonConfig.js","sourceRoot":"","sources":["../../../src/shim/shim-jsonConfig.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAK7B,4CAA0C;AAE1C,MAAM,sBAAsB,GAAG,wCAAwC,CAAC;AACxE,MAAM,WAAW,GAAG,2CAA2C,CAAC;AAChE,MAAM,oBAAoB,GAAG,uCAAuC,CAAC;AACrE,MAAM,cAAc,GAAG,YAAY,CAAC;AACpC,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,MAAM,uBAAuB,GAAG,4CAA4C,CAAC;AAC7E,MAAM,wBAAwB,GAAG,+CAA+C,CAAC;AACjF,MAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,MAAM,4BAA4B,GAAG,iDAAiD,CAAC;AACvF,MAAM,uCAAuC,GAAG,2DAA2D,CAAC;AAC5G,MAAM,6BAA6B,GAAG,gDAAgD,CAAC;AAEvF,MAAa,cAAc;IAsDvB;QACI,mCAAmC;QACnC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAC1D,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAClE,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACpE,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAC5D,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC5E,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,IAAI,EAAE,CAAC;QAC9E,IAAI,CAAC,kCAAkC,GAAG,OA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C,8CAA8C,CAAC;YAChH,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,mBAAmB,CAAC;YAC1D,IAAI,CAAC,yBAAyB,GAAG,UAAU,CAAC,yBAAyB,CAAC;YACtE,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC5D,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC5D,IAAI,CAAC,0BAA0B,GAAG,UAAU,CAAC,0BAA0B,CAAC;YACxE,IAAI,CAAC,4BAA4B,GAAG,UAAU,CAAC,4BAA4B,CAAC;YAC5E,IAAI,CAAC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,CAAC;YAC9D,IAAI,CAAC,wBAAwB,GAAG,UAAU,CAAC,wBAAwB,CAAC;YACpE,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;SACnD;QAAC,OAAO,GAAG,EAAE;YACV,UAAI,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;SAC3D;IACL,CAAC;CACJ;AAjKD,wCAiKC","sourcesContent":["import * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport * as http from \"http\";\r\nimport * as https from \"https\";\r\nimport * as azureCoreAuth from \"@azure/core-auth\";\r\nimport { DistributedTracingModes, IDisabledExtendedMetrics, IJsonConfig, IWebInstrumentationConfig } from \"./types\";\r\nimport { diag } from \"@opentelemetry/api\";\r\n\r\nconst ENV_CONFIGURATION_FILE = \"APPLICATIONINSIGHTS_CONFIGURATION_FILE\";\r\nconst ENV_CONTENT = \"APPLICATIONINSIGHTS_CONFIGURATION_CONTENT\";\r\nconst ENV_connectionString = \"APPLICATIONINSIGHTS_CONNECTION_STRING\";\r\nconst ENV_http_proxy = \"http_proxy\";\r\nconst ENV_https_proxy = \"https_proxy\";\r\nconst ENV_noDiagnosticChannel = \"APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL\";\r\nconst ENV_noHttpAgentKeepAlive = \"APPLICATION_INSIGHTS_NO_HTTP_AGENT_KEEP_ALIVE\";\r\nconst ENV_noPatchModules = \"APPLICATION_INSIGHTS_NO_PATCH_MODULES\";\r\nconst ENV_webInstrumentationEnable = \"APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_ENABLED\";\r\nconst ENV_webInstrumentation_connectionString = \"APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_CONNECTION_STRING\";\r\nconst ENV_webInstrumentation_source = \"APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_SOURCE\";\r\n\r\nexport class ShimJsonConfig implements IJsonConfig {\r\n private static _instance: ShimJsonConfig;\r\n\r\n public endpointUrl: string;\r\n public connectionString: string;\r\n public disableAllExtendedMetrics: boolean;\r\n public extendedMetricDisablers: string;\r\n public proxyHttpUrl: string;\r\n public proxyHttpsUrl: string;\r\n public noDiagnosticChannel: boolean;\r\n public noHttpAgentKeepAlive: boolean;\r\n public noPatchModules: string;\r\n public maxBatchSize: number;\r\n public maxBatchIntervalMs: number;\r\n public disableAppInsights: boolean;\r\n public samplingPercentage: number;\r\n public correlationHeaderExcludedDomains: string[];\r\n public httpAgent: http.Agent;\r\n public httpsAgent: https.Agent;\r\n public ignoreLegacyHeaders: boolean;\r\n public aadTokenCredential?: azureCoreAuth.TokenCredential;\r\n public enableAutoCollectConsole: boolean;\r\n public enableLoggerErrorToTrace: boolean;\r\n public enableAutoCollectPerformance: boolean;\r\n public enableAutoCollectExternalLoggers: boolean;\r\n public enableAutoCollectPreAggregatedMetrics: boolean;\r\n public enableAutoCollectHeartbeat: boolean;\r\n public enableAutoCollectRequests: boolean;\r\n public enableAutoCollectDependencies: boolean;\r\n public enableAutoDependencyCorrelation: boolean;\r\n public enableAutoCollectIncomingRequestAzureFunctions: boolean;\r\n public enableSendLiveMetrics: boolean;\r\n public enableUseDiskRetryCaching: boolean;\r\n public enableUseAsyncHooks: boolean;\r\n public distributedTracingMode: DistributedTracingModes;\r\n public enableAutoCollectExtendedMetrics: boolean | IDisabledExtendedMetrics;\r\n public enableResendInterval: number;\r\n public enableMaxBytesOnDisk: number;\r\n public enableInternalDebugLogging: boolean;\r\n public enableInternalWarningLogging: boolean;\r\n public quickPulseHost: string;\r\n public enableWebInstrumentation: boolean;\r\n public enableAutoCollectExceptions: boolean;\r\n public webInstrumentationConnectionString?: string;\r\n public webInstrumentationConfig: IWebInstrumentationConfig[];\r\n public webInstrumentationSrc: string;\r\n\r\n public static getInstance() {\r\n if (!ShimJsonConfig._instance) {\r\n ShimJsonConfig._instance = new ShimJsonConfig();\r\n }\r\n return ShimJsonConfig._instance;\r\n }\r\n\r\n constructor() {\r\n // Load environment variables first\r\n this.connectionString = process.env[ENV_connectionString];\r\n this.noDiagnosticChannel = !!process.env[ENV_noDiagnosticChannel];\r\n this.noHttpAgentKeepAlive = !!process.env[ENV_noHttpAgentKeepAlive];\r\n this.noPatchModules = process.env[ENV_noPatchModules] || \"\";\r\n this.enableWebInstrumentation = !!process.env[ENV_webInstrumentationEnable];\r\n this.webInstrumentationSrc = process.env[ENV_webInstrumentation_source] || \"\";\r\n this.webInstrumentationConnectionString = process.env[ENV_webInstrumentation_connectionString] || \"\";\r\n\r\n this._loadJsonFile();\r\n }\r\n\r\n private _loadJsonFile() {\r\n let jsonString = \"\";\r\n const contentJsonConfig = process.env[ENV_CONTENT];\r\n // JSON string added directly in env variable\r\n if (contentJsonConfig) {\r\n jsonString = contentJsonConfig;\r\n }\r\n // JSON file\r\n else {\r\n const configFileName = \"applicationinsights.json\";\r\n const rootPath = path.join(__dirname, \"../../../\"); // Root of folder (__dirname = ../dist-esm/src)\r\n let tempDir = path.join(rootPath, configFileName); // default\r\n const configFile = process.env[ENV_CONFIGURATION_FILE];\r\n if (configFile) {\r\n if (path.isAbsolute(configFile)) {\r\n tempDir = configFile;\r\n } else {\r\n tempDir = path.join(rootPath, configFile); // Relative path to applicationinsights folder\r\n }\r\n }\r\n try {\r\n jsonString = fs.readFileSync(tempDir, \"utf8\");\r\n } catch (err) {\r\n diag.info(\"Failed to read JSON config file: \", err);\r\n }\r\n }\r\n try {\r\n const jsonConfig: IJsonConfig = JSON.parse(jsonString);\r\n if (jsonConfig.connectionString !== undefined) {\r\n this.connectionString = jsonConfig.connectionString;\r\n }\r\n if (jsonConfig.disableAllExtendedMetrics !== undefined) {\r\n this.disableAllExtendedMetrics = jsonConfig.disableAllExtendedMetrics;\r\n }\r\n if (jsonConfig.extendedMetricDisablers !== undefined) {\r\n this.extendedMetricDisablers = jsonConfig.extendedMetricDisablers;\r\n }\r\n if (jsonConfig.proxyHttpUrl !== undefined) {\r\n this.proxyHttpUrl = jsonConfig.proxyHttpUrl;\r\n }\r\n if (jsonConfig.proxyHttpsUrl !== undefined) {\r\n this.proxyHttpsUrl = jsonConfig.proxyHttpsUrl;\r\n }\r\n if (jsonConfig.noDiagnosticChannel !== undefined) {\r\n this.noDiagnosticChannel = jsonConfig.noDiagnosticChannel;\r\n }\r\n if (jsonConfig.noHttpAgentKeepAlive !== undefined) {\r\n this.noHttpAgentKeepAlive = jsonConfig.noHttpAgentKeepAlive;\r\n }\r\n if (jsonConfig.noPatchModules !== undefined) {\r\n this.noPatchModules = jsonConfig.noPatchModules;\r\n }\r\n if (jsonConfig.enableWebInstrumentation !== undefined) {\r\n this.enableWebInstrumentation = jsonConfig.enableWebInstrumentation;\r\n }\r\n if (jsonConfig.webInstrumentationSrc !== undefined) {\r\n this.webInstrumentationSrc = jsonConfig.webInstrumentationSrc;\r\n }\r\n if (jsonConfig.webInstrumentationConnectionString !== undefined) {\r\n this.webInstrumentationConnectionString = jsonConfig.webInstrumentationConnectionString;\r\n }\r\n this.endpointUrl = jsonConfig.endpointUrl;\r\n this.samplingPercentage = jsonConfig.samplingPercentage;\r\n this.enableAutoCollectExternalLoggers = jsonConfig.enableAutoCollectExternalLoggers;\r\n this.enableAutoCollectConsole = jsonConfig.enableAutoCollectConsole;\r\n this.enableLoggerErrorToTrace = jsonConfig.enableLoggerErrorToTrace;\r\n this.enableAutoCollectExceptions = jsonConfig.enableAutoCollectExceptions;\r\n this.enableAutoCollectPerformance = jsonConfig.enableAutoCollectPerformance;\r\n this.enableAutoCollectPreAggregatedMetrics = jsonConfig.enableAutoCollectPreAggregatedMetrics;\r\n this.enableAutoDependencyCorrelation = jsonConfig.enableAutoDependencyCorrelation;\r\n this.maxBatchSize = jsonConfig.maxBatchSize;\r\n this.maxBatchIntervalMs = jsonConfig.maxBatchIntervalMs;\r\n this.disableAppInsights = jsonConfig.disableAppInsights;\r\n this.correlationHeaderExcludedDomains = jsonConfig.correlationHeaderExcludedDomains;\r\n this.ignoreLegacyHeaders = jsonConfig.ignoreLegacyHeaders;\r\n this.distributedTracingMode = jsonConfig.distributedTracingMode;\r\n this.enableAutoCollectExtendedMetrics = jsonConfig.enableAutoCollectExtendedMetrics;\r\n this.enableAutoCollectHeartbeat = jsonConfig.enableAutoCollectHeartbeat;\r\n this.enableAutoCollectRequests = jsonConfig.enableAutoCollectRequests;\r\n this.enableAutoCollectDependencies = jsonConfig.enableAutoCollectDependencies;\r\n this.enableAutoCollectIncomingRequestAzureFunctions = jsonConfig.enableAutoCollectIncomingRequestAzureFunctions;\r\n this.enableUseAsyncHooks = jsonConfig.enableUseAsyncHooks;\r\n this.enableUseDiskRetryCaching = jsonConfig.enableUseDiskRetryCaching;\r\n this.enableResendInterval = jsonConfig.enableResendInterval;\r\n this.enableMaxBytesOnDisk = jsonConfig.enableMaxBytesOnDisk;\r\n this.enableInternalDebugLogging = jsonConfig.enableInternalDebugLogging;\r\n this.enableInternalWarningLogging = jsonConfig.enableInternalWarningLogging;\r\n this.enableSendLiveMetrics = jsonConfig.enableSendLiveMetrics;\r\n this.webInstrumentationConfig = jsonConfig.webInstrumentationConfig;\r\n this.quickPulseHost = jsonConfig.quickPulseHost;\r\n } catch (err) {\r\n diag.info(\"Missing or invalid JSON config file: \", err);\r\n }\r\n }\r\n}"]}