From a8d2d7e8a17b536ee50ab93b4f4c2f701f3b9729 Mon Sep 17 00:00:00 2001 From: Hector Date: Tue, 26 Sep 2023 16:16:28 -0700 Subject: [PATCH] Revert "Fix issue with live metrics initialization" This reverts commit c018ab8458b19731e9d55e63f35d2425ae376978. --- Tests/applicationInsights.tests.ts | 5 +---- applicationinsights.ts | 12 +++--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Tests/applicationInsights.tests.ts b/Tests/applicationInsights.tests.ts index be0a69b4c..7cd5cdd8c 100644 --- a/Tests/applicationInsights.tests.ts +++ b/Tests/applicationInsights.tests.ts @@ -77,10 +77,7 @@ describe("ApplicationInsights", () => { WebSnippet.INSTANCE= undefined; }); - afterEach(() => { - AppInsights.defaultClient = undefined; - AppInsights.liveMetricsClient = undefined; - }); + afterEach(() => AppInsights.defaultClient = undefined); it("should warn if start is called before setup", () => { var warnStub = sandbox.stub(console, "warn"); diff --git a/applicationinsights.ts b/applicationinsights.ts index cec074c88..2aa133cfe 100644 --- a/applicationinsights.ts +++ b/applicationinsights.ts @@ -120,7 +120,7 @@ function _setDefaultConfig() { defaultClient.config.enableAutoDependencyCorrelation = true; } if (defaultClient.config.enableSendLiveMetrics == undefined) { - defaultClient.config.enableSendLiveMetrics = false; + defaultClient.config.enableSendLiveMetrics = true; } if (defaultClient.config.enableAutoCollectExtendedMetrics == undefined) { defaultClient.config.enableAutoCollectExtendedMetrics = true; @@ -154,14 +154,7 @@ export function start() { _serverRequests.enable(defaultClient.config.enableAutoCollectRequests); _clientRequests.enable(defaultClient.config.enableAutoCollectDependencies); _webSnippet.enable(defaultClient.config.enableWebInstrumentation, defaultClient.config.webInstrumentationConnectionString); - if (defaultClient.config.enableSendLiveMetrics) { - if (!liveMetricsClient) { - // No qps client exists. Create one and prepare it to be enabled at .start() - liveMetricsClient = new QuickPulseClient(defaultClient.config, defaultClient.context, defaultClient.getAuthorizationHandler); - _performanceLiveMetrics = new AutoCollectPerformance(liveMetricsClient as any, 1000, true); - liveMetricsClient.addCollector(_performanceLiveMetrics); - defaultClient.quickPulseClient = liveMetricsClient; // Need this so we can forward all manual tracks to live metrics via PerformanceMetricsTelemetryProcessor - } + if (liveMetricsClient && defaultClient.config.enableSendLiveMetrics) { liveMetricsClient.enable(defaultClient.config.enableSendLiveMetrics); } _azureFunctions.enable(defaultClient.config.enableAutoCollectIncomingRequestAzureFunctions); @@ -512,6 +505,7 @@ export function dispose() { } if (liveMetricsClient) { liveMetricsClient.enable(false); + defaultClient.config.enableSendLiveMetrics = false; liveMetricsClient = undefined; } if (_azureFunctions) {