-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Introduce IBufferedLogger #103138
Introduce IBufferedLogger #103138
Conversation
src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IBufferedLogRecordMetadata.cs
Outdated
Show resolved
Hide resolved
@geeknoid LGTM. Thanks for getting this that fast. I left a minor comment there. @noahfalk @samsp-msft any feedback? |
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IBufferedLogRecordMetadata.cs
Outdated
Show resolved
Hide resolved
I think we should do the transform you suggested so that we can extend this in the future if needed, but otherwise LGTM! EDIT: We also need to figure out what we're doing with EventSourceLoggerProvider and OpenTelemetry. At minimum we should make sure OTel folks are on-board with the design and its implications for their logger prior to taking this for review. |
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IBufferedLogRecordMetadata.cs
Outdated
Show resolved
Hide resolved
@CodeBlanch was in the meeting. Will be good to understand the plan for any OTel logger for that though. |
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/BufferedLogRecordMetadata.cs
Outdated
Show resolved
Hide resolved
...s/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs
Outdated
Show resolved
Hide resolved
@kalyanaj for FYI, |
src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
...nsions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/ConsoleLoggerTest.cs
Outdated
Show resolved
Hide resolved
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.
LGTM
...crosoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj
Outdated
Show resolved
Hide resolved
@@ -155,6 +155,23 @@ public enum LogLevel | |||
Critical = 5, | |||
None = 6, | |||
} | |||
public abstract class BufferedLogRecord |
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.
A few comments...
-
Should we add
ActivityTraceFlags
on here as well? OTel spec requires TraceId, SpanId, & TraceFlags for correlation: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#log-and-event-record-definition -
Suggest making attributes nullable...
- IReadOnlyList<KeyValuePair<string, object?>> Attributes + IReadOnlyList<KeyValuePair<string, object?>>? Attributes
Just thinking some logs won't have any attributes so the model should match.
-
The
abstract
andvirtual
stuff feels a bit odd. For really a DTO could we do...
public sealed class BufferedLogRecord
{
public required System.DateTimeOffset Timestamp { get; init; }
public required Microsoft.Extensions.Logging.LogLevel LogLevel { get; init; }
public required Microsoft.Extensions.Logging.EventId EventId { get; init; }
public string? Exception { get; init; }
public System.Diagnostics.ActivitySpanId? ActivitySpanId { get; init; }
public System.Diagnostics.ActivityTraceId? ActivityTraceId { get; init; }
public int? ManagedThreadId { get; init; }
public string? FormattedMessage { get; init; }
public string? MessageTemplate { get; init; }
public System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object?>> Attributes { get; init; }
}
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.
@noahfalk Should we add trace flags? Just another prop, not a big deal...
I thought it's fine to have the attributes non-nullable, it would just point to an empty attribute list if there is nothing there.
As for the virtual/abstract duality, that was a result of refactoring and not paying attention. This is now all abstract. This means whomever implements this abstraction gets to decide how to manage the underlying storage of each property.
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.
I'm happy to add trace flags if Blanch believes they would be useful.
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.
The abstract and virtual stuff feels a bit odd. For really a DTO could we do...
The design goal behind this type currently is that it isn't an intermediate DTO, it is likely the type that was used for backing storage. If you guys want to change this into a DTO and copy all the property values in from some private implementation type that does the storage I'm fine with that too.
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/BufferedLogRecord.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/BufferedLogRecord.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IBufferedLogger.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/IBufferedLogger.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs
Outdated
Show resolved
Hide resolved
...s/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/JsonConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/SystemdConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/SystemdConsoleFormatter.cs
Show resolved
Hide resolved
...nsions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/ConsoleLoggerTest.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Fixes #104129