microsoft / ApplicationInsights-Java

Application Insights for Java
http://aka.ms/application-insights
Other
297 stars 199 forks source link

cloud_RoleName blank on azure app insights portal when set in applicationinsights.json under 3.0.1 #1443

Closed petergphillips closed 3 years ago

petergphillips commented 3 years ago

Expected behavior

Setting the role.name in applicationinsights.json should set the cloud_RoleName in application insights portal. This was working in 3.0.1-BETA.2, but stopped working when we upgraded to 3.0.1. It looks like it was caused by a bug introduced in the fix for https://github.com/microsoft/ApplicationInsights-Java/issues/1425, specifically in https://github.com/microsoft/ApplicationInsights-Java/blob/master/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/configuration/ConfigurationBuilder.java#L196-L200 line 198 should set the instance rather than the name:

            config.role.instance = getEnv(WEBSITE_INSTANCE_ID);

Actual behavior

The cloud_RoleName field is blank in application insights

To Reproduce

In applicationinsights.json set the role name:

  "role": {
    "name": "my-application"
  },

Start the application, make a request to it and wait for the request to appear in app insights:

requests
| where cloud_RoleInstance == "my-pc"
| project timestamp, cloud_RoleName

The cloud_RoleName is then blank under 3.0.1.

Switching to the 3.0.1-BETA.2 agent and running the same test then correctly displays the cloud_RoleName.

Specifying an environment variable of APPLICATIONINSIGHTS_ROLE_NAME as documented in https://github.com/microsoft/ApplicationInsights-Java/issues/1425 also then correctly displays the cloud_RoleName.

Sample Application

Project to replicate the issue is https://github.com/ministryofjustice/prison-estate.git. Need Java 11. Replace with your key for app insights.

Demonstrating working under agent 3.0.1-BETA.2.

git checkout pgp-DT-1482-insights-v3
./gradlew clean assemble && cp applicationinsights.json build/libs
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=<your instrumentation key> java -javaagent:build/libs/applicationinsights-agent-3.0.1-BETA.2.jar -Dspring.profiles.active=dev -jar build/libs/prison-estate-*.jar
curl http://localhost:8080/prisons/id/MDI

Similarly not working under 3.0.1:

git checkout pgp-DT-1442-insights-v3.0.1
./gradlew clean assemble && cp applicationinsights.json build/libs
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=<your instrumentation key> java -javaagent:build/libs/applicationinsights-agent-3.0.1.jar -Dspring.profiles.active=dev -jar build/libs/prison-estate-*.jar
curl http://localhost:8080/prisons/id/MDI

In app insights

requests
| project cloud_RoleName

should then show the role name, but it is only populated for the 3.0.1-BETA.2 requests.

System information

Please provide the following information:

petergphillips commented 3 years ago

Duplicate of https://github.com/microsoft/ApplicationInsights-Java/issues/1444