From bad69c39bec486d92e0d8228ac38480800bd7dd4 Mon Sep 17 00:00:00 2001 From: kryalama <66494519+kryalama@users.noreply.github.com> Date: Thu, 2 Sep 2021 16:59:54 -0700 Subject: [PATCH] Add App Map to App service/function view support (#1868) * working code * add ostype * address comments and fix smoke test --- .../DefaultHeartBeatPropertyProvider.java | 4 ++ .../heartbeat/WebAppsHeartbeatProvider.java | 55 ++++++++++++++++++- .../smoketest/HeartBeatTest.java | 3 +- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/DefaultHeartBeatPropertyProvider.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/DefaultHeartBeatPropertyProvider.java index 5cd0335eba0..ac31728aca2 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/DefaultHeartBeatPropertyProvider.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/DefaultHeartBeatPropertyProvider.java @@ -60,6 +60,8 @@ public class DefaultHeartBeatPropertyProvider implements HeartBeatPayloadProvide private static final String PROCESS_SESSION_ID = "processSessionId"; + private static final String OS_TYPE = "osType"; + public DefaultHeartBeatPropertyProvider() { defaultFields = new HashSet<>(); initializeDefaultFields(defaultFields); @@ -86,6 +88,7 @@ public Boolean call() { hasSetValues = true; break; case OS_VERSION: + case OS_TYPE: provider.addHeartBeatProperty(fieldName, getOsVersion(), true); hasSetValues = true; break; @@ -119,6 +122,7 @@ private static void initializeDefaultFields(Set defaultFields) { defaultFields.add(SDK_VERSION); defaultFields.add(OS_VERSION); defaultFields.add(PROCESS_SESSION_ID); + defaultFields.add(OS_TYPE); } /** Returns the JDK version being used by the application. */ diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/WebAppsHeartbeatProvider.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/WebAppsHeartbeatProvider.java index dcd6cb64234..39eeff4c716 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/WebAppsHeartbeatProvider.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/heartbeat/WebAppsHeartbeatProvider.java @@ -21,6 +21,7 @@ package com.microsoft.applicationinsights.agent.internal.heartbeat; +import com.microsoft.applicationinsights.agent.internal.common.Strings; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -52,6 +53,12 @@ public class WebAppsHeartbeatProvider implements HeartBeatPayloadProviderInterfa private static final String WEBSITE_HOME_STAMPNAME = "appSrv_wsStamp"; + private static final String WEBSITE_OWNER_NAME = "appSrv_wsOwner"; + + private static final String WEBSITE_RESOURCE_GROUP = "appSrv_ResourceGroup"; + // Only populated in Azure functions + private static final String WEBSITE_SLOT_NAME = "appSrv_SlotName"; + /** Constructor that initializes fields and load environment variables. */ public WebAppsHeartbeatProvider() { defaultFields = new HashSet<>(); @@ -76,7 +83,7 @@ public Boolean call() { switch (fieldName) { case WEBSITE_SITE_NAME: String webSiteName = getWebsiteSiteName(); - if (webSiteName == null) { + if (Strings.isNullOrEmpty(webSiteName)) { break; } provider.addHeartBeatProperty(fieldName, webSiteName, true); @@ -84,7 +91,7 @@ public Boolean call() { break; case WEBSITE_HOSTNAME: String webSiteHostName = getWebsiteHostName(); - if (webSiteHostName == null) { + if (Strings.isNullOrEmpty(webSiteHostName)) { break; } provider.addHeartBeatProperty(fieldName, webSiteHostName, true); @@ -92,12 +99,36 @@ public Boolean call() { break; case WEBSITE_HOME_STAMPNAME: String websiteHomeStampName = getWebsiteHomeStampName(); - if (websiteHomeStampName == null) { + if (Strings.isNullOrEmpty(websiteHomeStampName)) { break; } provider.addHeartBeatProperty(fieldName, websiteHomeStampName, true); hasSetValues = true; break; + case WEBSITE_OWNER_NAME: + String websiteOwnerName = getWebsiteOwnerName(); + if (Strings.isNullOrEmpty(websiteOwnerName)) { + break; + } + provider.addHeartBeatProperty(fieldName, websiteOwnerName, true); + hasSetValues = true; + break; + case WEBSITE_RESOURCE_GROUP: + String websiteResourceGroup = getWebsiteResourceGroup(); + if (Strings.isNullOrEmpty(websiteResourceGroup)) { + break; + } + provider.addHeartBeatProperty(fieldName, websiteResourceGroup, true); + hasSetValues = true; + break; + case WEBSITE_SLOT_NAME: + String websiteSlotName = getWebsiteSlotName(); + if (Strings.isNullOrEmpty(websiteSlotName)) { + break; + } + provider.addHeartBeatProperty(fieldName, websiteSlotName, true); + hasSetValues = true; + break; default: logger.trace("Unknown web apps property encountered"); break; @@ -118,6 +149,9 @@ private static void initializeDefaultFields(Set defaultFields) { defaultFields.add(WEBSITE_SITE_NAME); defaultFields.add(WEBSITE_HOSTNAME); defaultFields.add(WEBSITE_HOME_STAMPNAME); + defaultFields.add(WEBSITE_OWNER_NAME); + defaultFields.add(WEBSITE_RESOURCE_GROUP); + defaultFields.add(WEBSITE_SLOT_NAME); } /** Returns the name of the website by reading environment variable. */ @@ -135,6 +169,21 @@ private String getWebsiteHomeStampName() { return environmentMap.get("WEBSITE_HOME_STAMPNAME"); } + /** Returns the website owner name by reading environment variable. */ + private String getWebsiteOwnerName() { + return environmentMap.get("WEBSITE_OWNER_NAME"); + } + + /** Returns the website resource group by reading environment variable. */ + private String getWebsiteResourceGroup() { + return environmentMap.get("WEBSITE_RESOURCE_GROUP"); + } + + /** Returns the website slot name by reading environment variable. */ + private String getWebsiteSlotName() { + return environmentMap.get("WEBSITE_SLOT_NAME"); + } + /** * This method updates the environment variable at every call to add the payload, to cover hotswap * scenarios. diff --git a/test/smoke/testApps/HeartBeat/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HeartBeatTest.java b/test/smoke/testApps/HeartBeat/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HeartBeatTest.java index 3840d953d45..376ec35b84c 100644 --- a/test/smoke/testApps/HeartBeat/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HeartBeatTest.java +++ b/test/smoke/testApps/HeartBeat/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HeartBeatTest.java @@ -48,7 +48,8 @@ public void testHeartBeat() throws Exception { assertNotNull(data.getProperties().get("sdkVersion")); assertNotNull(data.getProperties().get("osVersion")); assertNotNull(data.getProperties().get("processSessionId")); - assertEquals(4, data.getProperties().size()); + assertNotNull(data.getProperties().get("osType")); + assertEquals(5, data.getProperties().size()); } private static Predicate getMetricPredicate(String name) {