Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.16k stars 4.53k forks source link

[BUG] OpenTelemetry Exporter for Monitor/App Insights omits LoggerRecord CategoryName #44746

Open johncrim opened 6 days ago

johncrim commented 6 days ago

Library name and version

Azure.Monitor.OpenTelemetry.Exporter

Describe the bug

I am in the midst of switching from App Insights Classic to the OpenTelemetry exporter, and I found that the Logger exporter omits the CategoryName field when sending data to the App Insights endpoint.

The OpenTelemetry model has LogRecord.CategoryName, and the Application Insights classic API faithfully uses the ILogger.Name in the customDimensions/CategoryName field.

Note that the CategoryName field is not listed on this page: https://opentelemetry.io/docs/specs/otel/logs/data-model/#log-and-event-record-definition but it IS included in other .NET docs on the opentelemetry site.

This is a pretty severe oversight - I would say the green checkbox here isn't quite true! :)

image

Expected behavior

When using the OpenTelemetry exporter, calls to ILogger<T> pass all the same fields to the App Insights traces table as are passed using App Insights classic.

Actual behavior

The CategoryName field is omitted from App Insights by the exporter. I've stepped through the code and verified that it's missing from LogsHelper.OtelToAzureMonitorLogs().

Reproduction Steps

Run the OpenTelemetry Exporter demo with an App Insights Connection string, and comment out everything except the Logger part, eg:

        public static void Main()
        {
            // To use AAD, setup your desired credential and provide to the demo class.
            // var credential = new DefaultAzureCredential();
            // using var traceDemo = new TraceDemo(ConnectionString, credential);

            //using var traceDemo = new TraceDemo(ConnectionString);
            //traceDemo.GenerateTraces();

            //using var metricDemo = new MetricDemo(ConnectionString);
            //metricDemo.GenerateMetrics();

            using var logDemo = new LogDemo(ConnectionString);
            logDemo.GenerateLogs();

            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }

then run it, and note the output excludes CategoryName:

{
  "name": "Message",
  "time": "2024-06-26T22:22:56.9910123Z",
  "iKey": "02e6ee70-b253-4d75-9785-cf4ba016c9c3",
  "tags": {
    "ai.cloud.role": "[my-namespace]/my-service",
    "ai.cloud.roleInstance": "my-instance",
    "ai.application.ver": "1.0.0-demo",
    "ai.internal.sdkVersion": "dotnet7.0.20:otel1.9.0:ext1.4.0-alpha.20240626"
  },
  "data": {
    "baseType": "MessageData",
    "baseData": {
      "message": "Hello from {name} {price}.",
      "severityLevel": "Information",
      "properties": {
        "name": "tomato",
        "price": "2.99"
      },
      "ver": 2
    }
  }
}

Environment

  dotnet --info
.NET SDK:
 Version:           8.0.302
 Commit:            ef14e02af8
 Workload version:  8.0.300-manifests.5273bb1c
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.302\

Host:
  Version:      8.0.6
  Architecture: x64
  Commit:       3b8b000a0e

.NET SDKs installed:
  6.0.423 [C:\Program Files\dotnet\sdk]
  8.0.302 [C:\Program Files\dotnet\sdk]
github-actions[bot] commented 5 days ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra @vishweshbankwar.

mattmccleary commented 4 days ago

@johncrim Appreciate you taking the time to open issues and offer feedback. If you'd like to set up a regular sync, shoot me an email at OTel@microsoft.com. Since OTel is evolving pretty quickly, we could try to iterate faster based on your feedback. I'll be OOF for a week in early July but will respond ASAP.

johncrim commented 13 hours ago

Thanks @mattmccleary - will do. I have a few other items of feedback, would be happy to discuss.