Skip to content

cloud_RoleName blank in app insights portal under 3.0.1 (worked in 3.0.1-BETA.2) #1444

@petergphillips

Description

@petergphillips

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 #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 #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:

  • SDK Version: 2.6.2
  • Java Agent Version: 3.0.1
  • OS type and version: Debian 14
  • Application Server type and version (if applicable): Spring Boot 2.4.1
  • Using spring-boot? yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions