-
Notifications
You must be signed in to change notification settings - Fork 852
[sdk] Merge 1.5.1 fixes to main (1.6 dev) #4619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4619 +/- ##
==========================================
+ Coverage 84.85% 84.88% +0.02%
==========================================
Files 313 313
Lines 12604 12609 +5
==========================================
+ Hits 10695 10703 +8
+ Misses 1909 1906 -3
|
| if (count <= 0) | ||
| { | ||
| return null; | ||
| return Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work with LoggerSdk.EmitLog? This would be changing the behavior of LoggerSdk.EmitLog to return an empty list instead of null when the attribute count is zero. Is that what we want?
| logRecord.Attributes = attributes.Export(ref logRecord.AttributeStorage); |
LogRecord.Attributes description says that its value is set depending upon the options: IncludeAttributes or ParseStateValues. Would these options be considered when using LoggerSdk.EmitLog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot to unpack here 🤣
How does this work with LoggerSdk.EmitLog? This would be changing the behavior of LoggerSdk.EmitLog to return an empty list instead of null when the attribute count is zero. Is that what we want?
I don't think it is an issue. It is all net-new so up to us to define the behavior. When calling Logger.EmitLog (at the moment) there are always attributes. It is either user-supplied (may have 0 count or more) or it is default (0 count). It is a struct so there isn't a way to pass null. With this change the LogRecord will mirror that behavior. It will always have attributes either empty (0) or some list using the pool storage.
I made this change because the exporter which causes the 1.5.1 breakfix is doing...
var list = (IReadOnlyList<KeyValuePair<string, object>>)logRecord.State;
It isn't checking for null and it isn't looking at Attributes or StateValues. If some users take a newer SDK and starts using some Logger.EmitLog thing that exporter would break again. I needed to make sure this path also had a valid logRecord.State. Since State would have a value I decided Attributes / StateValues should as well. It felt confusing the other way around.
LogRecord.Attributes description says that its value is set depending upon the options: IncludeAttributes or ParseStateValues. Would these options be considered when using LoggerSdk.EmitLog?
OpenTelemetryLoggerOptions only applies to the ILogger integration. I'll open a follow-up PR to clarify the XML comments on LogRecord because you are right they are kind of misleading.
Now you can use LogRecordAttributeList with the ILogger integration! You can do logger.Log<LogRecordAttributeList>(...) which is using LogRecordAttributeList as TState in the ILogger API. This is really the only way at the moment to get truly allocation-free logging in OpenTelemetry .NET. If you set OpenTelemetryLoggerOptions.IncludeAttributes = false AND you use LogRecordAttributeList as the TState THEN IncludeAttributes is respected and the LogRecord ends up with null values for State, Attributes, and StateValues.
Relates to #4609
Relates to #4614
Relates to #4615
Changes
main-1.5.0branch (1.5.1 hotfix) to main (1.6 dev line).LogRecordAttributeListwhich is part of 1.6 dev.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes