Cloud Role Name is missing after upgrading to latest stable version of Microsoft.ApplicationInsights.AspNetCore

See original GitHub issue

Recently I upgraded to latest stable version of Microsoft.ApplicationInsights.AspNetCore (2.1.16) and cloud_RoleName started disappearing from Application Insights Traces. ( see 2147) for more details)

Serilog Packages used:

  • Serilog.AspNetCore (3.4.0)
  • Serilog.Sinks.ApplicationInsights (3.1.0)

Below are the samples which will help to reproduce the issue.

With Serilog.zip Without Serilog (working).zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
alexeymarkovcommented, Jun 30, 2021

Are there any news? When it is going to be fixed?

2reactions
NitinM3commented, May 13, 2021

Not sure if it will help, but I had a similar issue which I “fixed” (patched in a most hacky way) by creating an overridden TraceTelemetryInitializer and using that when setting up my App Insights sink. I also couldn’t live without my custom cloud_roleName!

SerilogAppInsightsTraceTelemetryConverter.cs

using Microsoft.ApplicationInsights.Channel;
using Serilog.Events;
using Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters;
using System;
using System.Collections.Generic;
using System.Reflection;

namespace MyApp.Common.Logging.TelemetryConverters
{
    public class SerilogAppInsightsTraceTelemetryConverter : TraceTelemetryConverter
    {
        private string? _roleName;

        public SerilogAppInsightsTraceTelemetryConverter()
        {
            _roleName = Assembly.GetEntryAssembly()?.GetName()?.Name;  // Or whatever else you'd like to set the name to.
        }

        public override IEnumerable<ITelemetry> Convert(LogEvent logEvent, IFormatProvider formatProvider)
        {
            foreach(var telemetry in base.Convert(logEvent, formatProvider))
            {
                telemetry.Context.Cloud.RoleName = _roleName;
                yield return telemetry;
            }
        }
    }
}

Then use it during startup:

Host.CreateDefaultBuilder(args)
    .UseSerilog((context, services, serilogConfiguration) =>
        serilogConfiguration.WriteTo.ApplicationInsights(new TelemetryConfiguration(instrumentationKey), new SerilogAppInsightsTraceTelemetryConverter(), LogEventLevel.Information);
    )

@daniel-simpson Thanks. This workaround worked for me as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud Role Name is missing after upgrading to latest ...
After upgrading cloud_RoleName is missing from Application Insights Traces. Previously, it was working with the below versions. When downgraded ...
Read more >
Send cloud role name to appinsight using serilog
I use serilog to send traces to appinsights this is my code Log.Logger = new LoggerConfiguration() .Enrich.WithProperty("AppName", Assembly.
Read more >
Setting Cloud Role Name in Application Insights
I'm using "Microsoft.Extensions.Logging.ApplicationInsights" Version="2.14.0" in my AspNet Core 3.1 project. Any clues, what am I missing here?
Read more >
c# - Microsoft.ApplicationInsights missing
I installed the new version with Install-Package Microsoft.ApplicationInsights ... ApplicationInsights.dll file in the bin folder as well.
Read more >
Untitled
Web1 Feb 2016 · Cloud Role Name is missing after upgrading to latest stable version of Microsoft.ApplicationInsights.AspNetCore · Issue #152 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found