From 3699ff9083996d6a5031e369eed64026eee421b3 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 20:53:04 -0700 Subject: [PATCH 01/11] extract common part --- ...ityProcessor.cs => BaseExportProcessor.cs} | 22 +- src/OpenTelemetry/BaseExporter.cs | 137 +++++++++++++ .../Internal/CircularBufferStruct.cs | 190 ------------------ src/OpenTelemetry/Logs/LogRecord.cs | 14 +- src/OpenTelemetry/Trace/ActivityExporter.cs | 110 +--------- .../Trace/BatchExportActivityProcessor.cs | 2 +- .../Trace/ReentrantExportActivityProcessor.cs | 2 +- .../Trace/SimpleExportActivityProcessor.cs | 2 +- 8 files changed, 160 insertions(+), 319 deletions(-) rename src/OpenTelemetry/{Trace/BaseExportActivityProcessor.cs => BaseExportProcessor.cs} (73%) create mode 100644 src/OpenTelemetry/BaseExporter.cs delete mode 100644 src/OpenTelemetry/Internal/CircularBufferStruct.cs diff --git a/src/OpenTelemetry/Trace/BaseExportActivityProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs similarity index 73% rename from src/OpenTelemetry/Trace/BaseExportActivityProcessor.cs rename to src/OpenTelemetry/BaseExportProcessor.cs index f4948524f00..d16cf9407bf 100644 --- a/src/OpenTelemetry/Trace/BaseExportActivityProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,32 +18,34 @@ using System.Diagnostics; using OpenTelemetry.Internal; -namespace OpenTelemetry.Trace +namespace OpenTelemetry { /// - /// Implements processor that exports objects. + /// Implements processor that exports telemetry objects. /// - public abstract class BaseExportActivityProcessor : ActivityProcessor + /// The type of object to be exported. + public abstract class BaseExportProcessor : BaseProcessor + where T : class { - protected readonly ActivityExporter exporter; + protected readonly BaseExporter exporter; private bool disposed; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Activity exporter instance. - public BaseExportActivityProcessor(ActivityExporter exporter) + /// Exporter instance. + public BaseExportProcessor(BaseExporter exporter) { this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter)); } /// - public sealed override void OnStart(Activity activity) + public sealed override void OnStart(T data) { } /// - public abstract override void OnEnd(Activity activity); + public abstract override void OnEnd(T data); /// protected override bool OnShutdown(int timeoutMilliseconds) diff --git a/src/OpenTelemetry/BaseExporter.cs b/src/OpenTelemetry/BaseExporter.cs new file mode 100644 index 00000000000..6210a14ea0b --- /dev/null +++ b/src/OpenTelemetry/BaseExporter.cs @@ -0,0 +1,137 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Diagnostics; +using System.Threading; +using OpenTelemetry.Internal; + +namespace OpenTelemetry +{ + /// + /// Enumeration used to define the result of an export operation. + /// + public enum ExportResult + { + /// + /// Export succeeded. + /// + Success = 0, + + /// + /// Export failed. + /// + Failure = 1, + } + + /// + /// Exporter base class. + /// + /// The type of object to be exported. + public abstract class BaseExporter : IDisposable + where T : class + { + private int shutdownCount; + + /// + /// Exports a batch of telemetry objects. + /// + /// Batch of telemetry objects to export. + /// Result of the export operation. + public abstract ExportResult Export(in Batch batch); + + /// + /// Attempts to shutdown the exporter, blocks the current thread until + /// shutdown completed or timed out. + /// + /// + /// The number of milliseconds to wait, or Timeout.Infinite to + /// wait indefinitely. + /// + /// + /// Returns true when shutdown succeeded; otherwise, false. + /// + /// + /// Thrown when the timeoutMilliseconds is smaller than -1. + /// + /// + /// This function guarantees thread-safety. Only the first call will + /// win, subsequent calls will be no-op. + /// + public bool Shutdown(int timeoutMilliseconds = Timeout.Infinite) + { + if (timeoutMilliseconds < 0 && timeoutMilliseconds != Timeout.Infinite) + { + throw new ArgumentOutOfRangeException(nameof(timeoutMilliseconds)); + } + + if (Interlocked.Increment(ref this.shutdownCount) > 1) + { + return false; // shutdown already called + } + + try + { + return this.OnShutdown(timeoutMilliseconds); + } + catch (Exception ex) + { + OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.Shutdown), ex); + return false; + } + } + + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Called by Shutdown. This function should block the current + /// thread until shutdown completed or timed out. + /// + /// + /// The number of milliseconds to wait, or Timeout.Infinite to + /// wait indefinitely. + /// + /// + /// Returns true when shutdown succeeded; otherwise, false. + /// + /// + /// This function is called synchronously on the thread which made the + /// first call to Shutdown. This function should not throw + /// exceptions. + /// + protected virtual bool OnShutdown(int timeoutMilliseconds) + { + return true; + } + + /// + /// Releases the unmanaged resources used by this class and optionally + /// releases the managed resources. + /// + /// + /// to release both managed and unmanaged resources; + /// to release only unmanaged resources. + /// + protected virtual void Dispose(bool disposing) + { + } + } +} diff --git a/src/OpenTelemetry/Internal/CircularBufferStruct.cs b/src/OpenTelemetry/Internal/CircularBufferStruct.cs deleted file mode 100644 index e174af24183..00000000000 --- a/src/OpenTelemetry/Internal/CircularBufferStruct.cs +++ /dev/null @@ -1,190 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using System; -using System.Runtime.CompilerServices; -using System.Threading; - -namespace OpenTelemetry.Internal -{ - /// - /// Lock-free implementation of single-reader multi-writer circular buffer. - /// - /// The type of the underlying value. - internal class CircularBufferStruct - where T : struct - { - private readonly Trait[] trait; - private long head; - private long tail; - - /// - /// Initializes a new instance of the class. - /// - /// The capacity of the circular buffer, must be a positive integer. - public CircularBufferStruct(int capacity) - { - if (capacity <= 0) - { - throw new ArgumentOutOfRangeException(nameof(capacity)); - } - - this.Capacity = capacity; - this.trait = new Trait[capacity]; - } - - /// - /// Gets the capacity of the . - /// - public int Capacity { get; } - - /// - /// Gets the number of items contained in the . - /// - public int Count - { - get - { - var tailSnapshot = this.tail; - return (int)(this.head - tailSnapshot); - } - } - - /// - /// Gets the number of items added to the . - /// - public long AddedCount => this.head; - - /// - /// Gets the number of items removed from the . - /// - public long RemovedCount => this.tail; - - /// - /// Adds the specified item to the buffer. - /// - /// The value to add. - /// - /// Returns true if the item was added to the buffer successfully; - /// false if the buffer is full. - /// - public bool Add(T value) - { - while (true) - { - var tailSnapshot = this.tail; - var headSnapshot = this.head; - - if (headSnapshot - tailSnapshot >= this.Capacity) - { - return false; // buffer is full - } - - var head = Interlocked.CompareExchange(ref this.head, headSnapshot + 1, headSnapshot); - if (head != headSnapshot) - { - continue; - } - - var index = (int)(head % this.Capacity); - this.trait[index].Value = value; - this.trait[index].IsReady = true; - return true; - } - } - - /// - /// Attempts to add the specified item to the buffer. - /// - /// The value to add. - /// The maximum allowed spin count, when set to a negative number or zero, will spin indefinitely. - /// - /// Returns true if the item was added to the buffer successfully; - /// false if the buffer is full or the spin count exceeded . - /// - public bool TryAdd(T value, int maxSpinCount) - { - if (maxSpinCount <= 0) - { - return this.Add(value); - } - - var spinCountDown = maxSpinCount; - - while (true) - { - var tailSnapshot = this.tail; - var headSnapshot = this.head; - - if (headSnapshot - tailSnapshot >= this.Capacity) - { - return false; // buffer is full - } - - var head = Interlocked.CompareExchange(ref this.head, headSnapshot + 1, headSnapshot); - if (head != headSnapshot) - { - if (spinCountDown-- == 0) - { - return false; // exceeded maximum spin count - } - - continue; - } - - var index = (int)(head % this.Capacity); - this.trait[index].Value = value; - this.trait[index].IsReady = true; - return true; - } - } - - /// - /// Reads an item from the . - /// - /// - /// This function is not reentrant-safe, only one reader is allowed at any given time. - /// Warning: There is no bounds check in this method. Do not call unless you have verified Count > 0. - /// - /// Item read. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public T Read() - { - var index = (int)(this.tail % this.Capacity); - while (true) - { - if (!this.trait[index].IsReady) - { - // If we got here it means a writer isn't done. - continue; - } - - // TODO: we are doing an extra copy from the buffer, this can be optimized if Read() could take a callback - var value = this.trait[index].Value; - this.trait[index].IsReady = false; - this.trait[index].Value = default(T); - this.tail++; - return value; - } - } - - private struct Trait - { - internal bool IsReady; - internal T Value; - } - } -} diff --git a/src/OpenTelemetry/Logs/LogRecord.cs b/src/OpenTelemetry/Logs/LogRecord.cs index a4d7499f2d8..5f4091c28fa 100644 --- a/src/OpenTelemetry/Logs/LogRecord.cs +++ b/src/OpenTelemetry/Logs/LogRecord.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry.Logs /// /// Log record base class. /// - public readonly struct LogRecord + public class LogRecord { internal LogRecord(DateTime timestamp, string categoryName, LogLevel logLevel, EventId eventId, object state, Exception exception) { @@ -35,17 +35,17 @@ internal LogRecord(DateTime timestamp, string categoryName, LogLevel logLevel, E this.Exception = exception; } - public DateTime Timestamp { get; } + public DateTime Timestamp { get; protected set; } - public string CategoryName { get; } + public string CategoryName { get; protected set; } - public LogLevel LogLevel { get; } + public LogLevel LogLevel { get; protected set; } - public EventId EventId { get; } + public EventId EventId { get; protected set; } - public object State { get; } + public object State { get; protected set; } - public Exception Exception { get; } + public Exception Exception { get; protected set; } } } #endif diff --git a/src/OpenTelemetry/Trace/ActivityExporter.cs b/src/OpenTelemetry/Trace/ActivityExporter.cs index 4bff2651953..8fce68a8acb 100644 --- a/src/OpenTelemetry/Trace/ActivityExporter.cs +++ b/src/OpenTelemetry/Trace/ActivityExporter.cs @@ -14,122 +14,14 @@ // limitations under the License. // -using System; using System.Diagnostics; -using System.Threading; -using OpenTelemetry.Internal; namespace OpenTelemetry.Trace { - /// - /// Enumeration used to define the result of an export operation. - /// - public enum ExportResult - { - /// - /// Export succeeded. - /// - Success = 0, - - /// - /// Export failed. - /// - Failure = 1, - } - /// /// Activity exporter base class. /// - public abstract class ActivityExporter : IDisposable + public abstract class ActivityExporter : BaseExporter { - private int shutdownCount; - - /// - /// Exports a batch of objects. - /// - /// Batch of objects to export. - /// Result of the export operation. - public abstract ExportResult Export(in Batch batch); - - /// - /// Attempts to shutdown the exporter, blocks the current thread until - /// shutdown completed or timed out. - /// - /// - /// The number of milliseconds to wait, or Timeout.Infinite to - /// wait indefinitely. - /// - /// - /// Returns true when shutdown succeeded; otherwise, false. - /// - /// - /// Thrown when the timeoutMilliseconds is smaller than -1. - /// - /// - /// This function guarantees thread-safety. Only the first call will - /// win, subsequent calls will be no-op. - /// - public bool Shutdown(int timeoutMilliseconds = Timeout.Infinite) - { - if (timeoutMilliseconds < 0 && timeoutMilliseconds != Timeout.Infinite) - { - throw new ArgumentOutOfRangeException(nameof(timeoutMilliseconds)); - } - - if (Interlocked.Increment(ref this.shutdownCount) > 1) - { - return false; // shutdown already called - } - - try - { - return this.OnShutdown(timeoutMilliseconds); - } - catch (Exception ex) - { - OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.Shutdown), ex); - return false; - } - } - - /// - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Called by Shutdown. This function should block the current - /// thread until shutdown completed or timed out. - /// - /// - /// The number of milliseconds to wait, or Timeout.Infinite to - /// wait indefinitely. - /// - /// - /// Returns true when shutdown succeeded; otherwise, false. - /// - /// - /// This function is called synchronously on the thread which made the - /// first call to Shutdown. This function should not throw - /// exceptions. - /// - protected virtual bool OnShutdown(int timeoutMilliseconds) - { - return true; - } - - /// - /// Releases the unmanaged resources used by this class and optionally - /// releases the managed resources. - /// - /// - /// to release both managed and unmanaged resources; - /// to release only unmanaged resources. - /// - protected virtual void Dispose(bool disposing) - { - } } } diff --git a/src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs b/src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs index 49cb1efbc8f..62fe1028787 100644 --- a/src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs +++ b/src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs @@ -24,7 +24,7 @@ namespace OpenTelemetry.Trace /// /// Implements processor that batches activities before calling exporter. /// - public class BatchExportActivityProcessor : BaseExportActivityProcessor + public class BatchExportActivityProcessor : BaseExportProcessor { private readonly CircularBuffer circularBuffer; private readonly int scheduledDelayMilliseconds; diff --git a/src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs b/src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs index c1d8c818ce4..8ba137650e7 100644 --- a/src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs +++ b/src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry.Trace /// /// Implements activity processor that exports at each OnEnd call without synchronization. /// - public class ReentrantExportActivityProcessor : BaseExportActivityProcessor + public class ReentrantExportActivityProcessor : BaseExportProcessor { /// /// Initializes a new instance of the class. diff --git a/src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs b/src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs index fd85e75154c..cd073218450 100644 --- a/src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs +++ b/src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry.Trace /// /// Implements activity processor that exports at each OnEnd call. /// - public class SimpleExportActivityProcessor : BaseExportActivityProcessor + public class SimpleExportActivityProcessor : BaseExportProcessor { private readonly object syncObject = new object(); From a45855ccb4af570c1b285377a47b36dfa4a16a12 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 21:52:33 -0700 Subject: [PATCH 02/11] make process/exporter generic --- docs/logs/getting-started/LoggerExtensions.cs | 12 ++ docs/logs/getting-started/MyExporter.cs | 63 ++++++ docs/logs/getting-started/MyProcessor.cs | 39 +--- docs/logs/getting-started/Program.cs | 34 +++- docs/trace/extending-the-sdk/MyExporter.cs | 2 +- .../MyExporterHelperExtensions.cs | 4 +- docs/trace/extending-the-sdk/MyProcessor.cs | 4 +- docs/trace/extending-the-sdk/Program.cs | 2 +- src/OpenTelemetry/BaseExportProcessor.cs | 2 +- ...tyProcessor.cs => BatchExportProcessor.cs} | 34 ++-- ...vityProcessor.cs => CompositeProcessor.cs} | 36 ++-- .../Logs/CompositeLogProcessor.cs | 191 ------------------ src/OpenTelemetry/Logs/LogProcessor.cs | 31 --- .../Logs/OpenTelemetryLoggerOptions.cs | 4 +- .../Logs/OpenTelemetryLoggerProvider.cs | 8 +- .../Logs/OpenTelemetryLoggingExtensions.cs | 1 + ...ocessor.cs => ReentrantExportProcessor.cs} | 20 +- ...yProcessor.cs => SimpleExportProcessor.cs} | 21 +- src/OpenTelemetry/Trace/ActivityExporter.cs | 27 --- src/OpenTelemetry/Trace/ActivityProcessor.cs | 27 --- .../Trace/ActivitySourceAdapter.cs | 6 +- .../Trace/TracerProviderBuilder.cs | 5 +- .../Trace/TracerProviderExtensions.cs | 3 +- src/OpenTelemetry/Trace/TracerProviderSdk.cs | 10 +- 24 files changed, 198 insertions(+), 388 deletions(-) create mode 100644 docs/logs/getting-started/MyExporter.cs rename src/OpenTelemetry/{Trace/BatchExportActivityProcessor.cs => BatchExportProcessor.cs} (86%) rename src/OpenTelemetry/{Trace/CompositeActivityProcessor.cs => CompositeProcessor.cs} (80%) delete mode 100644 src/OpenTelemetry/Logs/CompositeLogProcessor.cs delete mode 100644 src/OpenTelemetry/Logs/LogProcessor.cs rename src/OpenTelemetry/{Trace/ReentrantExportActivityProcessor.cs => ReentrantExportProcessor.cs} (63%) rename src/OpenTelemetry/{Trace/SimpleExportActivityProcessor.cs => SimpleExportProcessor.cs} (67%) delete mode 100644 src/OpenTelemetry/Trace/ActivityExporter.cs delete mode 100644 src/OpenTelemetry/Trace/ActivityProcessor.cs diff --git a/docs/logs/getting-started/LoggerExtensions.cs b/docs/logs/getting-started/LoggerExtensions.cs index c9a88072402..04174c6e013 100644 --- a/docs/logs/getting-started/LoggerExtensions.cs +++ b/docs/logs/getting-started/LoggerExtensions.cs @@ -16,6 +16,8 @@ using System; using Microsoft.Extensions.Logging; +using OpenTelemetry; +using OpenTelemetry.Logs; internal static class LoggerExtensions { @@ -29,4 +31,14 @@ public static void LogEx(this ILogger logger, object obj) { LogExAction(logger, obj, null); } + + public static OpenTelemetryLoggerOptions AddMyExporter(this OpenTelemetryLoggerOptions options) + { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + return options.AddProcessor(new BatchExportProcessor(new MyExporter())); + } } diff --git a/docs/logs/getting-started/MyExporter.cs b/docs/logs/getting-started/MyExporter.cs new file mode 100644 index 00000000000..45a09149ec9 --- /dev/null +++ b/docs/logs/getting-started/MyExporter.cs @@ -0,0 +1,63 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Diagnostics; +using System.Text; +using OpenTelemetry; +using OpenTelemetry.Logs; + +internal class MyExporter : BaseExporter +{ + private readonly string name; + + public MyExporter(string name = "MyExporter") + { + this.name = name; + } + + public override ExportResult Export(in Batch batch) + { + // SuppressInstrumentationScope should be used to prevent exporter + // code from generating telemetry and causing live-loop. + using var scope = SuppressInstrumentationScope.Begin(); + + var sb = new StringBuilder(); + foreach (var record in batch) + { + if (sb.Length > 0) + { + sb.Append(", "); + } + + sb.Append(record.Timestamp.ToString()); + } + + Console.WriteLine($"{this.name}.Export([{sb.ToString()}])"); + return ExportResult.Success; + } + + protected override bool OnShutdown(int timeoutMilliseconds) + { + Console.WriteLine($"{this.name}.OnShutdown(timeoutMilliseconds={timeoutMilliseconds})"); + return true; + } + + protected override void Dispose(bool disposing) + { + Console.WriteLine($"{this.name}.Dispose({disposing})"); + } +} diff --git a/docs/logs/getting-started/MyProcessor.cs b/docs/logs/getting-started/MyProcessor.cs index e14ee2e5a9c..84112bd1c55 100644 --- a/docs/logs/getting-started/MyProcessor.cs +++ b/docs/logs/getting-started/MyProcessor.cs @@ -16,9 +16,10 @@ using System; using System.Collections.Generic; +using OpenTelemetry; using OpenTelemetry.Logs; -internal class MyProcessor : LogProcessor +internal class MyProcessor : BaseProcessor { private readonly string name; @@ -29,44 +30,12 @@ public MyProcessor(string name = "MyProcessor") public override void OnEnd(LogRecord record) { - var state = record.State; - - if (state is IReadOnlyCollection> dict) - { - var isUnstructuredLog = dict.Count == 1; - - if (isUnstructuredLog) - { - foreach (var entry in dict) - { - Console.WriteLine($"{record.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ} {record.CategoryName}({record.LogLevel}, Id={record.EventId}): {entry.Value}"); - } - } - else - { - Console.WriteLine($"{record.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ} {record.CategoryName}({record.LogLevel}, Id={record.EventId}):"); - foreach (var entry in dict) - { - if (string.Equals(entry.Key, "{OriginalFormat}", StringComparison.Ordinal)) - { - Console.WriteLine($" $format: {entry.Value}"); - continue; - } - - Console.WriteLine($" {entry.Key}: {entry.Value}"); - } - } - - if (record.Exception != null) - { - Console.WriteLine($" $exception: {record.Exception}"); - } - } + Console.WriteLine($"{this.name}.OnEnd({record})"); } protected override bool OnForceFlush(int timeoutMilliseconds) { - Console.WriteLine($"{this.name}.OnForceFlush({timeoutMilliseconds})"); + Console.WriteLine($"{this.name}.OnForceFlush()"); return true; } diff --git a/docs/logs/getting-started/Program.cs b/docs/logs/getting-started/Program.cs index 07e9eca1e25..017a5769180 100644 --- a/docs/logs/getting-started/Program.cs +++ b/docs/logs/getting-started/Program.cs @@ -30,7 +30,10 @@ public static void Main() using var loggerFactory = LoggerFactory.Create(builder => #endif { - builder.AddOpenTelemetry(options => options.AddProcessor(new MyProcessor())); + builder.AddOpenTelemetry(options => options + .AddProcessor(new MyProcessor("A")) + .AddProcessor(new MyProcessor("B")) + .AddMyExporter()); }); #if NETCOREAPP2_1 @@ -61,6 +64,8 @@ public static void Main() ["Name"] = "truffle", ["Price"] = 299.99, }); + + var p = new FoodProcessor(new PotatoExporter()); } internal struct Food @@ -69,4 +74,31 @@ internal struct Food public double Price { get; set; } } + + internal class Exporter + { + } + + internal class FoodExporter : Exporter + { + } + + internal class PotatoExporter : FoodExporter + { + } + + internal class Processor + { + public Processor(Exporter exporter) + { + } + } + + internal class FoodProcessor : Processor + { + public FoodProcessor(Exporter exporter) + : base(exporter) + { + } + } } diff --git a/docs/trace/extending-the-sdk/MyExporter.cs b/docs/trace/extending-the-sdk/MyExporter.cs index 7a3677b8f4c..c65bf9b37e6 100644 --- a/docs/trace/extending-the-sdk/MyExporter.cs +++ b/docs/trace/extending-the-sdk/MyExporter.cs @@ -20,7 +20,7 @@ using OpenTelemetry; using OpenTelemetry.Trace; -internal class MyExporter : ActivityExporter +internal class MyExporter : BaseExporter { private readonly string name; diff --git a/docs/trace/extending-the-sdk/MyExporterHelperExtensions.cs b/docs/trace/extending-the-sdk/MyExporterHelperExtensions.cs index 8385f6783d2..e35ac0f4531 100644 --- a/docs/trace/extending-the-sdk/MyExporterHelperExtensions.cs +++ b/docs/trace/extending-the-sdk/MyExporterHelperExtensions.cs @@ -15,6 +15,8 @@ // using System; +using System.Diagnostics; +using OpenTelemetry; using OpenTelemetry.Trace; internal static class MyExporterHelperExtensions @@ -26,6 +28,6 @@ public static TracerProviderBuilder AddMyExporter(this TracerProviderBuilder bui throw new ArgumentNullException(nameof(builder)); } - return builder.AddProcessor(new BatchExportActivityProcessor(new MyExporter())); + return builder.AddProcessor(new BatchExportProcessor(new MyExporter())); } } diff --git a/docs/trace/extending-the-sdk/MyProcessor.cs b/docs/trace/extending-the-sdk/MyProcessor.cs index 350c2dd2d4e..652154498bb 100644 --- a/docs/trace/extending-the-sdk/MyProcessor.cs +++ b/docs/trace/extending-the-sdk/MyProcessor.cs @@ -16,9 +16,9 @@ using System; using System.Diagnostics; -using OpenTelemetry.Trace; +using OpenTelemetry; -internal class MyProcessor : ActivityProcessor +internal class MyProcessor : BaseProcessor { private readonly string name; diff --git a/docs/trace/extending-the-sdk/Program.cs b/docs/trace/extending-the-sdk/Program.cs index 5d018e6dd63..c099ab6e877 100644 --- a/docs/trace/extending-the-sdk/Program.cs +++ b/docs/trace/extending-the-sdk/Program.cs @@ -29,7 +29,7 @@ public static void Main() .AddSource("OTel.Demo") .AddProcessor(new MyProcessor("ProcessorA")) .AddProcessor(new MyProcessor("ProcessorB")) - .AddProcessor(new SimpleExportActivityProcessor(new MyExporter("ExporterX"))) + .AddProcessor(new SimpleExportProcessor(new MyExporter("ExporterX"))) .AddMyExporter() .Build(); diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index d16cf9407bf..4962068e41c 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry /// /// Implements processor that exports telemetry objects. /// - /// The type of object to be exported. + /// The type of telemetry object to be exported. public abstract class BaseExportProcessor : BaseProcessor where T : class { diff --git a/src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs b/src/OpenTelemetry/BatchExportProcessor.cs similarity index 86% rename from src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs rename to src/OpenTelemetry/BatchExportProcessor.cs index 62fe1028787..c38f7ec0fd4 100644 --- a/src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs +++ b/src/OpenTelemetry/BatchExportProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,14 +19,16 @@ using System.Threading; using OpenTelemetry.Internal; -namespace OpenTelemetry.Trace +namespace OpenTelemetry { /// - /// Implements processor that batches activities before calling exporter. + /// Implements processor that batches telemetry objects before calling exporter. /// - public class BatchExportActivityProcessor : BaseExportProcessor + /// The type of telemetry object to be exported. + public class BatchExportProcessor : BaseExportProcessor + where T : class { - private readonly CircularBuffer circularBuffer; + private readonly CircularBuffer circularBuffer; private readonly int scheduledDelayMilliseconds; private readonly int exporterTimeoutMilliseconds; private readonly int maxExportBatchSize; @@ -38,15 +40,15 @@ public class BatchExportActivityProcessor : BaseExportProcessor private long droppedCount; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Exporter instance. /// The maximum queue size. After the size is reached data are dropped. The default value is 2048. /// The delay interval in milliseconds between two consecutive exports. The default value is 5000. /// How long the export can run before it is cancelled. The default value is 30000. /// The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512. - public BatchExportActivityProcessor( - ActivityExporter exporter, + public BatchExportProcessor( + BaseExporter exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, @@ -73,37 +75,37 @@ public BatchExportActivityProcessor( throw new ArgumentOutOfRangeException(nameof(exporterTimeoutMilliseconds)); } - this.circularBuffer = new CircularBuffer(maxQueueSize); + this.circularBuffer = new CircularBuffer(maxQueueSize); this.scheduledDelayMilliseconds = scheduledDelayMilliseconds; this.exporterTimeoutMilliseconds = exporterTimeoutMilliseconds; this.maxExportBatchSize = maxExportBatchSize; this.exporterThread = new Thread(new ThreadStart(this.ExporterProc)) { IsBackground = true, - Name = $"OpenTelemetry-{nameof(BatchExportActivityProcessor)}-{exporter.GetType().Name}", + Name = $"OpenTelemetry-{nameof(BatchExportProcessor)}-{exporter.GetType().Name}", }; this.exporterThread.Start(); } /// - /// Gets the number of objects dropped by the processor. + /// Gets the number of telemetry objects dropped by the processor. /// internal long DroppedCount => this.droppedCount; /// - /// Gets the number of objects received by the processor. + /// Gets the number of telemetry objects received by the processor. /// internal long ReceivedCount => this.circularBuffer.AddedCount + this.DroppedCount; /// - /// Gets the number of objects processed by the underlying exporter. + /// Gets the number of telemetry objects processed by the underlying exporter. /// internal long ProcessedCount => this.circularBuffer.RemovedCount; /// - public override void OnEnd(Activity activity) + public override void OnEnd(T data) { - if (this.circularBuffer.TryAdd(activity, maxSpinCount: 50000)) + if (this.circularBuffer.TryAdd(data, maxSpinCount: 50000)) { if (this.circularBuffer.Count >= this.maxExportBatchSize) { @@ -210,7 +212,7 @@ private void ExporterProc() if (this.circularBuffer.Count > 0) { - this.exporter.Export(new Batch(this.circularBuffer, this.maxExportBatchSize)); + this.exporter.Export(new Batch(this.circularBuffer, this.maxExportBatchSize)); this.dataExportedNotification.Set(); this.dataExportedNotification.Reset(); diff --git a/src/OpenTelemetry/Trace/CompositeActivityProcessor.cs b/src/OpenTelemetry/CompositeProcessor.cs similarity index 80% rename from src/OpenTelemetry/Trace/CompositeActivityProcessor.cs rename to src/OpenTelemetry/CompositeProcessor.cs index 76d18ffde94..afef1b69603 100644 --- a/src/OpenTelemetry/Trace/CompositeActivityProcessor.cs +++ b/src/OpenTelemetry/CompositeProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,15 +20,15 @@ using System.Threading; using OpenTelemetry.Internal; -namespace OpenTelemetry.Trace +namespace OpenTelemetry { - public class CompositeActivityProcessor : ActivityProcessor + public class CompositeProcessor : BaseProcessor { - private DoublyLinkedListNode head; - private DoublyLinkedListNode tail; + private DoublyLinkedListNode> head; + private DoublyLinkedListNode> tail; private bool disposed; - public CompositeActivityProcessor(IEnumerable processors) + public CompositeProcessor(IEnumerable> processors) { if (processors == null) { @@ -42,7 +42,7 @@ public CompositeActivityProcessor(IEnumerable processors) throw new ArgumentException($"{nameof(processors)} collection is empty"); } - this.head = new DoublyLinkedListNode(iter.Current); + this.head = new DoublyLinkedListNode>(iter.Current); this.tail = this.head; while (iter.MoveNext()) @@ -51,14 +51,14 @@ public CompositeActivityProcessor(IEnumerable processors) } } - public CompositeActivityProcessor AddProcessor(ActivityProcessor processor) + public CompositeProcessor AddProcessor(BaseProcessor processor) { if (processor == null) { throw new ArgumentNullException(nameof(processor)); } - var node = new DoublyLinkedListNode(processor) + var node = new DoublyLinkedListNode>(processor) { Previous = this.tail, }; @@ -69,25 +69,25 @@ public CompositeActivityProcessor AddProcessor(ActivityProcessor processor) } /// - public override void OnEnd(Activity activity) + public override void OnEnd(T data) { var cur = this.head; while (cur != null) { - cur.Value.OnEnd(activity); + cur.Value.OnEnd(data); cur = cur.Next; } } /// - public override void OnStart(Activity activity) + public override void OnStart(T data) { var cur = this.head; while (cur != null) { - cur.Value.OnStart(activity); + cur.Value.OnStart(data); cur = cur.Next; } } @@ -184,18 +184,18 @@ protected override void Dispose(bool disposing) this.disposed = true; } - private class DoublyLinkedListNode + private class DoublyLinkedListNode { - public readonly T Value; + public readonly T2 Value; - public DoublyLinkedListNode(T value) + public DoublyLinkedListNode(T2 value) { this.Value = value; } - public DoublyLinkedListNode Previous { get; set; } + public DoublyLinkedListNode Previous { get; set; } - public DoublyLinkedListNode Next { get; set; } + public DoublyLinkedListNode Next { get; set; } } } } diff --git a/src/OpenTelemetry/Logs/CompositeLogProcessor.cs b/src/OpenTelemetry/Logs/CompositeLogProcessor.cs deleted file mode 100644 index 987648cf1e7..00000000000 --- a/src/OpenTelemetry/Logs/CompositeLogProcessor.cs +++ /dev/null @@ -1,191 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#if NETSTANDARD2_0 -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; -using OpenTelemetry.Internal; - -namespace OpenTelemetry.Logs -{ - public class CompositeLogProcessor : LogProcessor - { - private DoublyLinkedListNode head; - private DoublyLinkedListNode tail; - private bool disposed; - - public CompositeLogProcessor(IEnumerable processors) - { - if (processors == null) - { - throw new ArgumentNullException(nameof(processors)); - } - - using var iter = processors.GetEnumerator(); - - if (!iter.MoveNext()) - { - throw new ArgumentException($"{nameof(processors)} collection is empty"); - } - - this.head = new DoublyLinkedListNode(iter.Current); - this.tail = this.head; - - while (iter.MoveNext()) - { - this.AddProcessor(iter.Current); - } - } - - public CompositeLogProcessor AddProcessor(LogProcessor processor) - { - if (processor == null) - { - throw new ArgumentNullException(nameof(processor)); - } - - var node = new DoublyLinkedListNode(processor) - { - Previous = this.tail, - }; - this.tail.Next = node; - this.tail = node; - - return this; - } - - /// - public override void OnEnd(LogRecord record) - { - var cur = this.head; - - while (cur != null) - { - cur.Value.OnEnd(record); - cur = cur.Next; - } - } - - /// - protected override bool OnForceFlush(int timeoutMilliseconds) - { - var cur = this.head; - - var sw = Stopwatch.StartNew(); - - while (cur != null) - { - if (timeoutMilliseconds == Timeout.Infinite) - { - _ = cur.Value.ForceFlush(Timeout.Infinite); - } - else - { - var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds; - - if (timeout <= 0) - { - return false; - } - - var succeeded = cur.Value.ForceFlush((int)timeout); - - if (!succeeded) - { - return false; - } - } - - cur = cur.Next; - } - - return true; - } - - /// - protected override bool OnShutdown(int timeoutMilliseconds) - { - var cur = this.head; - var result = true; - var sw = Stopwatch.StartNew(); - - while (cur != null) - { - if (timeoutMilliseconds == Timeout.Infinite) - { - result = cur.Value.Shutdown(Timeout.Infinite) && result; - } - else - { - var timeout = timeoutMilliseconds - sw.ElapsedMilliseconds; - - // notify all the processors, even if we run overtime - result = cur.Value.Shutdown((int)Math.Max(timeout, 0)) && result; - } - - cur = cur.Next; - } - - return result; - } - - protected override void Dispose(bool disposing) - { - if (this.disposed) - { - return; - } - - if (disposing) - { - var cur = this.head; - - while (cur != null) - { - try - { - cur.Value?.Dispose(); - } - catch (Exception ex) - { - OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.Dispose), ex); - } - - cur = cur.Next; - } - } - - this.disposed = true; - } - - private class DoublyLinkedListNode - { - public readonly T Value; - - public DoublyLinkedListNode(T value) - { - this.Value = value; - } - - public DoublyLinkedListNode Previous { get; set; } - - public DoublyLinkedListNode Next { get; set; } - } - } -} -#endif diff --git a/src/OpenTelemetry/Logs/LogProcessor.cs b/src/OpenTelemetry/Logs/LogProcessor.cs deleted file mode 100644 index 3b3753459c3..00000000000 --- a/src/OpenTelemetry/Logs/LogProcessor.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#if NETSTANDARD2_0 -namespace OpenTelemetry.Logs -{ - /// - /// Log processor base class. - /// - public abstract class LogProcessor : BaseProcessor - { - /// - public sealed override void OnStart(LogRecord record) - { - } - } -} -#endif diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs index 46d65077e7f..b0a99586ca1 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs @@ -23,14 +23,14 @@ namespace OpenTelemetry.Logs { public class OpenTelemetryLoggerOptions { - internal readonly List Processors = new List(); + internal readonly List> Processors = new List>(); /// /// Adds processor to the options. /// /// Log processor to add. /// Returns for chaining. - public OpenTelemetryLoggerOptions AddProcessor(LogProcessor processor) + public OpenTelemetryLoggerOptions AddProcessor(BaseProcessor processor) { if (processor == null) { diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs index 683dad75e58..47ac2b86325 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs @@ -25,7 +25,7 @@ namespace OpenTelemetry.Logs [ProviderAlias("OpenTelemetry")] public class OpenTelemetryLoggerProvider : ILoggerProvider, ISupportExternalScope { - internal LogProcessor Processor; + internal BaseProcessor Processor; private readonly OpenTelemetryLoggerOptions options; private readonly IDictionary loggers; private bool disposed; @@ -90,7 +90,7 @@ public void Dispose() GC.SuppressFinalize(this); } - internal OpenTelemetryLoggerProvider AddProcessor(LogProcessor processor) + internal OpenTelemetryLoggerProvider AddProcessor(BaseProcessor processor) { if (processor == null) { @@ -101,13 +101,13 @@ internal OpenTelemetryLoggerProvider AddProcessor(LogProcessor processor) { this.Processor = processor; } - else if (this.Processor is CompositeLogProcessor compositeProcessor) + else if (this.Processor is CompositeProcessor compositeProcessor) { compositeProcessor.AddProcessor(processor); } else { - this.Processor = new CompositeLogProcessor(new[] + this.Processor = new CompositeProcessor(new[] { this.Processor, processor, diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs index bc44746b855..dbd03989b68 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggingExtensions.cs @@ -20,6 +20,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Configuration; +using OpenTelemetry; using OpenTelemetry.Logs; namespace Microsoft.Extensions.Logging diff --git a/src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs b/src/OpenTelemetry/ReentrantExportProcessor.cs similarity index 63% rename from src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs rename to src/OpenTelemetry/ReentrantExportProcessor.cs index 8ba137650e7..bceb1789f96 100644 --- a/src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs +++ b/src/OpenTelemetry/ReentrantExportProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,28 +18,30 @@ using System.Diagnostics; using OpenTelemetry.Internal; -namespace OpenTelemetry.Trace +namespace OpenTelemetry { /// - /// Implements activity processor that exports at each OnEnd call without synchronization. + /// Implements processor that exports telemetry data at each OnEnd call without synchronization. /// - public class ReentrantExportActivityProcessor : BaseExportProcessor + /// The type of telemetry object to be exported. + public class ReentrantExportProcessor : BaseExportProcessor + where T : class { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Activity exporter instance. - public ReentrantExportActivityProcessor(ActivityExporter exporter) + /// Exporter instance. + public ReentrantExportProcessor(BaseExporter exporter) : base(exporter) { } /// - public override void OnEnd(Activity activity) + public override void OnEnd(T data) { try { - this.exporter.Export(new Batch(activity)); + this.exporter.Export(new Batch(data)); } catch (Exception ex) { diff --git a/src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs b/src/OpenTelemetry/SimpleExportProcessor.cs similarity index 67% rename from src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs rename to src/OpenTelemetry/SimpleExportProcessor.cs index cd073218450..47872fb84f8 100644 --- a/src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs +++ b/src/OpenTelemetry/SimpleExportProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,35 +15,36 @@ // using System; -using System.Diagnostics; using OpenTelemetry.Internal; -namespace OpenTelemetry.Trace +namespace OpenTelemetry { /// - /// Implements activity processor that exports at each OnEnd call. + /// Implements processor that exports telemetry data at each OnEnd call. /// - public class SimpleExportActivityProcessor : BaseExportProcessor + /// The type of telemetry object to be exported. + public class SimpleExportProcessor : BaseExportProcessor + where T : class { private readonly object syncObject = new object(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Activity exporter instance. - public SimpleExportActivityProcessor(ActivityExporter exporter) + /// Exporter instance. + public SimpleExportProcessor(BaseExporter exporter) : base(exporter) { } /// - public override void OnEnd(Activity activity) + public override void OnEnd(T data) { lock (this.syncObject) { try { - this.exporter.Export(new Batch(activity)); + this.exporter.Export(new Batch(data)); } catch (Exception ex) { diff --git a/src/OpenTelemetry/Trace/ActivityExporter.cs b/src/OpenTelemetry/Trace/ActivityExporter.cs deleted file mode 100644 index 8fce68a8acb..00000000000 --- a/src/OpenTelemetry/Trace/ActivityExporter.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using System.Diagnostics; - -namespace OpenTelemetry.Trace -{ - /// - /// Activity exporter base class. - /// - public abstract class ActivityExporter : BaseExporter - { - } -} diff --git a/src/OpenTelemetry/Trace/ActivityProcessor.cs b/src/OpenTelemetry/Trace/ActivityProcessor.cs deleted file mode 100644 index f671f4dd72a..00000000000 --- a/src/OpenTelemetry/Trace/ActivityProcessor.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using System.Diagnostics; - -namespace OpenTelemetry.Trace -{ - /// - /// Activity processor base class. - /// - public abstract class ActivityProcessor : BaseProcessor - { - } -} diff --git a/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs b/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs index e4c00e64ea1..448c86a6381 100644 --- a/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs +++ b/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs @@ -41,10 +41,10 @@ public class ActivitySourceAdapter private static readonly Action SetKindProperty = CreateActivityKindSetter(); private readonly Sampler sampler; private readonly Resource resource; - private ActivityProcessor activityProcessor; + private BaseProcessor activityProcessor; private Action getRequestedDataAction; - internal ActivitySourceAdapter(Sampler sampler, ActivityProcessor activityProcessor, Resource resource) + internal ActivitySourceAdapter(Sampler sampler, BaseProcessor activityProcessor, Resource resource) { this.sampler = sampler ?? throw new ArgumentNullException(nameof(sampler)); this.resource = resource ?? throw new ArgumentNullException(nameof(resource)); @@ -97,7 +97,7 @@ public void Stop(Activity activity) } } - internal void UpdateProcessor(ActivityProcessor processor) + internal void UpdateProcessor(BaseProcessor processor) { this.activityProcessor = processor; } diff --git a/src/OpenTelemetry/Trace/TracerProviderBuilder.cs b/src/OpenTelemetry/Trace/TracerProviderBuilder.cs index c1113a8691e..46c31fdec26 100644 --- a/src/OpenTelemetry/Trace/TracerProviderBuilder.cs +++ b/src/OpenTelemetry/Trace/TracerProviderBuilder.cs @@ -15,6 +15,7 @@ // using System; using System.Collections.Generic; +using System.Diagnostics; using OpenTelemetry.Resources; namespace OpenTelemetry.Trace @@ -25,7 +26,7 @@ namespace OpenTelemetry.Trace public class TracerProviderBuilder { private readonly List instrumentationFactories = new List(); - private readonly List processors = new List(); + private readonly List> processors = new List>(); private readonly List sources = new List(); private Resource resource = Resource.Empty; private Sampler sampler = new ParentBasedSampler(new AlwaysOnSampler()); @@ -98,7 +99,7 @@ public TracerProviderBuilder AddSource(params string[] names) /// /// Activity processor to add. /// Returns for chaining. - public TracerProviderBuilder AddProcessor(ActivityProcessor processor) + public TracerProviderBuilder AddProcessor(BaseProcessor processor) { if (processor == null) { diff --git a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs index d47ea6e77bd..f503cb59f97 100644 --- a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs +++ b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs @@ -15,12 +15,13 @@ // using System; +using System.Diagnostics; namespace OpenTelemetry.Trace { public static class TracerProviderExtensions { - public static TracerProvider AddProcessor(this TracerProvider provider, ActivityProcessor processor) + public static TracerProvider AddProcessor(this TracerProvider provider, BaseProcessor processor) { if (provider == null) { diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index ed1aa751b33..0cf17affc2f 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -30,7 +30,7 @@ internal class TracerProviderSdk : TracerProvider private readonly ActivityListener listener; private readonly Resource resource; private readonly Sampler sampler; - private ActivityProcessor processor; + private BaseProcessor processor; private ActivitySourceAdapter adapter; static TracerProviderSdk() @@ -44,7 +44,7 @@ internal TracerProviderSdk( IEnumerable sources, IEnumerable instrumentationFactories, Sampler sampler, - List processors) + List> processors) { this.resource = resource; this.sampler = sampler; @@ -157,7 +157,7 @@ internal TracerProviderSdk( this.listener = listener; } - internal TracerProviderSdk AddProcessor(ActivityProcessor processor) + internal TracerProviderSdk AddProcessor(BaseProcessor processor) { if (processor == null) { @@ -168,13 +168,13 @@ internal TracerProviderSdk AddProcessor(ActivityProcessor processor) { this.processor = processor; } - else if (this.processor is CompositeActivityProcessor compositeProcessor) + else if (this.processor is CompositeProcessor compositeProcessor) { compositeProcessor.AddProcessor(processor); } else { - this.processor = new CompositeActivityProcessor(new[] + this.processor = new CompositeProcessor(new[] { this.processor, processor, From c9c74608881c150fe29c824e0fac0a42303f4d54 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 21:58:29 -0700 Subject: [PATCH 03/11] update dependencies --- docs/trace/extending-the-sdk/README.md | 16 ++++++++-------- .../ConsoleExporter.cs | 3 ++- .../JaegerExporter.cs | 3 ++- .../OtlpExporter.cs | 3 ++- .../ZPagesExporter.cs | 3 ++- .../ZipkinExporter.cs | 3 ++- .../Shared/TestActivityExporter.cs | 3 ++- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/trace/extending-the-sdk/README.md b/docs/trace/extending-the-sdk/README.md index 75b861d19d7..ec3ca486242 100644 --- a/docs/trace/extending-the-sdk/README.md +++ b/docs/trace/extending-the-sdk/README.md @@ -18,7 +18,7 @@ OpenTelemetry .NET SDK has provided the following built-in exporters: Custom exporters can be implemented to send telemetry data to places which are not covered by the built-in exporters: -* Exporters should derive from `OpenTelemetry.Trace.ActivityExporter` (which +* Exporters should derive from `OpenTelemetry.BaseExporter` (which belongs to the [OpenTelemetry](../../../src/OpenTelemetry/README.md) package) and implement the `Export` method. * Exporters can optionally implement the `OnShutdown` method. @@ -34,7 +34,7 @@ not covered by the built-in exporters: done via `OpenTelemetry.SuppressInstrumentationScope`. ```csharp -class MyExporter : ActivityExporter +class MyExporter : BaseExporter { public override ExportResult Export(in Batch batch) { @@ -65,14 +65,14 @@ TBD OpenTelemetry .NET SDK has provided the following built-in processors: -* [BatchExportActivityProcessor](../../../src/OpenTelemetry/Trace/BatchExportActivityProcessor.cs) -* [CompositeActivityProcessor](../../../src/OpenTelemetry/Trace/CompositeActivityProcessor.cs) -* [ReentrantExportActivityProcessor](../../../src/OpenTelemetry/Trace/ReentrantExportActivityProcessor.cs) -* [SimpleExportActivityProcessor](../../../src/OpenTelemetry/Trace/SimpleExportActivityProcessor.cs) +* [BatchExportProcessor](../../../src/OpenTelemetry/BatchExportProcessor.cs) +* [CompositeProcessor](../../../src/OpenTelemetry/CompositeProcessor.cs) +* [ReentrantExportProcessor](../../../src/OpenTelemetry/ReentrantExportProcessor.cs) +* [SimpleExportProcessor](../../../src/OpenTelemetry/SimpleExportProcessor.cs) Custom processors can be implemented to cover more scenarios: -* Processors should inherit from `OpenTelemetry.Trace.ActivityProcessor` (which +* Processors should inherit from `OpenTelemetry.BaseProcessor` (which belongs to the [OpenTelemetry](../../../src/OpenTelemetry/README.md) package), and implement the `OnStart` and `OnEnd` methods. * Processors can optionally implement the `OnForceFlush` and `OnShutdown` @@ -83,7 +83,7 @@ Custom processors can be implemented to cover more scenarios: time, since they will be called on critical code path. ```csharp -class MyProcessor : ActivityProcessor +class MyProcessor : BaseProcessor { public override void OnStart(Activity activity) { diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs index c73fc11270e..31ffc1ed7cb 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs @@ -19,12 +19,13 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; +using OpenTelemetry; using OpenTelemetry.Resources; using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter.Console { - public class ConsoleExporter : ActivityExporter + public class ConsoleExporter : BaseExporter { private readonly JsonSerializerOptions serializerOptions; private readonly bool displayAsJson; diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 24cbd7f781a..7178ed9d6bc 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -20,6 +20,7 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; +using OpenTelemetry; using OpenTelemetry.Exporter.Jaeger.Implementation; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -28,7 +29,7 @@ namespace OpenTelemetry.Exporter.Jaeger { - public class JaegerExporter : ActivityExporter + public class JaegerExporter : BaseExporter { private readonly int maxPayloadSizeInBytes; private readonly TProtocolFactory protocolFactory; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs index 4e39e30979b..363f2ed4ae3 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; using Grpc.Core; +using OpenTelemetry; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Trace; using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1; @@ -28,7 +29,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol /// Exporter consuming and exporting the data using /// the OpenTelemetry protocol (OTLP). /// - public class OtlpExporter : ActivityExporter + public class OtlpExporter : BaseExporter { private readonly Channel channel; private readonly OtlpCollector.TraceService.TraceServiceClient traceClient; diff --git a/src/OpenTelemetry.Exporter.ZPages/ZPagesExporter.cs b/src/OpenTelemetry.Exporter.ZPages/ZPagesExporter.cs index ab026895839..066f068a5fd 100644 --- a/src/OpenTelemetry.Exporter.ZPages/ZPagesExporter.cs +++ b/src/OpenTelemetry.Exporter.ZPages/ZPagesExporter.cs @@ -17,6 +17,7 @@ using System; using System.Diagnostics; using System.Timers; +using OpenTelemetry; using OpenTelemetry.Exporter.ZPages.Implementation; using OpenTelemetry.Trace; using Timer = System.Timers.Timer; @@ -26,7 +27,7 @@ namespace OpenTelemetry.Exporter.ZPages /// /// Implements ZPages exporter. /// - public class ZPagesExporter : ActivityExporter + public class ZPagesExporter : BaseExporter { internal readonly ZPagesExporterOptions Options; private readonly Timer minuteTimer; diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index 384ed457d10..f2336380923 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -28,6 +28,7 @@ #endif using System.Threading; using System.Threading.Tasks; +using OpenTelemetry; using OpenTelemetry.Exporter.Zipkin.Implementation; using OpenTelemetry.Trace; @@ -36,7 +37,7 @@ namespace OpenTelemetry.Exporter.Zipkin /// /// Zipkin exporter. /// - public class ZipkinExporter : ActivityExporter + public class ZipkinExporter : BaseExporter { private readonly ZipkinExporterOptions options; #if !NET452 diff --git a/test/OpenTelemetry.Tests/Shared/TestActivityExporter.cs b/test/OpenTelemetry.Tests/Shared/TestActivityExporter.cs index d9bb3c5e718..b68c64f610a 100644 --- a/test/OpenTelemetry.Tests/Shared/TestActivityExporter.cs +++ b/test/OpenTelemetry.Tests/Shared/TestActivityExporter.cs @@ -16,11 +16,12 @@ using System.Collections.Concurrent; using System.Diagnostics; +using OpenTelemetry; using OpenTelemetry.Trace; namespace OpenTelemetry.Tests.Shared { - internal class TestActivityExporter : ActivityExporter + internal class TestActivityExporter : BaseExporter { internal readonly BlockingCollection Exported = new BlockingCollection(); private bool disposed; From fd8dee124eecde78d29db034460ef64cbe2590a3 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 22:19:01 -0700 Subject: [PATCH 04/11] update all the tests and docs --- examples/Console/TestConsoleExporter.cs | 2 +- .../ConsoleExporterHelperExtensions.cs | 3 ++- .../JaegerExporterHelperExtensions.cs | 3 ++- .../OtlpExporterHelperExtensions.cs | 3 ++- .../ZPagesProcessor.cs | 2 +- .../ZipkinExporterHelperExtensions.cs | 3 ++- .../README.md | 4 ++-- .../README.md | 6 +++--- .../{Tracing => Logs}/LogBenchmarks.cs | 2 +- test/Benchmarks/Tracing/TraceBenchmarks.cs | 2 +- .../Benchmarks/Tracing/TraceShimBenchmarks.cs | 2 +- .../ZipkinExporterTests.cs | 4 ++-- .../HttpInListenerTests.cs | 2 +- .../BasicTests.cs | 12 +++++------ ...stsCollectionsIsAccordingToTheSpecTests.cs | 2 +- .../GrpcFixture.cs | 4 +++- .../GrpcTests.client.cs | 6 +++--- .../GrpcTests.server.cs | 2 +- .../HttpClientTests.Basic.netcore31.cs | 16 +++++++-------- .../HttpClientTests.netcore31.cs | 4 ++-- .../HttpWebRequestTests.Basic.netfx.cs | 10 +++++----- .../HttpWebRequestTests.netfx.cs | 2 +- .../SqlClientTests.cs | 6 +++--- .../SqlEventSourceTests.netfx.cs | 8 ++++---- ...kExchangeRedisCallsInstrumentationTests.cs | 4 ++-- .../Shared/TestActivityProcessor.cs | 2 +- .../Trace/BatchExportActivityProcessorTest.cs | 20 +++++++++---------- .../Trace/CompositeActivityProcessorTests.cs | 14 ++++++------- .../ReentrantExportActivityProcessorTest.cs | 8 ++++---- .../SimpleExportActivityProcessorTest.cs | 8 ++++---- 30 files changed, 86 insertions(+), 80 deletions(-) rename test/Benchmarks/{Tracing => Logs}/LogBenchmarks.cs (97%) diff --git a/examples/Console/TestConsoleExporter.cs b/examples/Console/TestConsoleExporter.cs index 31b001e33bb..7ef9d24f766 100644 --- a/examples/Console/TestConsoleExporter.cs +++ b/examples/Console/TestConsoleExporter.cs @@ -98,7 +98,7 @@ internal static object Run(ConsoleOptions options) return null; } - internal class MyProcessor : ActivityProcessor + internal class MyProcessor : BaseProcessor { public override void OnStart(Activity activity) { diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs index 3013c1e7aba..aa7b2aeef00 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporterHelperExtensions.cs @@ -15,6 +15,7 @@ // using System; +using System.Diagnostics; using OpenTelemetry.Exporter.Console; namespace OpenTelemetry.Trace @@ -37,7 +38,7 @@ public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilde var options = new ConsoleExporterOptions(); configure?.Invoke(options); - return builder.AddProcessor(new SimpleExportActivityProcessor(new ConsoleExporter(options))); + return builder.AddProcessor(new SimpleExportProcessor(new ConsoleExporter(options))); } } } diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs index 1212bc00d7b..0837a542928 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs @@ -15,6 +15,7 @@ // using System; +using System.Diagnostics; using OpenTelemetry.Exporter.Jaeger; namespace OpenTelemetry.Trace @@ -43,7 +44,7 @@ public static TracerProviderBuilder AddJaegerExporter(this TracerProviderBuilder var jaegerExporter = new JaegerExporter(exporterOptions); // TODO: Pick Simple vs Batching based on JaegerExporterOptions - return builder.AddProcessor(new BatchExportActivityProcessor(jaegerExporter)); + return builder.AddProcessor(new BatchExportProcessor(jaegerExporter)); } } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs index 06afb26e652..fc868c266f0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterHelperExtensions.cs @@ -15,6 +15,7 @@ // using System; +using System.Diagnostics; using OpenTelemetry.Exporter.OpenTelemetryProtocol; namespace OpenTelemetry.Trace @@ -43,7 +44,7 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b var otlpExporter = new OtlpExporter(exporterOptions); // TODO: Pick Simple vs Batching based on OtlpExporterOptions - return builder.AddProcessor(new BatchExportActivityProcessor(otlpExporter)); + return builder.AddProcessor(new BatchExportProcessor(otlpExporter)); } } } diff --git a/src/OpenTelemetry.Exporter.ZPages/ZPagesProcessor.cs b/src/OpenTelemetry.Exporter.ZPages/ZPagesProcessor.cs index 5aca956d730..907f6a8fa15 100644 --- a/src/OpenTelemetry.Exporter.ZPages/ZPagesProcessor.cs +++ b/src/OpenTelemetry.Exporter.ZPages/ZPagesProcessor.cs @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.ZPages /// /// Implements the zpages span processor that exports spans in OnEnd call without batching. /// - public class ZPagesProcessor : ActivityProcessor + public class ZPagesProcessor : BaseProcessor { private readonly ZPagesExporter exporter; diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs index c3e7af6a52e..19ad7df3e81 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterHelperExtensions.cs @@ -15,6 +15,7 @@ // using System; +using System.Diagnostics; using OpenTelemetry.Exporter.Zipkin; namespace OpenTelemetry.Trace @@ -43,7 +44,7 @@ public static TracerProviderBuilder AddZipkinExporter(this TracerProviderBuilder var zipkinExporter = new ZipkinExporter(exporterOptions); // TODO: Pick Simple vs Batching based on ZipkinExporterOptions - return builder.AddProcessor(new BatchExportActivityProcessor(zipkinExporter)); + return builder.AddProcessor(new BatchExportProcessor(zipkinExporter)); } } } diff --git a/src/OpenTelemetry.Instrumentation.AspNet/README.md b/src/OpenTelemetry.Instrumentation.AspNet/README.md index 9c8ea8b6afb..53e330a4529 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNet/README.md @@ -110,7 +110,7 @@ and the `Filter` option does the filtering *before* the Sampler is invoked. ### Special topic - Enriching automatically collected telemetry ASP.NET instrumentation stores the `HttpRequest`, `HttpResponse` objects in the -`Activity`. These can be accessed in ActivityProcessors, and can be used to +`Activity`. These can be accessed in `BaseProcessor`, and can be used to further enrich the Activity as shown below. The key name for HttpRequest custom property inside Activity is "OTel.AspNet.Request". @@ -118,7 +118,7 @@ The key name for HttpRequest custom property inside Activity is "OTel.AspNet.Req The key name for HttpResponse custom property inside Activity is "OTel.AspNet.Response". ```csharp -internal class MyAspNetEnrichingProcessor : ActivityProcessor +internal class MyAspNetEnrichingProcessor : BaseProcessor { public override void OnStart(Activity activity) { diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md index 73cd73ef84c..489c0cb2efb 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md @@ -95,8 +95,8 @@ and the `Filter` option does the filtering *before* the Sampler is invoked. ### Special topic - Enriching automatically collected telemetry This instrumentation library stores the raw `HttpRequest`, `HttpResponse` -objects in the activity. This can be accessed in ActivityProcessors, and can be -used to further enrich the Activity with additional tags as shown below. +objects in the activity. This can be accessed in `BaseProcessor`, and +can be used to further enrich the Activity with additional tags as shown below. The key name for HttpRequest custom property inside Activity is "OTel.AspNetCore.Request". @@ -105,7 +105,7 @@ The key name for HttpResponse custom property inside Activity is "OTel.AspNetCore.Response". ```csharp -internal class MyAspNetCoreEnrichingProcessor : ActivityProcessor +internal class MyAspNetCoreEnrichingProcessor : BaseProcessor { public override void OnStart(Activity activity) { diff --git a/test/Benchmarks/Tracing/LogBenchmarks.cs b/test/Benchmarks/Logs/LogBenchmarks.cs similarity index 97% rename from test/Benchmarks/Tracing/LogBenchmarks.cs rename to test/Benchmarks/Logs/LogBenchmarks.cs index 4a4b82707a1..feb06a53da3 100644 --- a/test/Benchmarks/Tracing/LogBenchmarks.cs +++ b/test/Benchmarks/Logs/LogBenchmarks.cs @@ -82,7 +82,7 @@ public void ThreeProcessors() this.loggerWithThreeProcessors.LogInformation("Hello, World!"); } - internal class DummyLogProcessor : LogProcessor + internal class DummyLogProcessor : BaseProcessor { } } diff --git a/test/Benchmarks/Tracing/TraceBenchmarks.cs b/test/Benchmarks/Tracing/TraceBenchmarks.cs index 75e8dbbe388..72c4b2e8265 100644 --- a/test/Benchmarks/Tracing/TraceBenchmarks.cs +++ b/test/Benchmarks/Tracing/TraceBenchmarks.cs @@ -140,7 +140,7 @@ public void ThreeProcessors() } } - internal class DummyActivityProcessor : ActivityProcessor + internal class DummyActivityProcessor : BaseProcessor { } } diff --git a/test/Benchmarks/Tracing/TraceShimBenchmarks.cs b/test/Benchmarks/Tracing/TraceShimBenchmarks.cs index 3adbc1eec42..3e8df28af0c 100644 --- a/test/Benchmarks/Tracing/TraceShimBenchmarks.cs +++ b/test/Benchmarks/Tracing/TraceShimBenchmarks.cs @@ -86,7 +86,7 @@ public void ThreeProcessors() } } - internal class DummyActivityProcessor : ActivityProcessor + internal class DummyActivityProcessor : BaseProcessor { } } diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index 47a56a0eb2f..e1ad27e3925 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -107,7 +107,7 @@ public void SuppresssesInstrumentation() exporterOptions.ServiceName = "test-zipkin"; exporterOptions.Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}"); var zipkinExporter = new ZipkinExporter(exporterOptions); - var exportActivityProcessor = new BatchExportActivityProcessor(zipkinExporter); + var exportActivityProcessor = new BatchExportProcessor(zipkinExporter); var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) @@ -145,7 +145,7 @@ public void IntegrationTest(bool useShortTraceIds) }); var activity = CreateTestActivity(); - var processor = new SimpleExportActivityProcessor(exporter); + var processor = new SimpleExportProcessor(exporter); processor.OnEnd(activity); diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs index 7c2bf8b8fd3..4d0f0bcb79a 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs @@ -137,7 +137,7 @@ public void AspNetRequestsAreCollectedSuccessfully( var activity = new Activity(ActivityNameAspNet).AddBaggage("Stuff", "123"); activity.SetParentId(expectedTraceId, expectedSpanId, ActivityTraceFlags.Recorded); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using (openTelemetry = Sdk.CreateTracerProviderBuilder() .AddAspNetInstrumentation( (options) => diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index bde752b8a9f..bf5429be45d 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -64,7 +64,7 @@ public void AddAspNetCoreInstrumentation_BadArgs() public async Task SuccessfulTemplateControllerCallGeneratesASpan(bool shouldEnrich) { var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); void ConfigureTestServices(IServiceCollection services) { this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() @@ -104,7 +104,7 @@ void ConfigureTestServices(IServiceCollection services) [Fact] public async Task SuccessfulTemplateControllerCallUsesParentContext() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); var expectedTraceId = ActivityTraceId.CreateRandom(); var expectedSpanId = ActivitySpanId.CreateRandom(); @@ -155,7 +155,7 @@ public async Task SuccessfulTemplateControllerCallUsesParentContext() [Fact] public async Task CustomPropagator() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); var expectedTraceId = ActivityTraceId.CreateRandom(); var expectedSpanId = ActivitySpanId.CreateRandom(); @@ -204,7 +204,7 @@ public async Task CustomPropagator() [Fact] public async Task RequestNotCollectedWhenFilterIsApplied() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); void ConfigureTestServices(IServiceCollection services) { @@ -243,7 +243,7 @@ void ConfigureTestServices(IServiceCollection services) [Fact] public async Task RequestNotCollectedWhenFilterThrowException() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); void ConfigureTestServices(IServiceCollection services) { @@ -298,7 +298,7 @@ public void Dispose() this.openTelemetrySdk?.Dispose(); } - private static void WaitForProcessorInvocations(Mock activityProcessor, int invocationCount) + private static void WaitForProcessorInvocations(Mock> activityProcessor, int invocationCount) { // We need to let End callback execute as it is executed AFTER response was returned. // In unit tests environment there may be a lot of parallel unit tests executed, so diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs index 2c87bc15100..802d43009ce 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs @@ -52,7 +52,7 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( int statusCode, string reasonPhrase) { - var processor = new Mock(); + var processor = new Mock>(); // Arrange using (var client = this.factory diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcFixture.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcFixture.cs index 92a4a63d340..729a5041cb6 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcFixture.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcFixture.cs @@ -13,7 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. // + using System; +using System.Diagnostics; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; @@ -61,7 +63,7 @@ public GrpcFixture() public int Port { get; } - public Mock GrpcServerSpanProcessor { get; } = new Mock(); + public Mock> GrpcServerSpanProcessor { get; } = new Mock>(); public void Dispose() { diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index 01bbdd0bcd3..48a0f5aea5e 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -43,7 +43,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho var uriHostNameType = Uri.CheckHostName(uri.Host); var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - var processor = new Mock(); + var processor = new Mock>(); var parent = new Activity("parent") .Start(); @@ -107,7 +107,7 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) { var uri = new Uri($"http://localhost:{this.fixture.Port}"); var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - var processor = new Mock(); + var processor = new Mock>(); var parent = new Activity("parent") .Start(); @@ -148,7 +148,7 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool sho { var uri = new Uri($"http://localhost:{this.fixture.Port}"); var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - var processor = new Mock(); + var processor = new Mock>(); var parent = new Activity("parent") .Start(); diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs index e4a711525a6..c399eb285db 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs @@ -74,7 +74,7 @@ public void GrpcAspNetCoreInstrumentationAddsCorrectAttributes() Assert.Null(activity.GetTagValue(GrpcTagHelper.GrpcStatusCodeTagName)); } - private static void WaitForProcessorInvocations(Mock spanProcessor, int invocationCount) + private static void WaitForProcessorInvocations(Mock> spanProcessor, int invocationCount) { // We need to let End callback execute as it is executed AFTER response was returned. // In unit tests environment there may be a lot of parallel unit tests executed, so diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs index 915e99a277e..19eda57e71b 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs @@ -61,7 +61,7 @@ public void AddHttpClientInstrumentation_BadArgs() [InlineData(false)] public async Task HttpClientInstrumentationInjectsHeadersAsync(bool shouldEnrich) { - var processor = new Mock(); + var processor = new Mock>(); var request = new HttpRequestMessage { RequestUri = new Uri(this.url), @@ -141,7 +141,7 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync_CustomFormat(bool action(message, "custom_tracestate", Activity.Current.TraceStateString); }); - var processor = new Mock(); + var processor = new Mock>(); var request = new HttpRequestMessage { @@ -192,7 +192,7 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync_CustomFormat(bool [Fact] public async Task HttpClientInstrumentation_AddViaFactory_HttpInstrumentation_CollectsSpans() { - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation() @@ -211,7 +211,7 @@ public async Task HttpClientInstrumentation_AddViaFactory_HttpInstrumentation_Co [Fact] public async Task HttpClientInstrumentation_AddViaFactory_DependencyInstrumentation_CollectsSpans() { - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation() @@ -230,7 +230,7 @@ public async Task HttpClientInstrumentation_AddViaFactory_DependencyInstrumentat [Fact] public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented() { - var processor = new Mock(); + var processor = new Mock>(); var request = new HttpRequestMessage { @@ -255,7 +255,7 @@ public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented() [Fact] public async void RequestNotCollectedWhenInstrumentationFilterApplied() { - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation( (opt) => opt.Filter = (req) => !req.RequestUri.OriginalString.Contains(this.url)) @@ -272,7 +272,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterApplied() [Fact] public async void RequestNotCollectedWhenInstrumentationFilterThrowsException() { - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation( (opt) => opt.Filter = (req) => throw new Exception("From InstrumentationFilter")) @@ -293,7 +293,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterThrowsException() [Fact] public async Task HttpClientInstrumentationCorrelationAndBaggage() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var parent = new Activity("w3c activity"); parent.SetIdFormat(ActivityIdFormat.W3C); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs index 642358a01f5..bb4ee606e7f 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs @@ -51,7 +51,7 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut out var port); var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - var processor = new Mock(); + var processor = new Mock>(); tc.Url = HttpTestData.NormalizeValues(tc.Url, host, port); using (serverLifeTime) @@ -181,7 +181,7 @@ public async Task CheckEnrichmentWhenSampling() private static async Task CheckEnrichment(Sampler sampler, int expect) { Counter = 0; - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .SetSampler(sampler) .AddHttpClientInstrumentation(options => options.Enrich = ActivityEnrichmentCounter) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs index 648ed946781..2d63347ebd9 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs @@ -60,7 +60,7 @@ public void Dispose() [Fact] public async Task HttpWebRequestInstrumentationInjectsHeadersAsync() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpWebRequestInstrumentation() @@ -106,7 +106,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat( action(message, "custom_tracestate", Activity.Current.TraceStateString); }); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpWebRequestInstrumentation(options => options.Propagator = propagator.Object) @@ -145,7 +145,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat( [Fact] public async Task HttpWebRequestInstrumentationBacksOffIfAlreadyInstrumented() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpWebRequestInstrumentation() @@ -168,7 +168,7 @@ public async Task HttpWebRequestInstrumentationBacksOffIfAlreadyInstrumented() [Fact] public async Task RequestNotCollectedWhenInstrumentationFilterApplied() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpWebRequestInstrumentation( @@ -184,7 +184,7 @@ public async Task RequestNotCollectedWhenInstrumentationFilterApplied() [Fact] public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException() { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpWebRequestInstrumentation( diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs index 84289ffe0b4..309e4d8ea60 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs @@ -47,7 +47,7 @@ public void HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOutTestCa out var port); var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .SetResource(expectedResource) .AddProcessor(activityProcessor.Object) diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index fefef2b47d4..b22872d1a17 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs @@ -82,7 +82,7 @@ public void SuccessfulCommandTest( bool isFailure = false, bool shouldEnrich = true) { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddSqlClientInstrumentation(options => @@ -145,7 +145,7 @@ public void SqlClientCallsAreCollectedSuccessfully( using var sqlConnection = new SqlConnection(TestConnectionString); using var sqlCommand = sqlConnection.CreateCommand(); - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddSqlClientInstrumentation( (opt) => @@ -209,7 +209,7 @@ public void SqlClientErrorsAreCollectedSuccessfully(string beforeCommand, string using var sqlConnection = new SqlConnection(TestConnectionString); using var sqlCommand = sqlConnection.CreateCommand(); - var processor = new Mock(); + var processor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddSqlClientInstrumentation(options => { diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs index 4ce4fa38406..d67b556e523 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs @@ -49,7 +49,7 @@ To use Docker... [InlineData(CommandType.StoredProcedure, "sp_who", true)] public async Task SuccessfulCommandTest(CommandType commandType, string commandText, bool captureText, bool isFailure = false) { - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddSqlClientInstrumentation(options => @@ -101,7 +101,7 @@ public void EventSourceFakeTests( { using FakeBehavingSqlEventSource fakeSqlEventSource = new FakeBehavingSqlEventSource(); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddSqlClientInstrumentation(options => @@ -140,7 +140,7 @@ public void EventSourceFakeUnknownEventWithNullPayloadTest() { using FakeMisbehavingSqlEventSource fakeSqlEventSource = new FakeMisbehavingSqlEventSource(); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddSqlClientInstrumentation() @@ -158,7 +158,7 @@ public void EventSourceFakeInvalidPayloadTest() { using FakeMisbehavingSqlEventSource fakeSqlEventSource = new FakeMisbehavingSqlEventSource(); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddSqlClientInstrumentation() diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index 6749fb52c48..fe8a6ed8cfd 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -53,7 +53,7 @@ public void SuccessfulCommandTest(string value) using var connection = ConnectionMultiplexer.Connect(connectionOptions); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); using (Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddRedisInstrumentation(connection) @@ -159,7 +159,7 @@ public void StackExchangeRedis_BadArgs() TracerProviderBuilder builder = null; Assert.Throws(() => builder.AddRedisInstrumentation(null)); - var activityProcessor = new Mock(); + var activityProcessor = new Mock>(); Assert.Throws(() => Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) diff --git a/test/OpenTelemetry.Tests/Shared/TestActivityProcessor.cs b/test/OpenTelemetry.Tests/Shared/TestActivityProcessor.cs index 8c7da98dba2..038de640ab3 100644 --- a/test/OpenTelemetry.Tests/Shared/TestActivityProcessor.cs +++ b/test/OpenTelemetry.Tests/Shared/TestActivityProcessor.cs @@ -20,7 +20,7 @@ namespace OpenTelemetry.Tests { - internal class TestActivityProcessor : ActivityProcessor + internal class TestActivityProcessor : BaseProcessor { public Action StartAction; public Action EndAction; diff --git a/test/OpenTelemetry.Tests/Trace/BatchExportActivityProcessorTest.cs b/test/OpenTelemetry.Tests/Trace/BatchExportActivityProcessorTest.cs index 33d2041e3fe..b6da7730905 100644 --- a/test/OpenTelemetry.Tests/Trace/BatchExportActivityProcessorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/BatchExportActivityProcessorTest.cs @@ -27,24 +27,24 @@ public class BatchExportActivityProcessorTest [Fact] public void CheckNullExporter() { - Assert.Throws(() => new BatchExportActivityProcessor(null)); + Assert.Throws(() => new BatchExportProcessor(null)); } [Fact] public void CheckConstructorWithInvalidValues() { - Assert.Throws(() => new BatchExportActivityProcessor(new TestActivityExporter(), maxQueueSize: 0)); - Assert.Throws(() => new BatchExportActivityProcessor(new TestActivityExporter(), maxExportBatchSize: 0)); - Assert.Throws(() => new BatchExportActivityProcessor(new TestActivityExporter(), maxQueueSize: 1, maxExportBatchSize: 2049)); - Assert.Throws(() => new BatchExportActivityProcessor(new TestActivityExporter(), scheduledDelayMilliseconds: 0)); - Assert.Throws(() => new BatchExportActivityProcessor(new TestActivityExporter(), exporterTimeoutMilliseconds: -1)); + Assert.Throws(() => new BatchExportProcessor(new TestActivityExporter(), maxQueueSize: 0)); + Assert.Throws(() => new BatchExportProcessor(new TestActivityExporter(), maxExportBatchSize: 0)); + Assert.Throws(() => new BatchExportProcessor(new TestActivityExporter(), maxQueueSize: 1, maxExportBatchSize: 2049)); + Assert.Throws(() => new BatchExportProcessor(new TestActivityExporter(), scheduledDelayMilliseconds: 0)); + Assert.Throws(() => new BatchExportProcessor(new TestActivityExporter(), exporterTimeoutMilliseconds: -1)); } [Fact] public void CheckIfBatchIsExportingOnQueueLimit() { using var exporter = new TestActivityExporter(); - using var processor = new BatchExportActivityProcessor( + using var processor = new BatchExportProcessor( exporter, maxQueueSize: 1, maxExportBatchSize: 1, @@ -68,7 +68,7 @@ public void CheckIfBatchIsExportingOnQueueLimit() public void CheckForceFlushWithInvalidTimeout() { using var exporter = new TestActivityExporter(); - using var processor = new BatchExportActivityProcessor(exporter, maxQueueSize: 2, maxExportBatchSize: 1); + using var processor = new BatchExportProcessor(exporter, maxQueueSize: 2, maxExportBatchSize: 1); Assert.Throws(() => processor.ForceFlush(-2)); } @@ -79,7 +79,7 @@ public void CheckForceFlushWithInvalidTimeout() public void CheckForceFlushExport(int timeout) { using var exporter = new TestActivityExporter(); - using var processor = new BatchExportActivityProcessor( + using var processor = new BatchExportProcessor( exporter, maxQueueSize: 3, maxExportBatchSize: 3, @@ -117,7 +117,7 @@ public void CheckForceFlushExport(int timeout) public void CheckShutdownExport(int timeout) { using var exporter = new TestActivityExporter(); - using var processor = new BatchExportActivityProcessor( + using var processor = new BatchExportProcessor( exporter, maxQueueSize: 3, maxExportBatchSize: 3, diff --git a/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs b/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs index 8192033c5d5..9446a1258a5 100644 --- a/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs +++ b/test/OpenTelemetry.Tests/Trace/CompositeActivityProcessorTests.cs @@ -27,11 +27,11 @@ public class CompositeActivityProcessorTests [Fact] public void CompositeActivityProcessor_BadArgs() { - Assert.Throws(() => new CompositeActivityProcessor(null)); - Assert.Throws(() => new CompositeActivityProcessor(new ActivityProcessor[0])); + Assert.Throws(() => new CompositeProcessor(null)); + Assert.Throws(() => new CompositeProcessor(new BaseProcessor[0])); using var p1 = new TestActivityProcessor(null, null); - using var processor = new CompositeActivityProcessor(new[] { p1 }); + using var processor = new CompositeProcessor(new[] { p1 }); Assert.Throws(() => processor.AddProcessor(null)); } @@ -49,7 +49,7 @@ public void CompositeActivityProcessor_CallsAllProcessorSequentially() var activity = new Activity("test"); - using (var processor = new CompositeActivityProcessor(new[] { p1, p2 })) + using (var processor = new CompositeProcessor(new[] { p1, p2 })) { processor.OnStart(activity); processor.OnEnd(activity); @@ -67,7 +67,7 @@ public void CompositeActivityProcessor_ProcessorThrows() var activity = new Activity("test"); - using (var processor = new CompositeActivityProcessor(new[] { p1 })) + using (var processor = new CompositeProcessor(new[] { p1 })) { Assert.Throws(() => { processor.OnStart(activity); }); Assert.Throws(() => { processor.OnEnd(activity); }); @@ -80,7 +80,7 @@ public void CompositeActivityProcessor_ShutsDownAll() using var p1 = new TestActivityProcessor(null, null); using var p2 = new TestActivityProcessor(null, null); - using (var processor = new CompositeActivityProcessor(new[] { p1, p2 })) + using (var processor = new CompositeProcessor(new[] { p1, p2 })) { processor.Shutdown(); Assert.True(p1.ShutdownCalled); @@ -97,7 +97,7 @@ public void CompositeActivityProcessor_ForceFlush(int timeout) using var p1 = new TestActivityProcessor(null, null); using var p2 = new TestActivityProcessor(null, null); - using (var processor = new CompositeActivityProcessor(new[] { p1, p2 })) + using (var processor = new CompositeProcessor(new[] { p1, p2 })) { processor.ForceFlush(timeout); diff --git a/test/OpenTelemetry.Tests/Trace/ReentrantExportActivityProcessorTest.cs b/test/OpenTelemetry.Tests/Trace/ReentrantExportActivityProcessorTest.cs index 1f69d9ae225..23785355e8c 100644 --- a/test/OpenTelemetry.Tests/Trace/ReentrantExportActivityProcessorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/ReentrantExportActivityProcessorTest.cs @@ -27,14 +27,14 @@ public class ReentrantExportActivityProcessorTest [Fact] public void CheckNullExporter() { - Assert.Throws(() => new ReentrantExportActivityProcessor(null)); + Assert.Throws(() => new ReentrantExportProcessor(null)); } [Fact] public void CheckExportedOnEnd() { using var exporter = new TestActivityExporter(); - using var processor = new ReentrantExportActivityProcessor(exporter); + using var processor = new ReentrantExportProcessor(exporter); processor.OnEnd(new Activity("start1")); Assert.Single(exporter.Exported); @@ -50,7 +50,7 @@ public void CheckExportedOnEnd() public void CheckForceFlushExport(int timeout) { using var exporter = new TestActivityExporter(); - using var processor = new ReentrantExportActivityProcessor(exporter); + using var processor = new ReentrantExportProcessor(exporter); processor.OnEnd(new Activity("start1")); processor.OnEnd(new Activity("start2")); @@ -70,7 +70,7 @@ public void CheckForceFlushExport(int timeout) public void CheckShutdownExport(int timeout) { using var exporter = new TestActivityExporter(); - using var processor = new ReentrantExportActivityProcessor(exporter); + using var processor = new ReentrantExportProcessor(exporter); processor.OnEnd(new Activity("start")); diff --git a/test/OpenTelemetry.Tests/Trace/SimpleExportActivityProcessorTest.cs b/test/OpenTelemetry.Tests/Trace/SimpleExportActivityProcessorTest.cs index b29c5723f1f..a59294b19e4 100644 --- a/test/OpenTelemetry.Tests/Trace/SimpleExportActivityProcessorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/SimpleExportActivityProcessorTest.cs @@ -27,14 +27,14 @@ public class SimpleExportActivityProcessorTest [Fact] public void CheckNullExporter() { - Assert.Throws(() => new SimpleExportActivityProcessor(null)); + Assert.Throws(() => new SimpleExportProcessor(null)); } [Fact] public void CheckExportedOnEnd() { using var exporter = new TestActivityExporter(); - using var processor = new SimpleExportActivityProcessor(exporter); + using var processor = new SimpleExportProcessor(exporter); processor.OnEnd(new Activity("start1")); Assert.Single(exporter.Exported); @@ -50,7 +50,7 @@ public void CheckExportedOnEnd() public void CheckForceFlushExport(int timeout) { using var exporter = new TestActivityExporter(); - using var processor = new SimpleExportActivityProcessor(exporter); + using var processor = new SimpleExportProcessor(exporter); processor.OnEnd(new Activity("start1")); processor.OnEnd(new Activity("start2")); @@ -70,7 +70,7 @@ public void CheckForceFlushExport(int timeout) public void CheckShutdownExport(int timeout) { using var exporter = new TestActivityExporter(); - using var processor = new SimpleExportActivityProcessor(exporter); + using var processor = new SimpleExportProcessor(exporter); processor.OnEnd(new Activity("start")); From 4fcd40f5552a0915d62dd8d0e87274f213025c6a Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 22:35:24 -0700 Subject: [PATCH 05/11] clean up --- docs/logs/getting-started/Program.cs | 29 ---------------------------- 1 file changed, 29 deletions(-) diff --git a/docs/logs/getting-started/Program.cs b/docs/logs/getting-started/Program.cs index 017a5769180..dfd2b274b10 100644 --- a/docs/logs/getting-started/Program.cs +++ b/docs/logs/getting-started/Program.cs @@ -64,8 +64,6 @@ public static void Main() ["Name"] = "truffle", ["Price"] = 299.99, }); - - var p = new FoodProcessor(new PotatoExporter()); } internal struct Food @@ -74,31 +72,4 @@ internal struct Food public double Price { get; set; } } - - internal class Exporter - { - } - - internal class FoodExporter : Exporter - { - } - - internal class PotatoExporter : FoodExporter - { - } - - internal class Processor - { - public Processor(Exporter exporter) - { - } - } - - internal class FoodProcessor : Processor - { - public FoodProcessor(Exporter exporter) - : base(exporter) - { - } - } } From 6e6119346dc6eee2afa5711403e20568b5e5c850 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 22:58:39 -0700 Subject: [PATCH 06/11] changelog --- src/OpenTelemetry/CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index e4712733326..58f81da6f83 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -13,6 +13,14 @@ * Added `ILogger`/`Microsoft.Extensions.Logging` integration ([#1308](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1308)) ([#1315](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1315)) +* Changed exporter and processor to generic types + ([#1328](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1328)): + * `ActivityExporter` changed to `BaseExporter` + * `ActivityProcessor` changed to `BaseProcessor` + * `BatchExportActivityProcessor` changed to `BatchExportProcessor` + * `ReentrantExportActivityProcessor` changed to + `ReentrantExportProcessor` + * `SimpleExportActivityProcessor` changed to `SimpleExportProcessor` ## 0.6.0-beta.1 From 5709f38e0041b005acc459a93f31ddeb2e4be690 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 23:01:09 -0700 Subject: [PATCH 07/11] update readme --- docs/trace/extending-the-sdk/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/trace/extending-the-sdk/README.md b/docs/trace/extending-the-sdk/README.md index ec3ca486242..eababfc2719 100644 --- a/docs/trace/extending-the-sdk/README.md +++ b/docs/trace/extending-the-sdk/README.md @@ -65,10 +65,10 @@ TBD OpenTelemetry .NET SDK has provided the following built-in processors: -* [BatchExportProcessor](../../../src/OpenTelemetry/BatchExportProcessor.cs) -* [CompositeProcessor](../../../src/OpenTelemetry/CompositeProcessor.cs) -* [ReentrantExportProcessor](../../../src/OpenTelemetry/ReentrantExportProcessor.cs) -* [SimpleExportProcessor](../../../src/OpenTelemetry/SimpleExportProcessor.cs) +* [BatchExportProcessor<T>](../../../src/OpenTelemetry/BatchExportProcessor.cs) +* [CompositeProcessor<T>](../../../src/OpenTelemetry/CompositeProcessor.cs) +* [ReentrantExportProcessor<T>](../../../src/OpenTelemetry/ReentrantExportProcessor.cs) +* [SimpleExportProcessor<T>](../../../src/OpenTelemetry/SimpleExportProcessor.cs) Custom processors can be implemented to cover more scenarios: From 695265e3f37b45e2ea9a504bda60b93390d9c8e5 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 23:03:26 -0700 Subject: [PATCH 08/11] prevent LogRecord to be inherited --- src/OpenTelemetry/Logs/LogRecord.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry/Logs/LogRecord.cs b/src/OpenTelemetry/Logs/LogRecord.cs index 5f4091c28fa..e53397edcca 100644 --- a/src/OpenTelemetry/Logs/LogRecord.cs +++ b/src/OpenTelemetry/Logs/LogRecord.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry.Logs /// /// Log record base class. /// - public class LogRecord + public sealed class LogRecord { internal LogRecord(DateTime timestamp, string categoryName, LogLevel logLevel, EventId eventId, object state, Exception exception) { @@ -35,17 +35,17 @@ internal LogRecord(DateTime timestamp, string categoryName, LogLevel logLevel, E this.Exception = exception; } - public DateTime Timestamp { get; protected set; } + public DateTime Timestamp { get; } - public string CategoryName { get; protected set; } + public string CategoryName { get; } - public LogLevel LogLevel { get; protected set; } + public LogLevel LogLevel { get; } - public EventId EventId { get; protected set; } + public EventId EventId { get; } - public object State { get; protected set; } + public object State { get; } - public Exception Exception { get; protected set; } + public Exception Exception { get; } } } #endif From dd01a329ce7f485ac884e9aebe3e7ec3b246349b Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 23:07:22 -0700 Subject: [PATCH 09/11] simplify example --- docs/logs/getting-started/MyExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/logs/getting-started/MyExporter.cs b/docs/logs/getting-started/MyExporter.cs index 45a09149ec9..4d1fee37ff4 100644 --- a/docs/logs/getting-started/MyExporter.cs +++ b/docs/logs/getting-started/MyExporter.cs @@ -43,7 +43,7 @@ public override ExportResult Export(in Batch batch) sb.Append(", "); } - sb.Append(record.Timestamp.ToString()); + sb.Append($"{record}"); } Console.WriteLine($"{this.name}.Export([{sb.ToString()}])"); From 991b985a8ae5e121c599f8a2e71c610226dafd20 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 23:15:24 -0700 Subject: [PATCH 10/11] simplify the code --- src/OpenTelemetry/CompositeProcessor.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/OpenTelemetry/CompositeProcessor.cs b/src/OpenTelemetry/CompositeProcessor.cs index afef1b69603..2b504e6432a 100644 --- a/src/OpenTelemetry/CompositeProcessor.cs +++ b/src/OpenTelemetry/CompositeProcessor.cs @@ -24,8 +24,8 @@ namespace OpenTelemetry { public class CompositeProcessor : BaseProcessor { - private DoublyLinkedListNode> head; - private DoublyLinkedListNode> tail; + private DoublyLinkedListNode head; + private DoublyLinkedListNode tail; private bool disposed; public CompositeProcessor(IEnumerable> processors) @@ -42,7 +42,7 @@ public CompositeProcessor(IEnumerable> processors) throw new ArgumentException($"{nameof(processors)} collection is empty"); } - this.head = new DoublyLinkedListNode>(iter.Current); + this.head = new DoublyLinkedListNode(iter.Current); this.tail = this.head; while (iter.MoveNext()) @@ -58,7 +58,7 @@ public CompositeProcessor AddProcessor(BaseProcessor processor) throw new ArgumentNullException(nameof(processor)); } - var node = new DoublyLinkedListNode>(processor) + var node = new DoublyLinkedListNode(processor) { Previous = this.tail, }; @@ -184,18 +184,18 @@ protected override void Dispose(bool disposing) this.disposed = true; } - private class DoublyLinkedListNode + private class DoublyLinkedListNode { - public readonly T2 Value; + public readonly BaseProcessor Value; - public DoublyLinkedListNode(T2 value) + public DoublyLinkedListNode(BaseProcessor value) { this.Value = value; } - public DoublyLinkedListNode Previous { get; set; } + public DoublyLinkedListNode Previous { get; set; } - public DoublyLinkedListNode Next { get; set; } + public DoublyLinkedListNode Next { get; set; } } } } From 98216b2a338082899db17fc72d6490782360eadc Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Tue, 6 Oct 2020 23:19:39 -0700 Subject: [PATCH 11/11] revert accidental change --- docs/logs/getting-started/MyProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/logs/getting-started/MyProcessor.cs b/docs/logs/getting-started/MyProcessor.cs index 84112bd1c55..033e3c36c0d 100644 --- a/docs/logs/getting-started/MyProcessor.cs +++ b/docs/logs/getting-started/MyProcessor.cs @@ -35,7 +35,7 @@ public override void OnEnd(LogRecord record) protected override bool OnForceFlush(int timeoutMilliseconds) { - Console.WriteLine($"{this.name}.OnForceFlush()"); + Console.WriteLine($"{this.name}.OnForceFlush({timeoutMilliseconds})"); return true; }