Skip to content

Commit

Permalink
Perf tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Jun 26, 2023
1 parent 82b33b4 commit 3a46aeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

## Unreleased

## 1.5.1

Released 2023-Jun-23

* Fixed a breaking change causing `LogRecord.State` to be `null` where it was
previously set to a valid value when
`OpenTelemetryLoggerOptions.ParseStateValues` is `false` and states implement
Expand Down
21 changes: 17 additions & 4 deletions src/OpenTelemetry/Logs/ILogger/OpenTelemetryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ internal static void SetLogRecordSeverityFields(ref LogRecordData logRecordData,
return null;
}

// Note: This is to preserve legacy behavior where State is
// exposed if we didn't parse state.
iLoggerData.State = !parseStateValues ? state : null;

/* TODO: Enable this if/when LogRecordAttributeList becomes public.
if (typeof(TState) == typeof(LogRecordAttributeList))
{
Expand All @@ -181,10 +177,20 @@ internal static void SetLogRecordSeverityFields(ref LogRecordData logRecordData,
else */
if (state is IReadOnlyList<KeyValuePair<string, object?>> stateList)
{
// Note: This is to preserve legacy behavior where State is exposed
// if we didn't parse state. We use stateList here to prevent a
// second boxing of struct TStates.
iLoggerData.State = !parseStateValues ? stateList : null;

return stateList;
}
else if (state is IEnumerable<KeyValuePair<string, object?>> stateValues)
{
// Note: This is to preserve legacy behavior where State is exposed
// if we didn't parse state. We use stateValues here to prevent a
// second boxing of struct TStates.
iLoggerData.State = !parseStateValues ? stateValues : null;

var attributeStorage = logRecord.AttributeStorage;
if (attributeStorage == null)
{
Expand All @@ -198,10 +204,17 @@ internal static void SetLogRecordSeverityFields(ref LogRecordData logRecordData,
}
else if (!parseStateValues)
{
// Note: This is to preserve legacy behavior where State is
// exposed if we didn't parse state.
iLoggerData.State = state;
return null;
}
else
{
// Note: We clear State because the LogRecord we are processing may
// have come from the pool and may have State from a prior log.
iLoggerData.State = null;

try
{
PropertyDescriptorCollection itemProperties = TypeDescriptor.GetProperties(state!);
Expand Down

0 comments on commit 3a46aeb

Please sign in to comment.