-
Notifications
You must be signed in to change notification settings - Fork 881
Decide what to do with LogRecord.CategoryName #3491
Description
Related conversation https://github.com/open-telemetry/opentelemetry-dotnet/pull/3454/files#r927184812
The top-level name field was dropped from the log data model. Originally, .NET's LogRecord.CategoryName was intended to serve the purpose of this top-level field.
CategoryName cannot be removed because it is part of .NET's stable log data model, so we need to decide what to do with it.
Options
1. Only use it for ILogger
Each exporter is responsible for how it represents CategoryName. Currently, the OTLP exporter translates this to an attribute named dotnet.ilogger.category
Lines 78 to 86 in cf3dfc5
| if (!string.IsNullOrEmpty(logRecord.CategoryName)) | |
| { | |
| // TODO: | |
| // 1. Track the following issue, and map CategoryName to Name | |
| // if it makes it to log data model. | |
| // https://github.com/open-telemetry/opentelemetry-specification/issues/2398 | |
| // 2. Confirm if this name for attribute is good. | |
| otlpLogRecord.Attributes.AddStringAttribute("dotnet.ilogger.category", logRecord.CategoryName); | |
| } |
If we agree to only use CategoryName for the purpose of ILogger then we could keep the OTLP exporter as it is. Though, we should decide if it makes sense to mimic this behavior in other exporters and components like log enrichers.
2. Make use of it across all logging frameworks we support
The Serilog sink makes use of CategoryName
opentelemetry-dotnet/src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogSink.cs
Lines 71 to 75 in bfabe9b
| if (property.Key == Constants.SourceContextPropertyName | |
| && property.Value is ScalarValue sourceContextValue) | |
| { | |
| data.CategoryName = sourceContextValue.Value as string; | |
| } |
This is problematic from the standpoint of the OTLP exporter. If we want to make use of CategoryName across logging frameworks, then we need to devise a generically named attribute that it gets mapped to.
3. Abandon the use of CategoryName from all SDK components
Perhaps the cleanest option is to abandon the use of CategoryName across all logging components. For each logging framework we support, if the framework has some notion of "category", we would map that to an attribute named appropriately for the framework - e.g., ilogger.category, serilog.context, event_source.name.
If we take this approach, it might make sense to mark CategoryName obsolete.
Though, we still would need to decide what to do if an end user wrote their own extension and made use of CategoryName. Should we map it to a generic attribute? e.g., dotnet.otel.category_name
I'm personally leaning towards option 3. There is an open issue asking to reintroduce the name field to the log data model. If this does happen in the future, it might make sense to keep our CategoryName field obsolete and instead introduce a new field.