-
Notifications
You must be signed in to change notification settings - Fork 364
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
LogRecord pipeline addition #5124
Open
CodeBlanch
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
CodeBlanch:otel-logs-pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
256 changes: 151 additions & 105 deletions
256
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/ILogRecordLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
namespace Microsoft.Diagnostics.Monitoring.EventPipe | ||
{ | ||
internal interface ILogRecordLogger | ||
{ | ||
void Log( | ||
in LogRecord log, | ||
ReadOnlySpan<KeyValuePair<string, object?>> attributes, | ||
in LogRecordScopeContainer scopes); | ||
|
||
Task PipelineStarted(CancellationToken token); | ||
Task PipelineStopped(CancellationToken token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/LogRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Diagnostics.Monitoring.EventPipe | ||
{ | ||
internal readonly struct LogRecord | ||
{ | ||
public LogRecord( | ||
DateTime timestamp, | ||
string categoryName, | ||
LogLevel logLevel, | ||
EventId eventId, | ||
in LogRecordException exception, | ||
string? formattedMessage, | ||
string? messageTemplate, | ||
ActivityTraceId traceId, | ||
ActivitySpanId spanId, | ||
ActivityTraceFlags traceFlags) | ||
{ | ||
if (string.IsNullOrEmpty(categoryName)) | ||
{ | ||
throw new ArgumentNullException(nameof(categoryName)); | ||
} | ||
|
||
Timestamp = timestamp; | ||
CategoryName = categoryName; | ||
LogLevel = logLevel; | ||
EventId = eventId; | ||
Exception = exception; | ||
FormattedMessage = formattedMessage; | ||
MessageTemplate = messageTemplate; | ||
TraceId = traceId; | ||
SpanId = spanId; | ||
TraceFlags = traceFlags; | ||
} | ||
|
||
public readonly DateTime Timestamp; | ||
|
||
public readonly string CategoryName; | ||
|
||
public readonly LogLevel LogLevel; | ||
|
||
public readonly EventId EventId; | ||
|
||
public readonly LogRecordException Exception; | ||
|
||
public readonly string? FormattedMessage; | ||
|
||
public readonly string? MessageTemplate; | ||
|
||
public readonly ActivityTraceId TraceId; | ||
|
||
public readonly ActivitySpanId SpanId; | ||
|
||
public readonly ActivityTraceFlags TraceFlags; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/LogRecordException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.Diagnostics.Monitoring.EventPipe | ||
{ | ||
internal readonly struct LogRecordException : IEquatable<LogRecordException> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a record struct might give you these semantics automatically. |
||
{ | ||
public LogRecordException( | ||
string? exceptionType, | ||
string? message, | ||
string? stackTrace) | ||
{ | ||
ExceptionType = exceptionType; | ||
Message = message; | ||
StackTrace = stackTrace; | ||
} | ||
|
||
public readonly string? ExceptionType; | ||
|
||
public readonly string? Message; | ||
|
||
public readonly string? StackTrace; | ||
|
||
public bool Equals(LogRecordException other) | ||
{ | ||
return ExceptionType == other.ExceptionType | ||
&& Message == other.Message | ||
&& StackTrace == other.StackTrace; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
=> obj is LogRecordException ex && Equals(ex); | ||
|
||
public override int GetHashCode() | ||
{ | ||
HashCode hash = default; | ||
|
||
hash.Add(ExceptionType); | ||
hash.Add(Message); | ||
hash.Add(StackTrace); | ||
|
||
return hash.ToHashCode(); | ||
} | ||
|
||
public static bool operator ==(LogRecordException left, LogRecordException right) | ||
=> left.Equals(right); | ||
|
||
public static bool operator !=(LogRecordException left, LogRecordException right) | ||
=> !left.Equals(right); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/LogRecordPayload.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Diagnostics.Monitoring.EventPipe | ||
{ | ||
internal ref struct LogRecordPayload | ||
{ | ||
public LogRecord LogRecord; | ||
|
||
public ReadOnlySpan<KeyValuePair<string, object?>> Attributes; | ||
|
||
public ReadOnlySpan<LogObject> Scopes; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/LogRecordScopeContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
using System; | ||
|
||
namespace Microsoft.Diagnostics.Monitoring.EventPipe | ||
{ | ||
internal readonly ref struct LogRecordScopeContainer | ||
{ | ||
private readonly ReadOnlySpan<LogObject> _Scopes; | ||
|
||
public LogRecordScopeContainer( | ||
ReadOnlySpan<LogObject> scopes) | ||
{ | ||
_Scopes = scopes; | ||
} | ||
|
||
public void ForEachScope<T>(LogRecordScopeAction<T> callback, ref T state) | ||
{ | ||
foreach (LogObject scope in _Scopes) | ||
{ | ||
callback(scope.ToSpan(), ref state); | ||
} | ||
} | ||
|
||
public delegate void LogRecordScopeAction<T>( | ||
ReadOnlySpan<KeyValuePair<string, object?>> attributes, | ||
ref T state); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why move from List to array?
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.
Would CollectionsMarshal.AsSpan work here?