Skip to content
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

LogEmitter System.Diagnostics.Tracing extension project #3305

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6d2f153
LogEmitter API.
CodeBlanch May 24, 2022
101ce19
Code review.
CodeBlanch May 25, 2022
7eb0006
Added LogRecordPool.
CodeBlanch May 26, 2022
20479f5
Nullable annotation updates.
CodeBlanch May 26, 2022
c64ca11
Merge branch 'main' into log-emitter
CodeBlanch May 26, 2022
53a6854
Cleanup.
CodeBlanch May 26, 2022
fd5a87e
Cleanup.
CodeBlanch May 26, 2022
035823b
Added reference counting into the log record pool.
CodeBlanch May 26, 2022
80cbdbb
Tweaks.
CodeBlanch May 28, 2022
744c399
Tweak.
CodeBlanch May 29, 2022
df93cf5
Test fix.
CodeBlanch May 29, 2022
1ba8afe
Merge branch 'main' into log-emitter
CodeBlanch May 29, 2022
9a0ee32
Test fix.
CodeBlanch May 29, 2022
888eb54
Rename.
CodeBlanch May 30, 2022
558e8d2
Trigger state buffering by processor inspection.
CodeBlanch May 31, 2022
4d76b87
Implement copy for in-memory log exporter.
CodeBlanch May 31, 2022
617d88d
Added GetDataRef.
CodeBlanch May 31, 2022
ca7e319
Tweaks.
CodeBlanch May 31, 2022
6fae76d
Merge branch 'main' into log-emitter
CodeBlanch May 31, 2022
a92e78e
Revert CompositeProcessor change.
CodeBlanch May 31, 2022
5e33474
Add log stress tests to solution.
CodeBlanch May 31, 2022
6b15b3b
Tweaks.
CodeBlanch May 31, 2022
2114dca
Code review.
CodeBlanch Jun 1, 2022
0d34533
Code review, example app, serilog + eventsource extensions.
CodeBlanch Jun 2, 2022
bb4293c
Rename.
CodeBlanch Jun 2, 2022
380f139
Typo.
CodeBlanch Jun 2, 2022
87597f8
New pool design + tests.
CodeBlanch Jun 6, 2022
345e1a2
Pool selection based on processor.
CodeBlanch Jun 6, 2022
ea63af4
Merge from main.
CodeBlanch Jun 7, 2022
a12d432
Update public api files.
CodeBlanch Jun 7, 2022
3b35268
Public api fix.
CodeBlanch Jun 7, 2022
57775a5
Lint and race comment.
CodeBlanch Jun 7, 2022
9ee18df
Comments in log emitter example app.
CodeBlanch Jun 7, 2022
f347e51
Switch to Volatile.Read.
CodeBlanch Jun 7, 2022
5537c73
Bump Microsoft.DotNet.ApiCompat.
CodeBlanch Jun 7, 2022
e0c2347
Typo fix.
CodeBlanch Jun 7, 2022
dd80cc9
Bump Microsoft.DotNet.ApiCompat.
CodeBlanch Jun 7, 2022
4f6b9e0
Attempting to fix ApiCompat failure.
CodeBlanch Jun 7, 2022
1dcd193
Tweak ApiCompatExcludeAttributeList path.
CodeBlanch Jun 7, 2022
226facf
Exclude NullableContextAttribute from ApiCompat.
CodeBlanch Jun 7, 2022
d3c5443
Merge from main.
CodeBlanch Jun 15, 2022
31f5a97
Merge from main.
CodeBlanch Jun 16, 2022
cb69e49
Fix merge.
CodeBlanch Jun 16, 2022
8693d93
Merge from main.
CodeBlanch Jun 17, 2022
b71006f
Updates.
CodeBlanch Jun 17, 2022
6269015
Merge from main.
CodeBlanch Jun 18, 2022
7647145
Revert OtlpLogExporter use of logRecord.GetDataRef because it is now …
CodeBlanch Jun 18, 2022
4f498af
Merge branch 'main' into log-emitter
cijothomas Jun 27, 2022
55537b5
Merge from main.
CodeBlanch Jun 30, 2022
d1a4b3b
Merge fix.
CodeBlanch Jun 30, 2022
ffda1ce
Merge from main.
CodeBlanch Jul 11, 2022
12c92ad
Merge from main.
CodeBlanch Jul 18, 2022
cf69b8c
Updates.
CodeBlanch Jul 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Trigger state buffering by processor inspection.
  • Loading branch information
CodeBlanch committed May 31, 2022
commit 558e8d2cf9dd414e81b4aab31b0e5c94d6f43623
4 changes: 2 additions & 2 deletions src/OpenTelemetry/.publicApi/net462/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ OpenTelemetry.BatchExportProcessorOptions<T>.ScheduledDelayMilliseconds.set -> v
OpenTelemetry.BatchLogRecordExportProcessor
OpenTelemetry.BatchLogRecordExportProcessor.BatchLogRecordExportProcessor(OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512) -> void
OpenTelemetry.CompositeProcessor<T>
~OpenTelemetry.CompositeProcessor<T>.AddProcessor(OpenTelemetry.BaseProcessor<T> processor) -> OpenTelemetry.CompositeProcessor<T>
~OpenTelemetry.CompositeProcessor<T>.CompositeProcessor(System.Collections.Generic.IEnumerable<OpenTelemetry.BaseProcessor<T>> processors) -> void
OpenTelemetry.CompositeProcessor<T>.AddProcessor(OpenTelemetry.BaseProcessor<T>! processor) -> OpenTelemetry.CompositeProcessor<T>!
OpenTelemetry.CompositeProcessor<T>.CompositeProcessor(System.Collections.Generic.IEnumerable<OpenTelemetry.BaseProcessor<T>!>! processors) -> void
OpenTelemetry.ExportProcessorType
OpenTelemetry.ExportProcessorType.Batch = 1 -> OpenTelemetry.ExportProcessorType
OpenTelemetry.ExportProcessorType.Simple = 0 -> OpenTelemetry.ExportProcessorType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ OpenTelemetry.BatchExportProcessorOptions<T>.ScheduledDelayMilliseconds.set -> v
OpenTelemetry.BatchLogRecordExportProcessor
OpenTelemetry.BatchLogRecordExportProcessor.BatchLogRecordExportProcessor(OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512) -> void
OpenTelemetry.CompositeProcessor<T>
~OpenTelemetry.CompositeProcessor<T>.AddProcessor(OpenTelemetry.BaseProcessor<T> processor) -> OpenTelemetry.CompositeProcessor<T>
~OpenTelemetry.CompositeProcessor<T>.CompositeProcessor(System.Collections.Generic.IEnumerable<OpenTelemetry.BaseProcessor<T>> processors) -> void
OpenTelemetry.CompositeProcessor<T>.AddProcessor(OpenTelemetry.BaseProcessor<T>! processor) -> OpenTelemetry.CompositeProcessor<T>!
OpenTelemetry.CompositeProcessor<T>.CompositeProcessor(System.Collections.Generic.IEnumerable<OpenTelemetry.BaseProcessor<T>!>! processors) -> void
OpenTelemetry.ExportProcessorType
OpenTelemetry.ExportProcessorType.Batch = 1 -> OpenTelemetry.ExportProcessorType
OpenTelemetry.ExportProcessorType.Simple = 0 -> OpenTelemetry.ExportProcessorType
Expand Down
24 changes: 13 additions & 11 deletions src/OpenTelemetry/CompositeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
// </copyright>

#nullable enable

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -24,7 +26,7 @@ namespace OpenTelemetry
{
public class CompositeProcessor<T> : BaseProcessor<T>
{
private readonly DoublyLinkedListNode head;
internal readonly DoublyLinkedListNode Head;
private DoublyLinkedListNode tail;
private bool disposed;

Expand All @@ -38,8 +40,8 @@ public CompositeProcessor(IEnumerable<BaseProcessor<T>> processors)
throw new ArgumentException($"'{iter}' is null or empty", nameof(iter));
}

this.head = new DoublyLinkedListNode(iter.Current);
this.tail = this.head;
this.Head = new DoublyLinkedListNode(iter.Current);
this.tail = this.Head;

while (iter.MoveNext())
{
Expand All @@ -64,7 +66,7 @@ public CompositeProcessor<T> AddProcessor(BaseProcessor<T> processor)
/// <inheritdoc/>
public override void OnEnd(T data)
{
for (var cur = this.head; cur != null; cur = cur.Next)
for (var cur = this.Head; cur != null; cur = cur.Next)
{
cur.Value.OnEnd(data);
}
Expand All @@ -73,7 +75,7 @@ public override void OnEnd(T data)
/// <inheritdoc/>
public override void OnStart(T data)
{
for (var cur = this.head; cur != null; cur = cur.Next)
for (var cur = this.Head; cur != null; cur = cur.Next)
{
cur.Value.OnStart(data);
}
Expand All @@ -87,7 +89,7 @@ protected override bool OnForceFlush(int timeoutMilliseconds)
? null
: Stopwatch.StartNew();

for (var cur = this.head; cur != null; cur = cur.Next)
for (var cur = this.Head; cur != null; cur = cur.Next)
{
if (sw == null)
{
Expand All @@ -113,7 +115,7 @@ protected override bool OnShutdown(int timeoutMilliseconds)
? null
: Stopwatch.StartNew();

for (var cur = this.head; cur != null; cur = cur.Next)
for (var cur = this.Head; cur != null; cur = cur.Next)
{
if (sw == null)
{
Expand All @@ -138,7 +140,7 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
for (var cur = this.head; cur != null; cur = cur.Next)
for (var cur = this.Head; cur != null; cur = cur.Next)
{
try
{
Expand All @@ -157,7 +159,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

private class DoublyLinkedListNode
internal sealed class DoublyLinkedListNode
{
public readonly BaseProcessor<T> Value;

Expand All @@ -166,9 +168,9 @@ public DoublyLinkedListNode(BaseProcessor<T> value)
this.Value = value;
}

public DoublyLinkedListNode Previous { get; set; }
public DoublyLinkedListNode? Previous { get; set; }

public DoublyLinkedListNode Next { get; set; }
public DoublyLinkedListNode? Next { get; set; }
}
}
}
10 changes: 8 additions & 2 deletions src/OpenTelemetry/Logs/OpenTelemetryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except

record.ScopeProvider = provider.IncludeScopes ? this.ScopeProvider : null;
record.State = provider.ParseStateValues ? null : state;
record.StateValues = provider.ParseStateValues ? this.ParseState(record, state) : null;
record.StateValues = provider.ParseStateValues ? this.ParseState(record, state, provider.HasBatchProcessor) : null;

ref LogRecordData data = ref record.Data;

Expand Down Expand Up @@ -88,7 +88,7 @@ public bool IsEnabled(LogLevel logLevel)

public IDisposable BeginScope<TState>(TState state) => this.ScopeProvider?.Push(state) ?? NullScope.Instance;

private IReadOnlyList<KeyValuePair<string, object?>> ParseState<TState>(LogRecord logRecord, TState state)
private IReadOnlyList<KeyValuePair<string, object?>> ParseState<TState>(LogRecord logRecord, TState state, bool buffer)
{
if (state is LogRecordAttributeList logRecordAttributes)
{
Expand All @@ -97,6 +97,12 @@ public bool IsEnabled(LogLevel logLevel)
}
else if (state is IReadOnlyList<KeyValuePair<string, object?>> stateList)
{
if (!buffer)
{
return stateList;
}

// Note: Buffering is needed to fix: https://github.com/open-telemetry/opentelemetry-dotnet/issues/2905
var attributeStorage = logRecord.AttributeStorage ??= new List<KeyValuePair<string, object?>>(stateList.Count);
attributeStorage.AddRange(stateList);
return attributeStorage;
Expand Down
28 changes: 28 additions & 0 deletions src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class OpenTelemetryLoggerProvider : BaseProvider, ILoggerProvider, ISuppo
internal readonly bool IncludeFormattedMessage;
internal readonly bool ParseStateValues;
internal BaseProcessor<LogRecord>? Processor;
internal bool HasBatchProcessor;
internal Resource Resource;
private readonly Hashtable loggers = new();
private bool disposed;
Expand Down Expand Up @@ -124,6 +125,11 @@ internal OpenTelemetryLoggerProvider AddProcessor(BaseProcessor<LogRecord> proce

processor.SetParentProvider(this);

if (!this.HasBatchProcessor)
{
this.InspectProcessor(processor);
}

if (this.Processor == null)
{
this.Processor = processor;
Expand Down Expand Up @@ -162,5 +168,27 @@ protected override void Dispose(bool disposing)

base.Dispose(disposing);
}

private void InspectProcessor(BaseProcessor<LogRecord> processor)
{
if (processor is BatchExportProcessor<LogRecord>)
{
this.HasBatchProcessor = true;
}
else if (processor is CompositeProcessor<LogRecord> compositeProcessor)
{
var current = compositeProcessor.Head;
while (current != null)
{
this.InspectProcessor(current.Value);
if (this.HasBatchProcessor)
{
return;
}

current = current.Next;
}
}
}
}
}