Search code examples
c#azureasp.net-coreazure-application-insightsotel

The ILogger category name is not available in Application Insights when using Azure.Monitor.OpenTelemetry.AspNetCore in ASP.NET Core application


I'm using the Azure.Monitor.OpenTelemetry.AspNetCore OTEL package to emit telemtry to Application Insights for an ASP.NET Core application (.NET 8).

Within Application Insights, I don't see the "Category" field that I would normally see for e.g. function apps. This field captures the category in ILogger<Category>, so I find it extremely useful for identifying the code that emitted the log.

How can I make the package also include the logging category?

Packages:

 <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
 <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />

Code:

logger.LogInformation("Fetched all users");

Application Insights:

enter image description here


Solution

  • This bug was fixed in Azure.Monitor.OpenTelemetry.Exporter v1.4.0-beta.1.

    This is included in Azure.Monitor.OpenTelemetry.AspNetCore v1.3.0-beta.2, so upgrade the package reference (from v1.2.0) to:

    <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.3.0-beta.2" />
    

    1.4.0-beta.1 (2024-07-12)

    Bugs Fixed

    • Added the LogRecord.CategoryName field to log and exception telemetry. Previously the CategoryName field was omitted, which was inconsistent with expected ILogger behavior, and with Application Insights classic behavior.
      (#44754)

    https://github.com/Azure/azure-sdk-for-net/blob/cd4482ea1ef034f9c875e8c85bcff6704677dc08/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md?plain=1#L32