From e65d9b877ad7ea90ad39109cc828e73511254747 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 15 Aug 2023 10:33:33 -0700 Subject: [PATCH 1/2] Files restructure (#1187) --- src/agent/agentLoader.ts | 2 +- src/agent/diagnostics/writers/consoleWriter.ts | 2 +- src/agent/diagnostics/writers/fileWriter.ts | 2 +- src/applicationInsightsClient.ts | 2 +- src/{shim/autoCollection => logs}/console.ts | 4 ++-- .../diagnostic-channel/bunyan.sub.ts | 4 ++-- .../diagnostic-channel/console.sub.ts | 4 ++-- .../diagnostic-channel/initialization.ts | 2 +- .../diagnostic-channel/winston.sub.ts | 4 ++-- src/{shim/autoCollection => logs}/exceptions.ts | 4 ++-- .../autoCollection => metrics}/nativeMetrics.ts | 2 +- src/{shim => shared}/configuration/internal.ts | 0 src/{shim => shared}/configuration/jsonConfig.ts | 0 src/{shim => shared}/logging/index.ts | 0 .../logging/internalAzureLogger.ts | 0 src/{shim => shared}/logging/logger.ts | 0 src/{shim => shared}/util/configHelper.ts | 0 src/{shim => shared}/util/contextTagKeys.ts | 0 src/{shim => shared}/util/fileSystemHelper.ts | 0 src/{shim => shared}/util/index.ts | 0 src/{shim => shared}/util/util.ts | 0 src/shim/NodeClient.ts | 2 +- src/shim/{configuration => }/config.ts | 6 +++--- src/shim/context.ts | 2 +- src/shim/correlationContextManager.ts | 2 +- src/shim/shim-applicationinsights.ts | 4 ++-- src/shim/telemetryClient.ts | 14 +++++++------- .../{shim/autoCollection => logs}/bunyan.tests.ts | 8 ++++---- .../{shim/autoCollection => logs}/console.tests.ts | 6 +++--- .../autoCollection => logs}/exceptions.tests.ts | 2 +- .../{shim/autoCollection => logs}/winston.tests.ts | 6 +++--- test/unitTests/shared/logging.tests.ts | 2 +- test/unitTests/shared/util.tests.ts | 2 +- test/unitTests/shim/config.tests.ts | 3 +-- 34 files changed, 45 insertions(+), 46 deletions(-) rename src/{shim/autoCollection => logs}/console.ts (92%) rename src/{shim/autoCollection => logs}/diagnostic-channel/bunyan.sub.ts (93%) rename src/{shim/autoCollection => logs}/diagnostic-channel/console.sub.ts (92%) rename src/{shim/autoCollection => logs}/diagnostic-channel/initialization.ts (95%) rename src/{shim/autoCollection => logs}/diagnostic-channel/winston.sub.ts (95%) rename src/{shim/autoCollection => logs}/exceptions.ts (98%) rename src/{shim/autoCollection => metrics}/nativeMetrics.ts (99%) rename src/{shim => shared}/configuration/internal.ts (100%) rename src/{shim => shared}/configuration/jsonConfig.ts (100%) rename src/{shim => shared}/logging/index.ts (100%) rename src/{shim => shared}/logging/internalAzureLogger.ts (100%) rename src/{shim => shared}/logging/logger.ts (100%) rename src/{shim => shared}/util/configHelper.ts (100%) rename src/{shim => shared}/util/contextTagKeys.ts (100%) rename src/{shim => shared}/util/fileSystemHelper.ts (100%) rename src/{shim => shared}/util/index.ts (100%) rename src/{shim => shared}/util/util.ts (100%) rename src/shim/{configuration => }/config.ts (97%) rename test/unitTests/{shim/autoCollection => logs}/bunyan.tests.ts (92%) rename test/unitTests/{shim/autoCollection => logs}/console.tests.ts (94%) rename test/unitTests/{shim/autoCollection => logs}/exceptions.tests.ts (96%) rename test/unitTests/{shim/autoCollection => logs}/winston.tests.ts (93%) diff --git a/src/agent/agentLoader.ts b/src/agent/agentLoader.ts index 36e6f768e..23a32fac4 100644 --- a/src/agent/agentLoader.ts +++ b/src/agent/agentLoader.ts @@ -3,7 +3,7 @@ import { ManagedIdentityCredential } from "@azure/identity"; import { AzureMonitorOpenTelemetryClient } from "@azure/monitor-opentelemetry"; -import { Util } from "../shim/util"; +import { Util } from "../shared/util"; import { ConsoleWriter } from "./diagnostics/writers/consoleWriter"; import { DiagnosticLogger } from "./diagnostics/diagnosticLogger"; import { StatusLogger } from "./diagnostics/statusLogger"; diff --git a/src/agent/diagnostics/writers/consoleWriter.ts b/src/agent/diagnostics/writers/consoleWriter.ts index 3d52d4138..8332bd677 100644 --- a/src/agent/diagnostics/writers/consoleWriter.ts +++ b/src/agent/diagnostics/writers/consoleWriter.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Util } from "../../../shim/util"; +import { Util } from "../../../shared/util"; import { IAgentLogger } from "../../types"; export class ConsoleWriter implements IAgentLogger { diff --git a/src/agent/diagnostics/writers/fileWriter.ts b/src/agent/diagnostics/writers/fileWriter.ts index 563843b4f..2bed57318 100644 --- a/src/agent/diagnostics/writers/fileWriter.ts +++ b/src/agent/diagnostics/writers/fileWriter.ts @@ -5,7 +5,7 @@ import * as path from "path"; import * as fs from "fs"; import { makeStatusDirs, renameCurrentFile } from "./fileHelpers"; import { IAgentLogger } from "../../types"; -import { Util } from "../../../shim/util"; +import { Util } from "../../../shared/util"; export interface FileWriterOptions { append: boolean; // Overwrite or append on file write (false) diff --git a/src/applicationInsightsClient.ts b/src/applicationInsightsClient.ts index cafee7a62..0f7faeb16 100644 --- a/src/applicationInsightsClient.ts +++ b/src/applicationInsightsClient.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { ApplicationInsightsConfig } from "./applicationInsightsConfig"; -import { Logger } from "./shim/logging"; +import { Logger } from "./shared/logging"; import { AzureMonitorOpenTelemetryClient, AzureMonitorOpenTelemetryOptions } from "@azure/monitor-opentelemetry"; /** diff --git a/src/shim/autoCollection/console.ts b/src/logs/console.ts similarity index 92% rename from src/shim/autoCollection/console.ts rename to src/logs/console.ts index 8bcb994ab..73ff09724 100644 --- a/src/shim/autoCollection/console.ts +++ b/src/logs/console.ts @@ -1,6 +1,6 @@ -import { LogInstrumentationsConfig } from "../../types"; +import { LogInstrumentationsConfig } from "../types"; import { enablePublishers } from "./diagnostic-channel/initialization"; -import { TelemetryClient } from "../telemetryClient"; +import { TelemetryClient } from "../shim/telemetryClient"; enablePublishers(); export class AutoCollectConsole { diff --git a/src/shim/autoCollection/diagnostic-channel/bunyan.sub.ts b/src/logs/diagnostic-channel/bunyan.sub.ts similarity index 93% rename from src/shim/autoCollection/diagnostic-channel/bunyan.sub.ts rename to src/logs/diagnostic-channel/bunyan.sub.ts index 3927bae68..81fee8155 100644 --- a/src/shim/autoCollection/diagnostic-channel/bunyan.sub.ts +++ b/src/logs/diagnostic-channel/bunyan.sub.ts @@ -2,8 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. import { channel, IStandardEvent, trueFilter } from "diagnostic-channel"; import { bunyan } from "diagnostic-channel-publishers"; -import { KnownSeverityLevel } from "../../../declarations/generated"; -import { TelemetryClient } from "../../telemetryClient"; +import { KnownSeverityLevel } from "../../declarations/generated"; +import { TelemetryClient } from "../../shim/telemetryClient"; let clients: TelemetryClient[] = []; diff --git a/src/shim/autoCollection/diagnostic-channel/console.sub.ts b/src/logs/diagnostic-channel/console.sub.ts similarity index 92% rename from src/shim/autoCollection/diagnostic-channel/console.sub.ts rename to src/logs/diagnostic-channel/console.sub.ts index 6969e0590..e3508680c 100644 --- a/src/shim/autoCollection/diagnostic-channel/console.sub.ts +++ b/src/logs/diagnostic-channel/console.sub.ts @@ -2,8 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. import { channel, IStandardEvent, trueFilter } from "diagnostic-channel"; import { console as consolePub } from "diagnostic-channel-publishers"; -import { KnownSeverityLevel } from "../../../declarations/generated"; -import { TelemetryClient } from "../../telemetryClient"; +import { KnownSeverityLevel } from "../../declarations/generated"; +import { TelemetryClient } from "../../shim/telemetryClient"; let clients: TelemetryClient[] = []; diff --git a/src/shim/autoCollection/diagnostic-channel/initialization.ts b/src/logs/diagnostic-channel/initialization.ts similarity index 95% rename from src/shim/autoCollection/diagnostic-channel/initialization.ts rename to src/logs/diagnostic-channel/initialization.ts index 61257a48f..b6db3dad8 100644 --- a/src/shim/autoCollection/diagnostic-channel/initialization.ts +++ b/src/logs/diagnostic-channel/initialization.ts @@ -3,7 +3,7 @@ // Don't reference modules from these directly. Use only for types. import * as DiagChannelPublishers from "diagnostic-channel-publishers"; -import { Logger } from "../../logging"; +import { Logger } from "../../shared/logging"; const TAG = "DiagnosticChannel"; let isInitialized = false; diff --git a/src/shim/autoCollection/diagnostic-channel/winston.sub.ts b/src/logs/diagnostic-channel/winston.sub.ts similarity index 95% rename from src/shim/autoCollection/diagnostic-channel/winston.sub.ts rename to src/logs/diagnostic-channel/winston.sub.ts index 47dfc4b58..cf9e3818d 100644 --- a/src/shim/autoCollection/diagnostic-channel/winston.sub.ts +++ b/src/logs/diagnostic-channel/winston.sub.ts @@ -2,8 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. import { channel, IStandardEvent, trueFilter } from "diagnostic-channel"; import { winston } from "diagnostic-channel-publishers"; -import { KnownSeverityLevel } from "../../../declarations/generated"; -import { TelemetryClient } from "../../telemetryClient"; +import { KnownSeverityLevel } from "../../declarations/generated"; +import { TelemetryClient } from "../../shim/telemetryClient"; let clients: TelemetryClient[] = []; diff --git a/src/shim/autoCollection/exceptions.ts b/src/logs/exceptions.ts similarity index 98% rename from src/shim/autoCollection/exceptions.ts rename to src/logs/exceptions.ts index 772e900d8..ca8764d87 100644 --- a/src/shim/autoCollection/exceptions.ts +++ b/src/logs/exceptions.ts @@ -1,5 +1,5 @@ -import { Util } from "../util"; -import { TelemetryClient } from "../telemetryClient"; +import { Util } from "../shared/util"; +import { TelemetryClient } from "../shim/telemetryClient"; type ExceptionHandle = "uncaughtExceptionMonitor" | "uncaughtException" | "unhandledRejection"; const UNCAUGHT_EXCEPTION_MONITOR_HANDLER_NAME: ExceptionHandle = "uncaughtExceptionMonitor"; diff --git a/src/shim/autoCollection/nativeMetrics.ts b/src/metrics/nativeMetrics.ts similarity index 99% rename from src/shim/autoCollection/nativeMetrics.ts rename to src/metrics/nativeMetrics.ts index cd7fe92e6..47ebfb8eb 100644 --- a/src/shim/autoCollection/nativeMetrics.ts +++ b/src/metrics/nativeMetrics.ts @@ -10,7 +10,7 @@ import { PeriodicExportingMetricReaderOptions, } from "@opentelemetry/sdk-metrics"; import { Histogram, Meter, ObservableGauge, ObservableResult } from "@opentelemetry/api"; -import { Logger } from "../logging"; +import { Logger } from "../shared/logging"; /** * Azure Monitor Native Metrics diff --git a/src/shim/configuration/internal.ts b/src/shared/configuration/internal.ts similarity index 100% rename from src/shim/configuration/internal.ts rename to src/shared/configuration/internal.ts diff --git a/src/shim/configuration/jsonConfig.ts b/src/shared/configuration/jsonConfig.ts similarity index 100% rename from src/shim/configuration/jsonConfig.ts rename to src/shared/configuration/jsonConfig.ts diff --git a/src/shim/logging/index.ts b/src/shared/logging/index.ts similarity index 100% rename from src/shim/logging/index.ts rename to src/shared/logging/index.ts diff --git a/src/shim/logging/internalAzureLogger.ts b/src/shared/logging/internalAzureLogger.ts similarity index 100% rename from src/shim/logging/internalAzureLogger.ts rename to src/shared/logging/internalAzureLogger.ts diff --git a/src/shim/logging/logger.ts b/src/shared/logging/logger.ts similarity index 100% rename from src/shim/logging/logger.ts rename to src/shared/logging/logger.ts diff --git a/src/shim/util/configHelper.ts b/src/shared/util/configHelper.ts similarity index 100% rename from src/shim/util/configHelper.ts rename to src/shared/util/configHelper.ts diff --git a/src/shim/util/contextTagKeys.ts b/src/shared/util/contextTagKeys.ts similarity index 100% rename from src/shim/util/contextTagKeys.ts rename to src/shared/util/contextTagKeys.ts diff --git a/src/shim/util/fileSystemHelper.ts b/src/shared/util/fileSystemHelper.ts similarity index 100% rename from src/shim/util/fileSystemHelper.ts rename to src/shared/util/fileSystemHelper.ts diff --git a/src/shim/util/index.ts b/src/shared/util/index.ts similarity index 100% rename from src/shim/util/index.ts rename to src/shared/util/index.ts diff --git a/src/shim/util/util.ts b/src/shared/util/util.ts similarity index 100% rename from src/shim/util/util.ts rename to src/shared/util/util.ts diff --git a/src/shim/NodeClient.ts b/src/shim/NodeClient.ts index 86ccb4842..ab9e29c06 100644 --- a/src/shim/NodeClient.ts +++ b/src/shim/NodeClient.ts @@ -1,4 +1,4 @@ -import { Logger } from "./logging"; +import { Logger } from "../shared/logging"; import { Contracts, TelemetryClient } from "./shim-applicationinsights"; class NodeClient extends TelemetryClient { diff --git a/src/shim/configuration/config.ts b/src/shim/config.ts similarity index 97% rename from src/shim/configuration/config.ts rename to src/shim/config.ts index 5f537e42f..a141a974e 100644 --- a/src/shim/configuration/config.ts +++ b/src/shim/config.ts @@ -1,9 +1,9 @@ -import { DistributedTracingModes, IConfig, IDisabledExtendedMetrics, IWebInstrumentationConfig } from "../types"; +import { DistributedTracingModes, IConfig, IDisabledExtendedMetrics, IWebInstrumentationConfig } from "./types"; import http = require("http"); import https = require("https"); import azureCoreAuth = require("@azure/core-auth"); -import { Logger } from "../logging"; -import constants = require("../../declarations/constants"); +import { Logger } from "../shared/logging"; +import constants = require("../declarations/constants"); class config implements IConfig { diff --git a/src/shim/context.ts b/src/shim/context.ts index b60f1fe44..30a21331c 100644 --- a/src/shim/context.ts +++ b/src/shim/context.ts @@ -1,4 +1,4 @@ -import ContextTagKeys = require("./util/contextTagKeys"); +import ContextTagKeys = require("../shared/util/contextTagKeys"); export class Context { public keys: ContextTagKeys; diff --git a/src/shim/correlationContextManager.ts b/src/shim/correlationContextManager.ts index 888ddb5bd..7a70493af 100644 --- a/src/shim/correlationContextManager.ts +++ b/src/shim/correlationContextManager.ts @@ -4,7 +4,7 @@ import { context, SpanContext, trace, Context } from "@opentelemetry/api"; import { TraceState } from "@opentelemetry/core"; import { Span } from "@opentelemetry/sdk-trace-base"; import { ICorrelationContext, ITraceparent, ITracestate, HttpRequest, ICustomProperties } from "./types"; -import { Logger } from "./logging"; +import { Logger } from "../shared/logging"; import * as azureFunctionsTypes from "@azure/functions"; export class CorrelationContextManager { diff --git a/src/shim/shim-applicationinsights.ts b/src/shim/shim-applicationinsights.ts index 627a81173..32a8254e6 100644 --- a/src/shim/shim-applicationinsights.ts +++ b/src/shim/shim-applicationinsights.ts @@ -3,13 +3,13 @@ import { DiagLogLevel, SpanContext } from "@opentelemetry/api"; import { CorrelationContextManager } from "./correlationContextManager"; import * as azureFunctionsTypes from "@azure/functions"; import { Span } from "@opentelemetry/sdk-trace-base"; -import { Logger } from "./logging"; +import { Logger } from "../shared/logging"; import { ICorrelationContext, HttpRequest, DistributedTracingModes } from "./types"; import { TelemetryClient } from "./telemetryClient"; import * as Contracts from "../declarations/contracts"; import { ApplicationInsightsOptions } from "../types"; import { HttpInstrumentationConfig } from "@opentelemetry/instrumentation-http"; -import ConfigHelper = require("./util/configHelper"); +import ConfigHelper = require("../shared/util/configHelper"); // We export these imports so that SDK users may use these classes directly. // They're exposed using "export import" so that types are passed along as expected diff --git a/src/shim/telemetryClient.ts b/src/shim/telemetryClient.ts index 847f43fe8..b5f0ab533 100644 --- a/src/shim/telemetryClient.ts +++ b/src/shim/telemetryClient.ts @@ -10,17 +10,17 @@ import { SemanticAttributes } from "@opentelemetry/semantic-conventions"; import * as Contracts from "../declarations/contracts"; import { AvailabilityData, TelemetryItem as Envelope, KnownSeverityLevel, MessageData, MonitorDomain, PageViewData, TelemetryEventData, TelemetryExceptionData, TelemetryExceptionDetails } from "../declarations/generated"; import { Context } from "./context"; -import { Logger } from "./logging"; -import { Util } from "./util"; -import { AutoCollectConsole } from "./autoCollection/console"; -import { AutoCollectExceptions, parseStack } from "./autoCollection/exceptions"; +import { Logger } from "../shared/logging"; +import { Util } from "../shared/util"; +import { AutoCollectConsole } from "../logs/console"; +import { AutoCollectExceptions, parseStack } from "../logs/exceptions"; import { ApplicationInsightsOptions, ExtendedMetricType } from "../types"; -import { InternalConfig } from "./configuration/internal"; +import { InternalConfig } from "../shared/configuration/internal"; import { IConfig } from "../shim/types"; -import Config = require("./configuration/config"); +import Config = require("./config"); import { dispose, Configuration, _setupCalled } from "./shim-applicationinsights"; import { HttpInstrumentationConfig } from "@opentelemetry/instrumentation-http"; -import ConfigHelper = require("./util/configHelper"); +import ConfigHelper = require("../shared/util/configHelper"); /** * Application Insights telemetry client provides interface to track telemetry items, register telemetry initializers and diff --git a/test/unitTests/shim/autoCollection/bunyan.tests.ts b/test/unitTests/logs/bunyan.tests.ts similarity index 92% rename from test/unitTests/shim/autoCollection/bunyan.tests.ts rename to test/unitTests/logs/bunyan.tests.ts index 510e109d7..a13b9b380 100644 --- a/test/unitTests/shim/autoCollection/bunyan.tests.ts +++ b/test/unitTests/logs/bunyan.tests.ts @@ -3,10 +3,10 @@ import * as sinon from "sinon"; import { channel } from "diagnostic-channel"; import { bunyan } from "diagnostic-channel-publishers"; -import { enable, dispose } from "../../../../src/shim/autoCollection/diagnostic-channel/bunyan.sub"; -import { Util } from "../../../../src/shim/util"; -import { TelemetryClient } from "../../../../src"; -import { ApplicationInsightsOptions } from "../../../../src/types"; +import { enable, dispose } from "../../../src/logs/diagnostic-channel/bunyan.sub"; +import { Util } from "../../../src/shared/util"; +import { TelemetryClient } from "../../../src"; +import { ApplicationInsightsOptions } from "../../../src/types"; describe("diagnostic-channel/bunyan", () => { let sandbox: sinon.SinonSandbox; diff --git a/test/unitTests/shim/autoCollection/console.tests.ts b/test/unitTests/logs/console.tests.ts similarity index 94% rename from test/unitTests/shim/autoCollection/console.tests.ts rename to test/unitTests/logs/console.tests.ts index 2e18a3837..9837f141a 100644 --- a/test/unitTests/shim/autoCollection/console.tests.ts +++ b/test/unitTests/logs/console.tests.ts @@ -3,9 +3,9 @@ import * as sinon from "sinon"; import { channel } from "diagnostic-channel"; import { console } from "diagnostic-channel-publishers"; -import { enable, dispose } from "../../../../src/shim/autoCollection/diagnostic-channel/console.sub"; -import { TelemetryClient } from "../../../../src"; -import { ApplicationInsightsOptions } from "../../../../src/types"; +import { enable, dispose } from "../../../src/logs/diagnostic-channel/console.sub"; +import { TelemetryClient } from "../../../src"; +import { ApplicationInsightsOptions } from "../../../src/types"; describe("AutoCollection/Console", () => { let sandbox: sinon.SinonSandbox; diff --git a/test/unitTests/shim/autoCollection/exceptions.tests.ts b/test/unitTests/logs/exceptions.tests.ts similarity index 96% rename from test/unitTests/shim/autoCollection/exceptions.tests.ts rename to test/unitTests/logs/exceptions.tests.ts index 99d18f4e7..366690a88 100644 --- a/test/unitTests/shim/autoCollection/exceptions.tests.ts +++ b/test/unitTests/logs/exceptions.tests.ts @@ -1,7 +1,7 @@ import * as assert from "assert"; import * as sinon from "sinon"; -import { AutoCollectExceptions } from "../../../../src/shim/autoCollection/exceptions"; +import { AutoCollectExceptions } from "../../../src/logs/exceptions"; describe("AutoCollection/Exceptions", () => { let sandbox: sinon.SinonSandbox; diff --git a/test/unitTests/shim/autoCollection/winston.tests.ts b/test/unitTests/logs/winston.tests.ts similarity index 93% rename from test/unitTests/shim/autoCollection/winston.tests.ts rename to test/unitTests/logs/winston.tests.ts index 2df15bd55..0201b341e 100644 --- a/test/unitTests/shim/autoCollection/winston.tests.ts +++ b/test/unitTests/logs/winston.tests.ts @@ -3,9 +3,9 @@ import * as sinon from "sinon"; import { channel } from "diagnostic-channel"; import { winston } from "diagnostic-channel-publishers"; -import { enable, dispose } from "../../../../src/shim/autoCollection/diagnostic-channel/winston.sub"; -import { TelemetryClient } from "../../../../src"; -import { ApplicationInsightsOptions } from "../../../../src/types"; +import { enable, dispose } from "../../../src/logs/diagnostic-channel/winston.sub"; +import { TelemetryClient } from "../../../src"; +import { ApplicationInsightsOptions } from "../../../src/types"; describe("diagnostic-channel/winston", () => { let sandbox: sinon.SinonSandbox; diff --git a/test/unitTests/shared/logging.tests.ts b/test/unitTests/shared/logging.tests.ts index d854faf24..a93cbbc3b 100644 --- a/test/unitTests/shared/logging.tests.ts +++ b/test/unitTests/shared/logging.tests.ts @@ -2,7 +2,7 @@ import { diag, DiagLogLevel } from "@opentelemetry/api"; import * as assert from "assert"; import * as sinon from "sinon"; -import { Logger } from "../../../src/shim/logging"; +import { Logger } from "../../../src/shared/logging"; describe("Library/Logger", () => { let sandbox: sinon.SinonSandbox; diff --git a/test/unitTests/shared/util.tests.ts b/test/unitTests/shared/util.tests.ts index 6f97e149d..266bd617b 100644 --- a/test/unitTests/shared/util.tests.ts +++ b/test/unitTests/shared/util.tests.ts @@ -1,7 +1,7 @@ import * as assert from "assert"; import * as sinon from "sinon"; -import { Util } from "../../../src/shim/util"; +import { Util } from "../../../src/shared/util"; describe("Library/Util", () => { let sandbox: sinon.SinonSandbox; diff --git a/test/unitTests/shim/config.tests.ts b/test/unitTests/shim/config.tests.ts index 73f3acc69..b37e675d9 100644 --- a/test/unitTests/shim/config.tests.ts +++ b/test/unitTests/shim/config.tests.ts @@ -2,10 +2,9 @@ import assert = require('assert'); import sinon = require('sinon'); import { TelemetryClient } from '../../../applicationinsights'; import { HttpInstrumentationConfig } from '@opentelemetry/instrumentation-http'; -import { CorrelationContextManager } from '../../../src/shim/correlationContextManager'; const applicationInsights = require('../../../applicationinsights'); import azureCoreAuth = require("@azure/core-auth"); -import { Logger } from "../../../src/shim/logging" +import { Logger } from "../../../src/shared/logging" import { DiagLogLevel } from '@opentelemetry/api'; class TestTokenCredential implements azureCoreAuth.TokenCredential { From 95f0ec0a32a18cd45f2d7a1a0045e7aaf57301a0 Mon Sep 17 00:00:00 2001 From: Jackson Weber <47067795+JacksonWeber@users.noreply.github.com> Date: Mon, 21 Aug 2023 13:45:20 -0700 Subject: [PATCH 2/2] [Shim] Fully Support JSON Configuration (#1183) * Add AutoCollectDependencies and Requests logic. * Add http.enable functionality and setUseDiskRetryCaching. * Add required no-op methods. * Add methods to telemetryClient that were previously supported. * Add global applicationinsights to * Include possible way to handle config property on the TelemetryClient. * Set NodeHttp methods as no-ops. * Framework for the config class to use with client.config. * Begin adding config properties to be modified on the client. * Fix client.config initialization issue and implement config properties. * Add shim usage detection env var. * Revert "Add shim usage detection env var." This reverts commit 0c77845a3116e10467dfde3b74c498d75aaf0655. * Apply env var updates. * Fix env var check. * Revert "Fix env var check." This reverts commit 153662989644b3532000b95931e59048fca879d6. * Env var. * Update package-lock. * Test if parseConfig is breaking functionaltests. * Update parseConfig to only run when in shim mode. * Add more of the config parsing. * Add final config values. * Begin tests for the client.confg. * Fix distro tests and update httpInstrumentation configs. * Update functionaltests. * Update package-lock.json * Test functional test update. * Is parseConfig breaking functionalTests? * Test parseConfig except enableAutoCollect methods. * Remove autoCollect logic. * Test if we're wiping instrumentations configs when running autoCollect methods. * Update shim-applicationinsights.ts * Add flag to indicate shim is initialized so we know when to run * Implement noPatchModules and update noDiagnosticChannel. * Add ContextTagKeys for implementing them on the context object. * Fix import. * Add support for further properties on the config and begin working on setting the context.tags. * Write tests, and fix config parse methods. * Add further tests, and update config methods that weren't working. * Add final config tests, and clean up duplicate code. * Deliver warnings when trying to set unsupported values. * Implement maxBatchInterval. * Remove tests and values not supported by client.config in AppInsights 2.x. * Test functionalTest. * Fix functional tests. * Test functionalTest. * Update main.js * Does parseConfig break functionalTests. * Update client setup. * Remove unneded connStringParsing and enpointUrl contruction. * Convert config helper to a collection of functions. * Create NodeClient class. * Add required JSON config values. * Setup for supporting the first JSON config value. * Clean up telemetryClient. * Make track messages more explicit. * Add initial JSON config parsing update, deprecate instrumentationKey/endpointUrl,. * Update telemetryClient.ts * Split JsonConfig into shim and non-shim files. * Clean up config files and begin adding tests. * Fix duplicate files. * Clean up config files and add JSON tests. * Reconfigure file paths. * Add JSON config file tests. * Add tests for the configuration string and environment variables. * Update applicationinsights.json * Update JSON config fields. --- src/shared/util/configHelper.ts | 63 ++++- src/shim/config.ts | 16 +- src/shim/shim-jsonConfig.ts | 179 ++++++++++++++ src/shim/telemetryClient.ts | 295 ++++++++++++++++++++---- test/unitTests/shim/config.json | 29 +++ test/unitTests/shim/config.tests.ts | 3 - test/unitTests/shim/jsonConfig.tests.ts | 147 ++++++++++++ 7 files changed, 670 insertions(+), 62 deletions(-) create mode 100644 src/shim/shim-jsonConfig.ts create mode 100644 test/unitTests/shim/config.json create mode 100644 test/unitTests/shim/jsonConfig.tests.ts diff --git a/src/shared/util/configHelper.ts b/src/shared/util/configHelper.ts index 8aab205d1..74cd62b57 100644 --- a/src/shared/util/configHelper.ts +++ b/src/shared/util/configHelper.ts @@ -66,7 +66,7 @@ export function setAutoCollectDependencies(options: ApplicationInsightsOptions, } } -export function setAutoCollectConsole(options: ApplicationInsightsOptions, value: boolean, enableConsole: boolean, collectConsoleLog = false) { +export function setAutoCollectConsole(options: ApplicationInsightsOptions, value: boolean, collectConsoleLog = false) { if (options) { options.logInstrumentations = { bunyan: { enabled: value }, @@ -75,3 +75,64 @@ export function setAutoCollectConsole(options: ApplicationInsightsOptions, value } } } + +export function enableAutoCollectExternalLoggers(options: ApplicationInsightsOptions, value: boolean) { + options.logInstrumentations = { + ...options.logInstrumentations, + winston: { enabled: value }, + bunyan: { enabled: value }, + } +} + +export function enableAutoCollectConsole(options: ApplicationInsightsOptions, value: boolean) { + options.logInstrumentations = { + ...options.logInstrumentations, + console: { enabled: value }, + } +} + +export function enableAutoCollectExtendedMetrics(options: ApplicationInsightsOptions, value: boolean) { + options.extendedMetrics = { + [ExtendedMetricType.gc]: value, + [ExtendedMetricType.heap]: value, + [ExtendedMetricType.loop]: value, + } +} + +export function setMaxBatchIntervalMs(options: ApplicationInsightsOptions, value: number) { + options.otlpTraceExporterConfig = { ...options.otlpTraceExporterConfig, timeoutMillis: value }; + options.otlpMetricExporterConfig = { ...options.otlpMetricExporterConfig, timeoutMillis: value }; + options.otlpLogExporterConfig = { ...options.otlpLogExporterConfig, timeoutMillis: value }; +} + +export function setProxyUrl(options: ApplicationInsightsOptions, proxyUrlString: string) { + const proxyUrl = new URL(proxyUrlString); + options.azureMonitorExporterConfig.proxyOptions = { + host: proxyUrl.hostname, + port: Number(proxyUrl.port), + } +} + +export function setExtendedMetricDisablers(options: ApplicationInsightsOptions, disablers: string) { + const extendedMetricDisablers: string[] = disablers.split(","); + for (const extendedMetricDisabler of extendedMetricDisablers) { + if (extendedMetricDisabler === "gc") { + options.extendedMetrics = { + ...options.extendedMetrics, + [ExtendedMetricType.gc]: false + }; + } + if (extendedMetricDisabler === "heap") { + options.extendedMetrics = { + ...options.extendedMetrics, + [ExtendedMetricType.heap]: false + }; + } + if (extendedMetricDisabler === "loop") { + options.extendedMetrics = { + ...options.extendedMetrics, + [ExtendedMetricType.loop]: false + }; + } + } +} diff --git a/src/shim/config.ts b/src/shim/config.ts index a141a974e..a844349bc 100644 --- a/src/shim/config.ts +++ b/src/shim/config.ts @@ -2,8 +2,8 @@ import { DistributedTracingModes, IConfig, IDisabledExtendedMetrics, IWebInstrum import http = require("http"); import https = require("https"); import azureCoreAuth = require("@azure/core-auth"); +import { ShimJsonConfig } from "./shim-jsonConfig"; import { Logger } from "../shared/logging"; -import constants = require("../declarations/constants"); class config implements IConfig { @@ -61,8 +61,6 @@ class config implements IConfig { public enableAutoWebSnippetInjection: boolean; public correlationId: string; // TODO: Should be private NOTE: This is not noted in the README - private _connectionString: string; - private _endpointBase: string = constants.DEFAULT_BREEZE_ENDPOINT; private _instrumentationKey: string; public _webInstrumentationConnectionString: string; @@ -72,17 +70,12 @@ class config implements IConfig { constructor(setupString?: string) { this.instrumentationKey = setupString; - - this.maxBatchSize = this.maxBatchSize || 250; - this.maxBatchIntervalMs = this.maxBatchIntervalMs || 15000; - this.disableAppInsights = this.disableAppInsights || false; - this.samplingPercentage = this.samplingPercentage || 100; - this.correlationIdRetryIntervalMs = this.correlationIdRetryIntervalMs || 30 * 1000; // this.enableWebInstrumentation = this.enableWebInstrumentation || this.enableAutoWebSnippetInjection || false; this.webInstrumentationConfig = this.webInstrumentationConfig || null; // this.enableAutoWebSnippetInjection = this.enableWebInstrumentation; this.correlationHeaderExcludedDomains = this.correlationHeaderExcludedDomains || + ShimJsonConfig.getInstance().correlationHeaderExcludedDomains || [ "*.core.windows.net", "*.core.chinacloudapi.cn", @@ -139,6 +132,11 @@ class config implements IConfig { * Fifth section has 12 characters */ private static _validateInstrumentationKey(iKey: string): boolean { + if (iKey.startsWith("InstrumentationKey=")) { + const startIndex = iKey.indexOf("InstrumentationKey=") + "InstrumentationKey=".length; + const endIndex = iKey.indexOf(";", startIndex); + iKey = iKey.substring(startIndex, endIndex); + } const UUID_Regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; const regexp = new RegExp(UUID_Regex); return regexp.test(iKey); diff --git a/src/shim/shim-jsonConfig.ts b/src/shim/shim-jsonConfig.ts new file mode 100644 index 000000000..a0aeb4ad1 --- /dev/null +++ b/src/shim/shim-jsonConfig.ts @@ -0,0 +1,179 @@ +import * as fs from "fs"; +import * as path from "path"; +import { Logger } from "../shared/logging/logger"; +import { DistributedTracingModes, IDisabledExtendedMetrics, IJsonConfig, IWebInstrumentationConfig } from "./types"; +import * as http from "http"; +import * as https from "https"; +import * as azureCoreAuth from "@azure/core-auth"; + +const ENV_CONFIGURATION_FILE = "APPLICATIONINSIGHTS_CONFIGURATION_FILE"; +const ENV_CONTENT = "APPLICATIONINSIGHTS_CONFIGURATION_CONTENT"; + +const ENV_connectionString = "APPLICATIONINSIGHTS_CONNECTION_STRING"; +const ENV_azurePrefix = "APPSETTING_"; // Azure adds this prefix to all environment variables +const ENV_instrumentationKey = "APPINSIGHTS_INSTRUMENTATIONKEY"; +const ENV_legacyInstrumentationKey = "APPINSIGHTS_INSTRUMENTATION_KEY" +const ENV_nativeMetricsDisablers = "APPLICATION_INSIGHTS_DISABLE_EXTENDED_METRIC"; +const ENV_nativeMetricsDisableAll = "APPLICATION_INSIGHTS_DISABLE_ALL_EXTENDED_METRICS"; +const ENV_http_proxy = "http_proxy"; +const ENV_https_proxy = "https_proxy"; +const ENV_noDiagnosticChannel = "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"; +const ENV_noStatsbeat = "APPLICATION_INSIGHTS_NO_STATSBEAT"; +const ENV_noHttpAgentKeepAlive = "APPLICATION_INSIGHTS_NO_HTTP_AGENT_KEEP_ALIVE"; +const ENV_noPatchModules = "APPLICATION_INSIGHTS_NO_PATCH_MODULES"; + +export class ShimJsonConfig implements IJsonConfig { + private static _instance: ShimJsonConfig; + + public endpointUrl: string; + public connectionString: string; + public instrumentationKey: string; + public disableAllExtendedMetrics: boolean; + public extendedMetricDisablers: string; + public proxyHttpUrl: string; + public proxyHttpsUrl: string; + public noDiagnosticChannel: boolean; + public disableStatsbeat: boolean; + public noHttpAgentKeepAlive: boolean; + public noPatchModules: string; + public maxBatchSize: number; + public maxBatchIntervalMs: number; + public disableAppInsights: boolean; + public samplingPercentage: number; + public correlationIdRetryIntervalMs: number; + public correlationHeaderExcludedDomains: string[]; + public httpAgent: http.Agent; + public httpsAgent: https.Agent; + public ignoreLegacyHeaders: boolean; + public aadTokenCredential?: azureCoreAuth.TokenCredential; + public enableAutoCollectConsole: boolean; + public enableLoggerErrorToTrace: boolean; + public enableAutoCollectPerformance: boolean; + public enableAutoCollectExternalLoggers: boolean; + public enableAutoCollectPreAggregatedMetrics: boolean; + public enableAutoCollectHeartbeat: boolean; + public enableAutoCollectRequests: boolean; + public enableAutoCollectDependencies: boolean; + public enableAutoDependencyCorrelation: boolean; + public enableAutoCollectIncomingRequestAzureFunctions: boolean; + public enableSendLiveMetrics: boolean; + public enableUseDiskRetryCaching: boolean; + public enableUseAsyncHooks: boolean; + public distributedTracingMode: DistributedTracingModes; + public enableAutoCollectExtendedMetrics: boolean | IDisabledExtendedMetrics; + public enableResendInterval: number; + public enableMaxBytesOnDisk: number; + public enableInternalDebugLogging: boolean; + public enableInternalWarningLogging: boolean; + public quickPulseHost: string; + public enableWebInstrumentation: boolean; + public enableAutoCollectExceptions: boolean; + public webInstrumentationConnectionString?: string; + public webInstrumentationConfig: IWebInstrumentationConfig[]; + public webInstrumentationSrc: string; + public enableAutoWebSnippetInjection?: boolean; + public webSnippetConnectionString?: string; + + public static getInstance() { + if (!ShimJsonConfig._instance) { + ShimJsonConfig._instance = new ShimJsonConfig(); + } + return ShimJsonConfig._instance; + } + + constructor() { + // Load environment variables first + this.connectionString = process.env[ENV_connectionString]; + this.instrumentationKey = process.env[ENV_instrumentationKey] + || process.env[ENV_azurePrefix + ENV_instrumentationKey] + || process.env[ENV_legacyInstrumentationKey] + || process.env[ENV_azurePrefix + ENV_legacyInstrumentationKey]; + this._loadJsonFile(); + if (!this.connectionString && this.instrumentationKey) { + Logger.getInstance().warn("APPINSIGHTS_INSTRUMENTATIONKEY is in path of deprecation, please use APPLICATIONINSIGHTS_CONNECTION_STRING env variable to setup the SDK."); + } + this.disableAllExtendedMetrics = !!process.env[ENV_nativeMetricsDisableAll]; + this.extendedMetricDisablers = process.env[ENV_nativeMetricsDisablers]; + this.proxyHttpUrl = process.env[ENV_http_proxy] ? process.env[ENV_http_proxy] : this.proxyHttpUrl; + this.proxyHttpsUrl = process.env[ENV_https_proxy] ? process.env[ENV_https_proxy] : this.proxyHttpsUrl; + this.noDiagnosticChannel = process.env[ENV_noDiagnosticChannel] ? !!process.env[ENV_noDiagnosticChannel] : this.noDiagnosticChannel; + this.disableStatsbeat = !!process.env[ENV_noStatsbeat]; + this.noHttpAgentKeepAlive = process.env[ENV_noHttpAgentKeepAlive] ? !!process.env[ENV_noHttpAgentKeepAlive] : this.noHttpAgentKeepAlive; + this.noPatchModules = process.env[ENV_noPatchModules] ? process.env[ENV_noPatchModules] : this.noPatchModules || ""; + } + + private _loadJsonFile() { + let jsonString = ""; + const contentJsonConfig = process.env[ENV_CONTENT]; + // JSON string added directly in env variable + if (contentJsonConfig) { + jsonString = contentJsonConfig; + } + // JSON file + else { + const configFileName = "applicationinsights.json"; + const rootPath = path.join(__dirname, "../../../../"); // Root of folder (__dirname = ../dist-esm/src) + let tempDir = path.join(rootPath, configFileName); // default + const configFile = process.env[ENV_CONFIGURATION_FILE]; + if (configFile) { + if (path.isAbsolute(configFile)) { + tempDir = configFile; + } else { + tempDir = path.join(rootPath, configFile); // Relative path to applicationinsights folder + } + } + try { + jsonString = fs.readFileSync(tempDir, "utf8"); + } catch (err) { + Logger.getInstance().info("Failed to read JSON config file: ", err); + } + } + try { + const jsonConfig: IJsonConfig = JSON.parse(jsonString); + this.connectionString = jsonConfig.connectionString; + this.enableAutoCollectExceptions = jsonConfig.enableAutoCollectExceptions; + this.instrumentationKey = jsonConfig.instrumentationKey; + this.endpointUrl = jsonConfig.endpointUrl; + this.samplingPercentage = jsonConfig.samplingPercentage; + this.enableAutoCollectExternalLoggers = jsonConfig.enableAutoCollectExternalLoggers; + this.enableAutoCollectConsole = jsonConfig.enableAutoCollectConsole; + this.enableLoggerErrorToTrace = jsonConfig.enableLoggerErrorToTrace; + this.enableAutoCollectExceptions = jsonConfig.enableAutoCollectExceptions; + this.enableAutoCollectPerformance = jsonConfig.enableAutoCollectPerformance; + this.enableAutoCollectPreAggregatedMetrics = jsonConfig.enableAutoCollectPreAggregatedMetrics; + this.enableAutoDependencyCorrelation = jsonConfig.enableAutoDependencyCorrelation; + this.maxBatchSize = jsonConfig.maxBatchSize; + this.maxBatchIntervalMs = jsonConfig.maxBatchIntervalMs; + this.disableAppInsights = jsonConfig.disableAppInsights; + this.correlationHeaderExcludedDomains = jsonConfig.correlationHeaderExcludedDomains; + this.ignoreLegacyHeaders = jsonConfig.ignoreLegacyHeaders; + this.distributedTracingMode = jsonConfig.distributedTracingMode; + this.enableAutoCollectExtendedMetrics = jsonConfig.enableAutoCollectExtendedMetrics; + this.enableAutoCollectHeartbeat = jsonConfig.enableAutoCollectHeartbeat; + this.enableAutoCollectRequests = jsonConfig.enableAutoCollectRequests; + this.enableAutoCollectDependencies = jsonConfig.enableAutoCollectDependencies; + this.enableAutoCollectIncomingRequestAzureFunctions = jsonConfig.enableAutoCollectIncomingRequestAzureFunctions; + this.enableUseAsyncHooks = jsonConfig.enableUseAsyncHooks; + this.enableUseDiskRetryCaching = jsonConfig.enableUseDiskRetryCaching; + this.enableResendInterval = jsonConfig.enableResendInterval; + this.enableMaxBytesOnDisk = jsonConfig.enableMaxBytesOnDisk; + this.enableInternalDebugLogging = jsonConfig.enableInternalDebugLogging; + this.enableInternalWarningLogging = jsonConfig.enableInternalWarningLogging; + this.enableSendLiveMetrics = jsonConfig.enableSendLiveMetrics; + this.disableAllExtendedMetrics = jsonConfig.disableAllExtendedMetrics; + this.extendedMetricDisablers = jsonConfig.extendedMetricDisablers; + this.noDiagnosticChannel = jsonConfig.noDiagnosticChannel; + this.noPatchModules = jsonConfig.noPatchModules; + this.noHttpAgentKeepAlive = jsonConfig.noHttpAgentKeepAlive; + this.proxyHttpUrl = jsonConfig.proxyHttpUrl; + this.proxyHttpsUrl = jsonConfig.proxyHttpsUrl; + this.webInstrumentationConnectionString = jsonConfig.webInstrumentationConnectionString; + this.webInstrumentationConfig = jsonConfig.webInstrumentationConfig; + this.webInstrumentationSrc = jsonConfig.webInstrumentationSrc; + this.enableAutoWebSnippetInjection = jsonConfig.enableAutoWebSnippetInjection; + this.webSnippetConnectionString = jsonConfig.webSnippetConnectionString; + } catch (err) { + Logger.getInstance().info("Missing or invalid JSON config file: ", err); + } + } +} \ No newline at end of file diff --git a/src/shim/telemetryClient.ts b/src/shim/telemetryClient.ts index b5f0ab533..88f3078d2 100644 --- a/src/shim/telemetryClient.ts +++ b/src/shim/telemetryClient.ts @@ -20,6 +20,7 @@ import { IConfig } from "../shim/types"; import Config = require("./config"); import { dispose, Configuration, _setupCalled } from "./shim-applicationinsights"; import { HttpInstrumentationConfig } from "@opentelemetry/instrumentation-http"; +import { ShimJsonConfig } from "./shim-jsonConfig"; import ConfigHelper = require("../shared/util/configHelper"); /** @@ -70,7 +71,7 @@ export class TelemetryClient { * Parse the config property to set the appropriate values on the ApplicationInsightsOptions * @param input */ - private _parseConfig(input?: ApplicationInsightsOptions) { + private _parseConfig(jsonConfig: ShimJsonConfig, input?: ApplicationInsightsOptions) { // If we have a defined input (in the case that we are initializing from the start method) then we should use that if (input) { this._options = input; @@ -81,13 +82,12 @@ export class TelemetryClient { dispose(); } - if (this.config.instrumentationKey && this.config.endpointUrl) { - this._options.azureMonitorExporterConfig.connectionString = `InstrumentationKey=${this.config.instrumentationKey};IngestionEndpoint=${this.config.endpointUrl}`; + if (this.config.samplingPercentage) { + this._options.samplingRatio = this.config.samplingPercentage / 100; } - this._options.samplingRatio = this.config.samplingPercentage ? (this.config.samplingPercentage / 100) : 1; - this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, http: { ...input?.instrumentationOptions?.http, ignoreOutgoingUrls: this.config.correlationHeaderExcludedDomains, @@ -99,11 +99,7 @@ export class TelemetryClient { } if (typeof(this.config.enableAutoCollectConsole) === "boolean") { - const setting: boolean = this.config.enableAutoCollectConsole; - this._options.logInstrumentations = { - ...this._options.logInstrumentations, - console: { enabled: setting }, - } + ConfigHelper.enableAutoCollectConsole(this._options, this.config.enableAutoCollectConsole); } if (typeof(this.config.enableAutoCollectExceptions) === "boolean") { @@ -123,18 +119,17 @@ export class TelemetryClient { } if (typeof(this.config.enableAutoCollectExternalLoggers) === "boolean") { - this._options.logInstrumentations = { - ...this._options.logInstrumentations, - winston: { enabled: this.config.enableAutoCollectExternalLoggers }, - bunyan: { enabled: this.config.enableAutoCollectExternalLoggers }, - } + ConfigHelper.enableAutoCollectExternalLoggers(this._options, this.config.enableAutoCollectExternalLoggers); } if (typeof(this.config.enableAutoCollectPreAggregatedMetrics) === "boolean") { this._options.enableAutoCollectStandardMetrics = this.config.enableAutoCollectPreAggregatedMetrics; } - if (typeof(this.config.enableAutoCollectHeartbeat) === "boolean") { + if ( + typeof(this.config.enableAutoCollectHeartbeat) === "boolean" || + typeof(jsonConfig.enableAutoCollectHeartbeat) === "boolean" + ) { Configuration.setAutoCollectHeartbeat(this.config.enableAutoCollectHeartbeat); } @@ -154,7 +149,7 @@ export class TelemetryClient { Configuration.setUseDiskRetryCaching(this.config.enableUseDiskRetryCaching); } - if (this.config.enableUseAsyncHooks === false) { + if (this.config.enableUseAsyncHooks === false || jsonConfig.enableUseAsyncHooks === false) { Logger.getInstance().warn("The use of non async hooks is no longer supported."); } @@ -163,12 +158,7 @@ export class TelemetryClient { } if (typeof(this.config.enableAutoCollectExtendedMetrics) === "boolean") { - const setting = this.config.enableAutoCollectExtendedMetrics; - this._options.extendedMetrics = { - [ExtendedMetricType.gc]: setting, - [ExtendedMetricType.heap]: setting, - [ExtendedMetricType.loop]: setting, - } + ConfigHelper.enableAutoCollectExtendedMetrics(this._options, this.config.enableAutoCollectExtendedMetrics); } if (this.config.enableResendInterval) { @@ -180,76 +170,280 @@ export class TelemetryClient { } if (typeof(this.config.enableInternalDebugLogging) === "boolean") { - if (this.config.enableInternalDebugLogging) { - Logger.getInstance().updateLogLevel(DiagLogLevel.DEBUG); - } + Logger.getInstance().updateLogLevel(DiagLogLevel.DEBUG); } if (typeof(this.config.enableInternalWarningLogging) === "boolean") { - if (this.config.enableInternalWarningLogging) { - Logger.getInstance().updateLogLevel(DiagLogLevel.WARN); - } + Logger.getInstance().updateLogLevel(DiagLogLevel.WARN); } - // Disable or enable all extended metrics - if (this.config.disableAllExtendedMetrics === true) { + if ( + this.config.disableAllExtendedMetrics === true || + jsonConfig.disableAllExtendedMetrics === true + ) { for (const type in this._options.extendedMetrics) { this._options.extendedMetrics[type] = false; } this._options.extendedMetrics = { + ...this._options.extendedMetrics, [ExtendedMetricType.gc]: false, [ExtendedMetricType.heap]: false, [ExtendedMetricType.loop]: false, }; } - if (typeof(this.config.disableStatsbeat) === "boolean") { + if (typeof(this.config.disableStatsbeat || jsonConfig.disableStatsbeat) === "boolean") { Logger.getInstance().warn("The disableStatsbeat configuration option is deprecated."); } if (this.config.extendedMetricDisablers) { - const disabler = this.config.extendedMetricDisablers; - this._options.extendedMetrics[disabler] = false; + ConfigHelper.setExtendedMetricDisablers(this._options, this.config.extendedMetricDisablers); } - if (this.config.ignoreLegacyHeaders === false) { + if (this.config.ignoreLegacyHeaders === false || jsonConfig.ignoreLegacyHeaders === false) { Logger.getInstance().warn("LegacyHeaders are not supported by the shim."); } if (this.config.proxyHttpUrl || this.config.proxyHttpsUrl) { - const proxyUrl = new URL(this.config.proxyHttpsUrl || this.config.proxyHttpUrl); - this._options.azureMonitorExporterConfig.proxyOptions = { - host: proxyUrl.hostname, - port: Number(proxyUrl.port), - } + ConfigHelper.setProxyUrl(this._options, this.config.proxyHttpsUrl || this.config.proxyHttpUrl); } - if (this.config.maxBatchSize) { + if (this.config.maxBatchSize || jsonConfig.maxBatchSize) { Logger.getInstance().warn("The maxBatchSize configuration option is not supported by the shim."); } if (this.config.maxBatchIntervalMs) { - this._options.otlpTraceExporterConfig = { ...this._options.otlpTraceExporterConfig, timeoutMillis: this.config.maxBatchIntervalMs }; - this._options.otlpMetricExporterConfig = { ...this._options.otlpMetricExporterConfig, timeoutMillis: this.config.maxBatchIntervalMs }; - this._options.otlpLogExporterConfig = { ...this._options.otlpLogExporterConfig, timeoutMillis: this.config.maxBatchIntervalMs }; + ConfigHelper.setMaxBatchIntervalMs(this._options, this.config.maxBatchIntervalMs); } - if (this.config.correlationIdRetryIntervalMs) { + if (this.config.correlationIdRetryIntervalMs || jsonConfig.correlationIdRetryIntervalMs) { Logger.getInstance().warn("The correlationIdRetryIntervalMs configuration option is not supported by the shim."); } - if (this.config.enableLoggerErrorToTrace) { + if (this.config.enableLoggerErrorToTrace || jsonConfig.enableLoggerErrorToTrace) { Logger.getInstance().warn("The enableLoggerErrorToTrace configuration option is not supported by the shim."); } - if (this.config.httpAgent || this.config.httpsAgent) { + if (this.config.httpAgent || this.config.httpsAgent || jsonConfig.httpAgent || jsonConfig.httpsAgent) { Logger.getInstance().warn("The httpAgent and httpsAgent configuration options are not supported by the shim."); } - if (this.config.enableWebInstrumentation || this.config.webInstrumentationConfig || this.config.webInstrumentationSrc || this.config.webInstrumentationConnectionString) { + if ( + this.config.enableWebInstrumentation || this.config.webInstrumentationConfig || this.config.webInstrumentationSrc || this.config.webInstrumentationConnectionString || + jsonConfig.enableWebInstrumentation || jsonConfig.webInstrumentationConfig || jsonConfig.webInstrumentationSrc || jsonConfig.webInstrumentationConnectionString + ) { Logger.getInstance().warn("The webInstrumentation configuration options are not supported by the shim."); } } + + /** + * Parse the JSON config file to set the appropriate values on the ApplicationInsightsOptions + */ + private _parseJson(jsonConfig: ShimJsonConfig) { + const resendInterval: number | undefined = jsonConfig.enableResendInterval; + + if (jsonConfig.instrumentationKey || jsonConfig.endpointUrl) { + Logger.getInstance().warn("Please pass a connection string to the setup method to initialize the SDK client."); + } + + if (jsonConfig.connectionString) { + this._options.azureMonitorExporterConfig.connectionString = jsonConfig.connectionString; + } + + if (jsonConfig.disableAppInsights) { + dispose(); + } + + if (jsonConfig.samplingPercentage) { + this._options.samplingRatio = jsonConfig.samplingPercentage / 100; + } + + this._options.instrumentationOptions = { + http: { + ...this._options?.instrumentationOptions?.http, + ignoreOutgoingUrls: jsonConfig.correlationHeaderExcludedDomains, + } as HttpInstrumentationConfig, + } + + if (jsonConfig.distributedTracingMode) { + Configuration.setDistributedTracingMode(jsonConfig.distributedTracingMode); + } + + if (jsonConfig.enableAutoCollectExternalLoggers) { + ConfigHelper.enableAutoCollectExternalLoggers(this._options, jsonConfig.enableAutoCollectExternalLoggers); + } + + if (jsonConfig.enableAutoCollectConsole) { + ConfigHelper.enableAutoCollectConsole(this._options, jsonConfig.enableAutoCollectConsole); + } + + if (jsonConfig.enableAutoCollectExceptions) { + this._options.enableAutoCollectExceptions = jsonConfig.enableAutoCollectExceptions; + } + + if (jsonConfig.enableAutoCollectPerformance) { + ConfigHelper.setAutoCollectPerformance(this._options, jsonConfig.enableAutoCollectPerformance); + } + + if (typeof(jsonConfig.enableAutoCollectExtendedMetrics) === "boolean") { + ConfigHelper.enableAutoCollectExtendedMetrics(this._options, jsonConfig.enableAutoCollectExtendedMetrics); + } + + if (jsonConfig.enableAutoCollectRequests) { + ConfigHelper.setAutoCollectRequests(this._options, jsonConfig.enableAutoCollectRequests); + } + + if (jsonConfig.enableAutoCollectDependencies) { + ConfigHelper.setAutoCollectDependencies(this._options, jsonConfig.enableAutoCollectDependencies); + } + + if (typeof(jsonConfig.enableAutoDependencyCorrelation) === "boolean") { + Configuration.setAutoDependencyCorrelation(jsonConfig.enableAutoDependencyCorrelation); + } + + if (jsonConfig.maxBatchIntervalMs) { + ConfigHelper.setMaxBatchIntervalMs(this._options, jsonConfig.maxBatchIntervalMs); + } + + if (jsonConfig.proxyHttpUrl || jsonConfig.proxyHttpsUrl) { + ConfigHelper.setProxyUrl(this._options, jsonConfig.proxyHttpsUrl || jsonConfig.proxyHttpUrl); + } + + if (jsonConfig.enableAutoCollectIncomingRequestAzureFunctions) { + Configuration.setAutoCollectIncomingRequestAzureFunctions(jsonConfig.enableAutoCollectIncomingRequestAzureFunctions); + } + + if (jsonConfig.enableUseDiskRetryCaching) { + Configuration.setUseDiskRetryCaching(jsonConfig.enableUseDiskRetryCaching); + } + + if (jsonConfig.enableResendInterval) { + Configuration.setUseDiskRetryCaching(true, jsonConfig.enableResendInterval); + } + + if (jsonConfig.enableMaxBytesOnDisk) { + Configuration.setUseDiskRetryCaching(true, resendInterval, jsonConfig.enableMaxBytesOnDisk); + } + + if (jsonConfig.enableInternalDebugLogging) { + Logger.getInstance().updateLogLevel(DiagLogLevel.DEBUG); + } + + if (jsonConfig.enableInternalWarningLogging) { + Logger.getInstance().updateLogLevel(DiagLogLevel.WARN); + } + + if (jsonConfig.enableSendLiveMetrics) { + Configuration.setSendLiveMetrics(jsonConfig.enableSendLiveMetrics); + } + + if (jsonConfig.extendedMetricDisablers) { + ConfigHelper.setExtendedMetricDisablers(this._options, jsonConfig.extendedMetricDisablers); + } + + if (jsonConfig.noDiagnosticChannel) { + this._options.instrumentationOptions = { + azureSdk: { enabled: false }, + http: { enabled: false }, + mongoDb: { enabled: false }, + mySql: { enabled: false }, + postgreSql: { enabled: false }, + redis: { enabled: false }, + redis4: { enabled: false }, + } + this._options.logInstrumentations = { + console: { enabled: false }, + winston: { enabled: false }, + bunyan: { enabled: false }, + } + } + + if (jsonConfig.noPatchModules) { + const modules: string[] = jsonConfig.noPatchModules.split(","); + for (const module of modules) { + switch (module) { + case "console": + this._options.logInstrumentations = { + ...this._options.logInstrumentations, + console: { enabled: false }, + } + break; + case "winston": + this._options.logInstrumentations = { + ...this._options.logInstrumentations, + winston: { enabled: false }, + } + break; + case "bunyan": + this._options.logInstrumentations = { + ...this._options.logInstrumentations, + bunyan: { enabled: false }, + } + break; + case "azuresdk": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + azureSdk: { enabled: false }, + } + break; + case "http": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + http: { enabled: false }, + } + break; + case "mongodb": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + mongoDb: { enabled: false }, + } + break; + case "mysql": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + mySql: { enabled: false }, + } + break; + case "postgresql": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + postgreSql: { enabled: false }, + } + break; + case "redis": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + redis: { enabled: false }, + } + break; + case "redis4": + this._options.instrumentationOptions = { + ...this._options.instrumentationOptions, + redis4: { enabled: false }, + } + break; + default: + Logger.getInstance().warn(`Unknown module ${module} passed to noPatchModules.`); + break; + } + } + } + + if (jsonConfig.noHttpAgentKeepAlive === true) { + this._options.otlpTraceExporterConfig = { + ...this._options.otlpTraceExporterConfig, + enabled: false + }; + this._options.otlpMetricExporterConfig = { + ...this._options.otlpMetricExporterConfig, + enabled: false + }; + this._options.otlpLogExporterConfig = { + ...this._options.otlpLogExporterConfig, + enabled: false + }; + } + } /** * Starts automatic collection of telemetry. Prior to calling start no telemetry will be collected @@ -258,7 +452,10 @@ export class TelemetryClient { public start(input?: ApplicationInsightsOptions) { // Only parse config if we're running the shim if (_setupCalled) { - this._parseConfig(input); + const jsonConfig = ShimJsonConfig.getInstance(); + // Create the internalConfig based on the JSONConfig, and override with the client.config if defined + this._parseJson(jsonConfig); + this._parseConfig(jsonConfig, input); } this._internalConfig = new InternalConfig(this._options); this._client = new AzureMonitorOpenTelemetryClient(this._options); diff --git a/test/unitTests/shim/config.json b/test/unitTests/shim/config.json new file mode 100644 index 000000000..82c150163 --- /dev/null +++ b/test/unitTests/shim/config.json @@ -0,0 +1,29 @@ +{ + "connectionString": "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/", + "endpointUrl": "testEndpointUrl", + "disableAllExtendedMetrics": false, + "disableAppInsights": false, + "samplingPercentage": 30, + "correlationHeaderExcludedDomains": [ + "bing.com" + ], + "proxyHttpsUrl": "https://test:3000", + "enableAutoCollectExternalLoggers": true, + "enableAutoCollectConsole": true, + "enableAutoCollectExceptions": true, + "enableAutoCollectPerformance": true, + "enableAutoCollectExtendedMetrics": true, + "enableAutoCollectPreAggregatedMetrics": true, + "enableAutoCollectRequests": true, + "enableAutoCollectDependencies": true, + "enableAutoDependencyCorrelation": true, + "enableAutoCollectIncomingRequestAzureFunctions": false, + "noHttpAgentKeepAlive": false, + "distributedTracingMode": 0, + "enableInternalDebugLogging": false, + "enableInternalWarningLogging": false, + "extendedMetricDisablers": "gc,heap", + "noDiagnosticChannel": false, + "noPatchModules": "redis,azuresdk", + "maxBatchIntervalMs": 1000 +} \ No newline at end of file diff --git a/test/unitTests/shim/config.tests.ts b/test/unitTests/shim/config.tests.ts index b37e675d9..797ff0938 100644 --- a/test/unitTests/shim/config.tests.ts +++ b/test/unitTests/shim/config.tests.ts @@ -32,13 +32,10 @@ describe("shim/configuration/config", () => { beforeEach(() => { originalEnv = process.env; - process.env["APPLICATION_INSIGHTS_SHIM_CONFIGURATION"] = "true"; sandbox = sinon.createSandbox(); }); afterEach(() => { - process.env = originalEnv; - delete process.env.APPLICATION_INSIGHTS_SHIM_CONFIGURATION; sandbox.restore(); }) diff --git a/test/unitTests/shim/jsonConfig.tests.ts b/test/unitTests/shim/jsonConfig.tests.ts new file mode 100644 index 000000000..0025ed4db --- /dev/null +++ b/test/unitTests/shim/jsonConfig.tests.ts @@ -0,0 +1,147 @@ +import assert = require("assert"); +import path = require("path"); +import { ShimJsonConfig } from "../../../src/shim/shim-jsonConfig"; +import { HttpInstrumentationConfig } from "@opentelemetry/instrumentation-http"; +const applicationInsights = require('../../../applicationinsights'); + +describe("Json Config", () => { + const connectionString = "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"; + + beforeEach(() => { + ShimJsonConfig["_instance"] = undefined; + applicationInsights.dispose(); + }); + + afterEach(() => { + ShimJsonConfig["_instance"] = undefined; + applicationInsights.dispose(); + }); + + describe("configuration values", () => { + it("should take configurations from the JSON config file", () => { + const cutstomConfigJsonPath = path.resolve(__dirname, "../../../../test/unitTests/shim/config.json"); + process.env["APPLICATIONINSIGHTS_CONFIGURATION_FILE"] = cutstomConfigJsonPath; + + applicationInsights.setup(connectionString); + applicationInsights.start(); + + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.connectionString, "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.proxyOptions.host, "test"); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.proxyOptions.port, 3000); + assert.equal(applicationInsights["defaultClient"]["_options"].samplingRatio, 0.3, JSON.stringify(ShimJsonConfig["_instance"])); + const ignoreOutgoingUrls = applicationInsights["defaultClient"]["_options"].instrumentationOptions.http as HttpInstrumentationConfig; + assert.equal(ignoreOutgoingUrls.ignoreOutgoingUrls, "bing.com"); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].logInstrumentations), JSON.stringify({ winston: { enabled: true }, bunyan: { enabled: true }, console: { enabled: true } })); + assert.equal(applicationInsights["defaultClient"]["_options"].enableAutoCollectExceptions, true); + assert.equal(applicationInsights["defaultClient"]["_options"].enableAutoCollectPerformance, true); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].extendedMetrics), JSON.stringify({ gc: true, heap: true, loop: true })); + assert.equal(applicationInsights["defaultClient"]["_options"].instrumentationOptions.http.hasOwnProperty("ignoreIncomingRequestHook"), true); + assert.equal(applicationInsights["defaultClient"]["_options"].instrumentationOptions.http.hasOwnProperty("ignoreOutgoingRequestHook"), true); + assert.equal( + JSON.stringify(applicationInsights["defaultClient"]["_options"].otlpTraceExporterConfig), + JSON.stringify({timeoutMillis: 1000}) + ); + assert.equal( + JSON.stringify(applicationInsights["defaultClient"]["_options"].otlpMetricExporterConfig), + JSON.stringify({timeoutMillis: 1000}) + ); + assert.equal( + JSON.stringify(applicationInsights["defaultClient"]["_options"].otlpLogExporterConfig), + JSON.stringify({timeoutMillis: 1000}) + ); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.redis), JSON.stringify({ enabled: false })); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.azureSdk), JSON.stringify({ enabled: false })); + + delete process.env.APPLICATIONINSIGHTS_CONFIGURATION_FILE; + }); + + it("should take configurations from environment variables", () => { + process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] = connectionString; + process.env["APPLICATION_INSIGHTS_DISABLE_EXTENDED_METRIC"] = "gc"; + process.env["APPLICATION_INSIGHTS_NO_PATCH_MODULES"] = "azuresdk"; + process.env["APPLICATION_INSIGHTS_DISABLE_ALL_EXTENDED_METRICS"] = "true"; + process.env["APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"] = "true"; + process.env["APPLICATION_INSIGHTS_NO_HTTP_AGENT_KEEP_ALIVE"] = "true"; + process.env["https_proxy"] = "https://testproxy:3000"; + + applicationInsights.setup(); + applicationInsights.start(); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.connectionString, connectionString); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].extendedMetrics), JSON.stringify({ gc: false, heap: false, loop: false }, applicationInsights["defaultClient"]["_options"].extendedMetrics)); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.redis), JSON.stringify({ enabled: false })); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.redis4), JSON.stringify({ enabled: false })); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.postgreSql), JSON.stringify({ enabled: false })); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.proxyOptions.host, "testproxy"); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.proxyOptions.port, 3000); + + delete process.env.APPLICATIONINSIGHTS_CONNECTION_STRING; + delete process.env.APPLICATION_INSIGHTS_DISABLE_EXTENDED_METRIC; + delete process.env.APPLICATION_INSIGHTS_NO_PATCH_MODULES; + delete process.env.APPLICATION_INSIGHTS_DISABLE_ALL_EXTENDED_METRICS; + delete process.env.APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL; + delete process.env.APPLICATION_INSIGHTS_NO_HTTP_AGENT_KEEP_ALIVE; + delete process.env.https_proxy; + }); + + it("should take configuration from JSON string", () => { + const inputJson = { + "connectionString": "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/", + "endpointUrl": "testEndpointUrl", + "disableAllExtendedMetrics": false, + "disableAppInsights": false, + "samplingPercentage": 60, + "correlationHeaderExcludedDomains": ["bing.com"], + "proxyHttpsUrl": "https://test:3000", + "enableAutoCollectExternalLoggers": true, + "enableAutoCollectConsole": true, + "enableAutoCollectExceptions": true, + "enableAutoCollectPerformance": true, + "enableAutoCollectExtendedMetrics": true, + "enableAutoCollectPreAggregatedMetrics": true, + "enableAutoCollectRequests": true, + "enableAutoCollectDependencies": true, + "enableAutoDependencyCorrelation": true, + "enableAutoCollectIncomingRequestAzureFunctions": false, + "noHttpAgentKeepAlive": true, + "distributedTracingMode": 0, + "enableInternalDebugLogging": false, + "enableInternalWarningLogging": false, + "extendedMetricDisablers": "gc,heap", + "noDiagnosticChannel": false, + "noPatchModules": "redis,azuresdk", + "maxBatchIntervalMs": 1500 + }; + process.env["APPLICATIONINSIGHTS_CONFIGURATION_CONTENT"] = JSON.stringify(inputJson); + applicationInsights.setup(); + applicationInsights.start(); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.connectionString, "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.proxyOptions.host, "test"); + assert.equal(applicationInsights["defaultClient"]["_options"].azureMonitorExporterConfig.proxyOptions.port, 3000); + assert.equal(applicationInsights["defaultClient"]["_options"].samplingRatio, 0.6, JSON.stringify(ShimJsonConfig["_instance"])); + const ignoreOutgoingUrls = applicationInsights["defaultClient"]["_options"].instrumentationOptions.http as HttpInstrumentationConfig; + assert.equal(ignoreOutgoingUrls.ignoreOutgoingUrls, "bing.com"); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].logInstrumentations), JSON.stringify({ console: { enabled: true }, winston: { enabled: true }, bunyan: { enabled: true } })); + assert.equal(applicationInsights["defaultClient"]["_options"].enableAutoCollectExceptions, true); + assert.equal(applicationInsights["defaultClient"]["_options"].enableAutoCollectPerformance, true); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].extendedMetrics), JSON.stringify({ gc: true, heap: true, loop: true })); + assert.equal(applicationInsights["defaultClient"]["_options"].instrumentationOptions.http.hasOwnProperty("ignoreIncomingRequestHook"), true); + assert.equal(applicationInsights["defaultClient"]["_options"].instrumentationOptions.http.hasOwnProperty("ignoreOutgoingRequestHook"), true); + assert.equal( + JSON.stringify(applicationInsights["defaultClient"]["_options"].otlpTraceExporterConfig), + JSON.stringify({ timeoutMillis: 1500, enabled: false }) + ); + assert.equal( + JSON.stringify(applicationInsights["defaultClient"]["_options"].otlpMetricExporterConfig), + JSON.stringify({ timeoutMillis: 1500, enabled: false }) + ); + assert.equal( + JSON.stringify(applicationInsights["defaultClient"]["_options"].otlpLogExporterConfig), + JSON.stringify({ timeoutMillis: 1500, enabled: false }) + ); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.redis), JSON.stringify({ enabled: false })); + assert.equal(JSON.stringify(applicationInsights["defaultClient"]["_options"].instrumentationOptions.azureSdk), JSON.stringify({ enabled: false })); + + delete process.env.APPLICATIONINSIGHTS_CONFIGURATION_CONTENT; + }); + }); +});