Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role name in application insights profile list #214

Open
stephen-rotageek opened this issue Feb 27, 2024 · 6 comments
Open

Role name in application insights profile list #214

stephen-rotageek opened this issue Feb 27, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request Needs external fix

Comments

@stephen-rotageek
Copy link

Describe the bug
The role name in the Application Insights Profiler list is the resource Id of the app insights instead of the application name.

e.g. /subscriptions/subscriptionId/resourcegroups/resourcegroupid/providers/microsoft.insights/components/appinsightsname

To Reproduce
Steps to reproduce the behavior:

  1. Follow the steps in the readme of this repo for an MVC project targeting framework net6.0
  2. Deploy to Azure App Services as a docker container.
  3. Run the profiler in app insights, or let the schedule run it.
  4. The role name is the resource Id of the app insights instance instead of the application name.

Expected behavior
The role name is the application name in the App insights profiler list.

Screenshots
I've attached a screen shot of the profiler list showing the role name is the app insights resource id (identifiers redacted)

Profiler list

Desktop (please complete the following information):

  • OS: Linux (Container running on Azure App Service)
  • Package version (Microsoft.ApplicationInsights.Profiler.AspNetCore) 2.6.0
  • Application Insights: 2.22.0
  • Dockerfile is using mcr.microsoft.com/dotnet/aspnet:6.0 AS base

Additional context

Although it shouldn't be required, I've tried creating a custom ITelemetryInitializer to set the role name, but it doesn't have any effect.

  public class TelemetryInitializer : ITelemetryInitializer
  {
      public void Initialize(ITelemetry telemetry)
      {
          string? computerName = Environment.GetEnvironmentVariable("COMPUTERNAME");
          string? appName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME");

          telemetry.Context.Cloud.RoleInstance = computerName ?? "Unknown";
          telemetry.Context.Cloud.RoleName = appName ?? "Unknown";
      }
  }

Then using it in program.cs

builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddSingleton<ITelemetryInitializer, TelemetryInitializer>();
builder.Services.AddServiceProfiler();
@xiaomi7732 xiaomi7732 self-assigned this Feb 29, 2024
@xiaomi7732 xiaomi7732 added bug Something isn't working enhancement New feature or request and removed needs-triage bug Something isn't working labels Feb 29, 2024
@xiaomi7732
Copy link
Member

Hey @stephen-rotageek Thanks for the report. We will take a look.

@xiaomi7732
Copy link
Member

Hi @stephen-rotageek, there are actually 2 problems. 1 is addressed in 2.7.0-beta2. An other is on the service side and will take a while to fix.

Here are the details:

  • Issue 1. RoleName is not carried on in the telemetry objects. That means, the field of cloud_RoleName is always empty for data of the profiler - that's an easy fix.

  • Issue 2. RoleName is not queried on the server side - appName is instead used as the value in the role - which is why you see the full resource id in the role column - there's an internal bug to fix the issue. I currently don't have a good ETA on it.

@stephen-rotageek
Copy link
Author

Thank you for the update @xiaomi7732.

Just to confirm, do we need both issues resolved before RoleName will be available in the profiler list?

Are there any workarounds we could consider?

@xiaomi7732
Copy link
Member

@stephen-rotageek,

Yes, we need both fixed.

With regarding the workaround, you might be able to try to overwrite the value of the appName by using a telemetry initializer.

It sounds like having the proper role name is important to you, do you mind help me understand why?

@stephen-rotageek
Copy link
Author

@xiaomi7732 I previously tried overwriting the RoleName with a Telemetry Initializer but it didn't work. I defaulted the value to "Unknown" if the environment variable for the app name (website_site_name) couldn't be retrieved, but even that didn't come through.

  public class TelemetryInitializer : ITelemetryInitializer
  {
      public void Initialize(ITelemetry telemetry)
      {
          string? computerName = Environment.GetEnvironmentVariable("COMPUTERNAME");
          string? appName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME");

          telemetry.Context.Cloud.RoleInstance = computerName ?? "Unknown";
          telemetry.Context.Cloud.RoleName = appName ?? "Unknown";
      }
  }

In the program.cs

builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddSingleton<ITelemetryInitializer, TelemetryInitializer>();
builder.Services.AddServiceProfiler();

Regarding the importance of the role name, we are planning to use app profiler across multiple applications (microservices), each feeding into the same app insights to give us combined telemetry, using role name to filter to a subset of apps as needed.

If the role name in the profiler list is the resource Id of the app insights, we won't be able to distinguish which profile came from each app. It will make it impossible to sort and difficult to find the profiles we want to view.

@xiaomi7732
Copy link
Member

xiaomi7732 commented Mar 5, 2024

@stephen-rotageek , hey, thanks for the explanation, I'll see if we could prioritize the fix. Please understand that the server side fix has more impacts and will be a longer process.

On the work-around side, since our service side is querying appName (not roleNmae), could you please try to overwrite the value of appName field instead, by using the telemetry initializer?
Let me know! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Needs external fix
Projects
None yet
Development

No branches or pull requests

2 participants