[bug] OpenTelemetryLogger searches {OriginalFormat} attribute only at last position. #5983
Labels
bug
Something isn't working
needs-triage
New issues which have not been classified or triaged by a community member
pkg:OpenTelemetry
Issues related to OpenTelemetry NuGet package
Package
OpenTelemetry
Package Version
Runtime Version
net9.0
Description
There is a private TryGetOriginalFormatFromAttributes method in OpenTelemetryLogger class that tries to search {OriginalFormat} attribute only at last element of the list. I guess this decision was made to reflect behavior of built-in Microsoft Logger and for performance reasons.
But there are logging implementations that can write this attribute at other positions.
For example, we can face a problem when using modern logging source generator approach and add reference to
Microsoft.Extensions.Telemetry.Abstractions
nuget package. This official MS package contains it's own logging generator, that writes {OriginalFormat} attribute at the first element of list. Example of generated code:As the result, OpenTelemetryLogger can't find attribute and choose wrong code path to fill
Body
andFormattedMessage
properties of LogRecord.Is it a bug, or something like an expected behavior?
Guess there can be other implementations that don't respect the rule "{OriginalFormat} should always be last attribute". So searching only at last position feels like too strict.
If perf is critical and we can't enumerate whole list, maybe searching also at first position could be a good compromise?
Steps to Reproduce
Expected Result
(Some output omitted for simplicity).
I expect to see message template in
LogRecord.Body
:Actual Result
(Some output omitted for simplicity).
I see formatted message in
LogRecord.Body
because OpenTelemetryLogger didn't find attribute at last position and chose wrong path to fill properties of LogRecord.Additional Context
No response
The text was updated successfully, but these errors were encountered: