From 3978eb2a23d8a64b1c0c9d046d546d9b5fd25734 Mon Sep 17 00:00:00 2001
From: Hanxiao Liu <hanli@microsoft.com>
Date: Wed, 4 Nov 2020 09:50:03 +0800
Subject: [PATCH] Register service provider for insights before get insights
 client

---
 .../microsoft/azuretools/sdkmanage/AzureManagerBase.java  | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Utils/azuretools-core/src/com/microsoft/azuretools/sdkmanage/AzureManagerBase.java b/Utils/azuretools-core/src/com/microsoft/azuretools/sdkmanage/AzureManagerBase.java
index 344c1465a2..1c1d107932 100644
--- a/Utils/azuretools-core/src/com/microsoft/azuretools/sdkmanage/AzureManagerBase.java
+++ b/Utils/azuretools-core/src/com/microsoft/azuretools/sdkmanage/AzureManagerBase.java
@@ -64,6 +64,7 @@ public abstract class AzureManagerBase implements AzureManager {
     private static final String GLOBAL_SCM_SUFFIX = ".scm.azurewebsites.net";
 
     private static final Logger LOGGER = Logger.getLogger(AzureManagerBase.class.getName());
+    private static final String MICROSOFT_INSIGHTS_NAMESPACE = "microsoft.insights";
 
     protected Map<String, Azure> sidToAzureMap = new ConcurrentHashMap<>();
     protected Map<String, AppPlatformManager> sidToAzureSpringCloudManagerMap = new ConcurrentHashMap<>();
@@ -171,6 +172,13 @@ public InsightsManager getInsightsManager(String sid) throws IOException {
             return null;
         }
         return sidToInsightsManagerMap.computeIfAbsent(sid, s -> {
+            try {
+                // Register insights namespace first
+                final Azure azure = getAzure(sid);
+                azure.providers().register(MICROSOFT_INSIGHTS_NAMESPACE);
+            } catch (IOException e) {
+                // swallow exception while get azure client
+            }
             String tid = this.subscriptionManager.getSubscriptionTenant(sid);
             return authApplicationInsights(sid, tid);
         });