Add a fast path for LogRecordAttributeList used as TState to ILogger.Log. (#3750)

This commit is contained in:
Mikel Blanchard 2022-10-11 13:37:57 -07:00 committed by GitHub
parent 9aebae2d90
commit 741966832a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 6 deletions

View File

@ -135,14 +135,18 @@ namespace OpenTelemetry.Logs
private static IReadOnlyList<KeyValuePair<string, object?>>? ProcessState<TState>(LogRecord logRecord, TState state, bool parseStateValues)
{
/* TODO: Enable this if/when LogRecordAttributeList becomes public.
if (state is LogRecordAttributeList logRecordAttributes)
if (typeof(TState) == typeof(LogRecordAttributeList))
{
logRecordAttributes.ApplyToLogRecord(logRecord);
return logRecord.AttributeStorage!;
// Note: This block is written to be elided by the JIT when
// TState is not LogRecordAttributeList or optimized when it is.
// For users that pass LogRecordAttributeList as TState to
// ILogger.Log this will avoid boxing the struct.
var logRecordAttributes = (LogRecordAttributeList)(object)state!;
return logRecordAttributes.Export(ref logRecord.AttributeStorage);
}
else*/
if (state is IReadOnlyList<KeyValuePair<string, object?>> stateList)
else if (state is IReadOnlyList<KeyValuePair<string, object?>> stateList)
{
return stateList;
}