Skip to content

Commit

Permalink
Add App Map to App service/function view support (#1868)
Browse files Browse the repository at this point in the history
* working code

* add ostype

* address comments and fix smoke test
  • Loading branch information
kryalama authored Sep 2, 2021
1 parent 18d5a0d commit bad69c3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -86,6 +88,7 @@ public Boolean call() {
hasSetValues = true;
break;
case OS_VERSION:
case OS_TYPE:
provider.addHeartBeatProperty(fieldName, getOsVersion(), true);
hasSetValues = true;
break;
Expand Down Expand Up @@ -119,6 +122,7 @@ private static void initializeDefaultFields(Set<String> 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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<>();
Expand All @@ -76,28 +83,52 @@ 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);
hasSetValues = true;
break;
case WEBSITE_HOSTNAME:
String webSiteHostName = getWebsiteHostName();
if (webSiteHostName == null) {
if (Strings.isNullOrEmpty(webSiteHostName)) {
break;
}
provider.addHeartBeatProperty(fieldName, webSiteHostName, true);
hasSetValues = true;
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;
Expand All @@ -118,6 +149,9 @@ private static void initializeDefaultFields(Set<String> 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. */
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Envelope> getMetricPredicate(String name) {
Expand Down

0 comments on commit bad69c3

Please sign in to comment.