ILogger integration - part 3 (#1328)
* extract common part * make process/exporter generic * update dependencies * update all the tests and docs * clean up * changelog * update readme * prevent LogRecord to be inherited * simplify example * simplify the code * revert accidental change
This commit is contained in:
parent
6348f387f2
commit
71bb3635f5
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Logs;
|
||||
|
||||
internal static class LoggerExtensions
|
||||
{
|
||||
|
|
@ -29,4 +31,14 @@ internal static class LoggerExtensions
|
|||
{
|
||||
LogExAction(logger, obj, null);
|
||||
}
|
||||
|
||||
public static OpenTelemetryLoggerOptions AddMyExporter(this OpenTelemetryLoggerOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
return options.AddProcessor(new BatchExportProcessor<LogRecord>(new MyExporter()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
// <copyright file="MyExporter.cs" company="OpenTelemetry Authors">
|
||||
// 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.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Logs;
|
||||
|
||||
internal class MyExporter : BaseExporter<LogRecord>
|
||||
{
|
||||
private readonly string name;
|
||||
|
||||
public MyExporter(string name = "MyExporter")
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public override ExportResult Export(in Batch<LogRecord> 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}");
|
||||
}
|
||||
|
||||
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})");
|
||||
}
|
||||
}
|
||||
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Logs;
|
||||
|
||||
internal class MyProcessor : LogProcessor
|
||||
internal class MyProcessor : BaseProcessor<LogRecord>
|
||||
{
|
||||
private readonly string name;
|
||||
|
||||
|
|
@ -29,39 +30,7 @@ internal class MyProcessor : LogProcessor
|
|||
|
||||
public override void OnEnd(LogRecord record)
|
||||
{
|
||||
var state = record.State;
|
||||
|
||||
if (state is IReadOnlyCollection<KeyValuePair<string, object>> 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)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@ public class Program
|
|||
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
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ using System.Text;
|
|||
using OpenTelemetry;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
internal class MyExporter : ActivityExporter
|
||||
internal class MyExporter : BaseExporter<Activity>
|
||||
{
|
||||
private readonly string name;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
internal static class MyExporterHelperExtensions
|
||||
|
|
@ -26,6 +28,6 @@ internal static class MyExporterHelperExtensions
|
|||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
return builder.AddProcessor(new BatchExportActivityProcessor(new MyExporter()));
|
||||
return builder.AddProcessor(new BatchExportProcessor<Activity>(new MyExporter()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry;
|
||||
|
||||
internal class MyProcessor : ActivityProcessor
|
||||
internal class MyProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
private readonly string name;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class Program
|
|||
.AddSource("OTel.Demo")
|
||||
.AddProcessor(new MyProcessor("ProcessorA"))
|
||||
.AddProcessor(new MyProcessor("ProcessorB"))
|
||||
.AddProcessor(new SimpleExportActivityProcessor(new MyExporter("ExporterX")))
|
||||
.AddProcessor(new SimpleExportProcessor<Activity>(new MyExporter("ExporterX")))
|
||||
.AddMyExporter()
|
||||
.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Activity>` (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<Activity>
|
||||
{
|
||||
public override ExportResult Export(in Batch<Activity> 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<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:
|
||||
|
||||
* Processors should inherit from `OpenTelemetry.Trace.ActivityProcessor` (which
|
||||
* Processors should inherit from `OpenTelemetry.BaseProcessor<Activity>` (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<Activity>
|
||||
{
|
||||
public override void OnStart(Activity activity)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ namespace Examples.Console
|
|||
return null;
|
||||
}
|
||||
|
||||
internal class MyProcessor : ActivityProcessor
|
||||
internal class MyProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
public override void OnStart(Activity activity)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,12 +19,13 @@ using System.Diagnostics;
|
|||
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<Activity>
|
||||
{
|
||||
private readonly JsonSerializerOptions serializerOptions;
|
||||
private readonly bool displayAsJson;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Exporter.Console;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
|
|
@ -37,7 +38,7 @@ namespace OpenTelemetry.Trace
|
|||
|
||||
var options = new ConsoleExporterOptions();
|
||||
configure?.Invoke(options);
|
||||
return builder.AddProcessor(new SimpleExportActivityProcessor(new ConsoleExporter(options)));
|
||||
return builder.AddProcessor(new SimpleExportProcessor<Activity>(new ConsoleExporter(options)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ using System.Diagnostics;
|
|||
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 @@ using Thrift.Transport;
|
|||
|
||||
namespace OpenTelemetry.Exporter.Jaeger
|
||||
{
|
||||
public class JaegerExporter : ActivityExporter
|
||||
public class JaegerExporter : BaseExporter<Activity>
|
||||
{
|
||||
private readonly int maxPayloadSizeInBytes;
|
||||
private readonly TProtocolFactory protocolFactory;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Exporter.Jaeger;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
|
|
@ -43,7 +44,7 @@ namespace OpenTelemetry.Trace
|
|||
var jaegerExporter = new JaegerExporter(exporterOptions);
|
||||
|
||||
// TODO: Pick Simple vs Batching based on JaegerExporterOptions
|
||||
return builder.AddProcessor(new BatchExportActivityProcessor(jaegerExporter));
|
||||
return builder.AddProcessor(new BatchExportProcessor<Activity>(jaegerExporter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ using System;
|
|||
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 <see cref="Activity"/> and exporting the data using
|
||||
/// the OpenTelemetry protocol (OTLP).
|
||||
/// </summary>
|
||||
public class OtlpExporter : ActivityExporter
|
||||
public class OtlpExporter : BaseExporter<Activity>
|
||||
{
|
||||
private readonly Channel channel;
|
||||
private readonly OtlpCollector.TraceService.TraceServiceClient traceClient;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Exporter.OpenTelemetryProtocol;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
|
|
@ -43,7 +44,7 @@ namespace OpenTelemetry.Trace
|
|||
var otlpExporter = new OtlpExporter(exporterOptions);
|
||||
|
||||
// TODO: Pick Simple vs Batching based on OtlpExporterOptions
|
||||
return builder.AddProcessor(new BatchExportActivityProcessor(otlpExporter));
|
||||
return builder.AddProcessor(new BatchExportProcessor<Activity>(otlpExporter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <summary>
|
||||
/// Implements ZPages exporter.
|
||||
/// </summary>
|
||||
public class ZPagesExporter : ActivityExporter
|
||||
public class ZPagesExporter : BaseExporter<Activity>
|
||||
{
|
||||
internal readonly ZPagesExporterOptions Options;
|
||||
private readonly Timer minuteTimer;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.ZPages
|
|||
/// <summary>
|
||||
/// Implements the zpages span processor that exports spans in OnEnd call without batching.
|
||||
/// </summary>
|
||||
public class ZPagesProcessor : ActivityProcessor
|
||||
public class ZPagesProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
private readonly ZPagesExporter exporter;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ using System.Text.Json;
|
|||
#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
|
|||
/// <summary>
|
||||
/// Zipkin exporter.
|
||||
/// </summary>
|
||||
public class ZipkinExporter : ActivityExporter
|
||||
public class ZipkinExporter : BaseExporter<Activity>
|
||||
{
|
||||
private readonly ZipkinExporterOptions options;
|
||||
#if !NET452
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Exporter.Zipkin;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
|
|
@ -43,7 +44,7 @@ namespace OpenTelemetry.Trace
|
|||
var zipkinExporter = new ZipkinExporter(exporterOptions);
|
||||
|
||||
// TODO: Pick Simple vs Batching based on ZipkinExporterOptions
|
||||
return builder.AddProcessor(new BatchExportActivityProcessor(zipkinExporter));
|
||||
return builder.AddProcessor(new BatchExportProcessor<Activity>(zipkinExporter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Activity>`, 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<Activity>
|
||||
{
|
||||
public override void OnStart(Activity activity)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<Activity>`, 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<Activity>
|
||||
{
|
||||
public override void OnStart(Activity activity)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="BaseExportActivityProcessor.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="BaseExportProcessor.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -18,32 +18,34 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
namespace OpenTelemetry
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements processor that exports <see cref="Activity"/> objects.
|
||||
/// Implements processor that exports telemetry objects.
|
||||
/// </summary>
|
||||
public abstract class BaseExportActivityProcessor : ActivityProcessor
|
||||
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
|
||||
public abstract class BaseExportProcessor<T> : BaseProcessor<T>
|
||||
where T : class
|
||||
{
|
||||
protected readonly ActivityExporter exporter;
|
||||
protected readonly BaseExporter<T> exporter;
|
||||
private bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BaseExportActivityProcessor"/> class.
|
||||
/// Initializes a new instance of the <see cref="BaseExportProcessor{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="exporter">Activity exporter instance.</param>
|
||||
public BaseExportActivityProcessor(ActivityExporter exporter)
|
||||
/// <param name="exporter">Exporter instance.</param>
|
||||
public BaseExportProcessor(BaseExporter<T> exporter)
|
||||
{
|
||||
this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public sealed override void OnStart(Activity activity)
|
||||
public sealed override void OnStart(T data)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract override void OnEnd(Activity activity);
|
||||
public abstract override void OnEnd(T data);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool OnShutdown(int timeoutMilliseconds)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ActivityExporter.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="BaseExporter.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -19,7 +19,7 @@ using System.Diagnostics;
|
|||
using System.Threading;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
namespace OpenTelemetry
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration used to define the result of an export operation.
|
||||
|
|
@ -38,18 +38,20 @@ namespace OpenTelemetry.Trace
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activity exporter base class.
|
||||
/// Exporter base class.
|
||||
/// </summary>
|
||||
public abstract class ActivityExporter : IDisposable
|
||||
/// <typeparam name="T">The type of object to be exported.</typeparam>
|
||||
public abstract class BaseExporter<T> : IDisposable
|
||||
where T : class
|
||||
{
|
||||
private int shutdownCount;
|
||||
|
||||
/// <summary>
|
||||
/// Exports a batch of <see cref="Activity"/> objects.
|
||||
/// Exports a batch of telemetry objects.
|
||||
/// </summary>
|
||||
/// <param name="batch">Batch of <see cref="Activity"/> objects to export.</param>
|
||||
/// <param name="batch">Batch of telemetry objects to export.</param>
|
||||
/// <returns>Result of the export operation.</returns>
|
||||
public abstract ExportResult Export(in Batch<Activity> batch);
|
||||
public abstract ExportResult Export(in Batch<T> batch);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to shutdown the exporter, blocks the current thread until
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="BatchExportActivityProcessor.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="BatchExportProcessor.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -19,14 +19,16 @@ using System.Diagnostics;
|
|||
using System.Threading;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
namespace OpenTelemetry
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements processor that batches activities before calling exporter.
|
||||
/// Implements processor that batches telemetry objects before calling exporter.
|
||||
/// </summary>
|
||||
public class BatchExportActivityProcessor : BaseExportActivityProcessor
|
||||
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
|
||||
public class BatchExportProcessor<T> : BaseExportProcessor<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly CircularBuffer<Activity> circularBuffer;
|
||||
private readonly CircularBuffer<T> circularBuffer;
|
||||
private readonly int scheduledDelayMilliseconds;
|
||||
private readonly int exporterTimeoutMilliseconds;
|
||||
private readonly int maxExportBatchSize;
|
||||
|
|
@ -38,15 +40,15 @@ namespace OpenTelemetry.Trace
|
|||
private long droppedCount;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BatchExportActivityProcessor"/> class.
|
||||
/// Initializes a new instance of the <see cref="BatchExportProcessor{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="exporter">Exporter instance.</param>
|
||||
/// <param name="maxQueueSize">The maximum queue size. After the size is reached data are dropped. The default value is 2048.</param>
|
||||
/// <param name="scheduledDelayMilliseconds">The delay interval in milliseconds between two consecutive exports. The default value is 5000.</param>
|
||||
/// <param name="exporterTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
|
||||
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
|
||||
public BatchExportActivityProcessor(
|
||||
ActivityExporter exporter,
|
||||
public BatchExportProcessor(
|
||||
BaseExporter<T> exporter,
|
||||
int maxQueueSize = 2048,
|
||||
int scheduledDelayMilliseconds = 5000,
|
||||
int exporterTimeoutMilliseconds = 30000,
|
||||
|
|
@ -73,37 +75,37 @@ namespace OpenTelemetry.Trace
|
|||
throw new ArgumentOutOfRangeException(nameof(exporterTimeoutMilliseconds));
|
||||
}
|
||||
|
||||
this.circularBuffer = new CircularBuffer<Activity>(maxQueueSize);
|
||||
this.circularBuffer = new CircularBuffer<T>(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<T>)}-{exporter.GetType().Name}",
|
||||
};
|
||||
this.exporterThread.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of <see cref="Activity"/> objects dropped by the processor.
|
||||
/// Gets the number of telemetry objects dropped by the processor.
|
||||
/// </summary>
|
||||
internal long DroppedCount => this.droppedCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of <see cref="Activity"/> objects received by the processor.
|
||||
/// Gets the number of telemetry objects received by the processor.
|
||||
/// </summary>
|
||||
internal long ReceivedCount => this.circularBuffer.AddedCount + this.DroppedCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of <see cref="Activity"/> objects processed by the underlying exporter.
|
||||
/// Gets the number of telemetry objects processed by the underlying exporter.
|
||||
/// </summary>
|
||||
internal long ProcessedCount => this.circularBuffer.RemovedCount;
|
||||
|
||||
/// <inheritdoc/>
|
||||
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 @@ namespace OpenTelemetry.Trace
|
|||
|
||||
if (this.circularBuffer.Count > 0)
|
||||
{
|
||||
this.exporter.Export(new Batch<Activity>(this.circularBuffer, this.maxExportBatchSize));
|
||||
this.exporter.Export(new Batch<T>(this.circularBuffer, this.maxExportBatchSize));
|
||||
|
||||
this.dataExportedNotification.Set();
|
||||
this.dataExportedNotification.Reset();
|
||||
|
|
@ -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<Activity>`
|
||||
* `ActivityProcessor` changed to `BaseProcessor<Activity>`
|
||||
* `BatchExportActivityProcessor` changed to `BatchExportProcessor<Activity>`
|
||||
* `ReentrantExportActivityProcessor` changed to
|
||||
`ReentrantExportProcessor<Activity>`
|
||||
* `SimpleExportActivityProcessor` changed to `SimpleExportProcessor<Activity>`
|
||||
|
||||
## 0.6.0-beta.1
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="CompositeActivityProcessor.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="CompositeProcessor.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -20,15 +20,15 @@ using System.Diagnostics;
|
|||
using System.Threading;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
namespace OpenTelemetry
|
||||
{
|
||||
public class CompositeActivityProcessor : ActivityProcessor
|
||||
public class CompositeProcessor<T> : BaseProcessor<T>
|
||||
{
|
||||
private DoublyLinkedListNode<ActivityProcessor> head;
|
||||
private DoublyLinkedListNode<ActivityProcessor> tail;
|
||||
private DoublyLinkedListNode head;
|
||||
private DoublyLinkedListNode tail;
|
||||
private bool disposed;
|
||||
|
||||
public CompositeActivityProcessor(IEnumerable<ActivityProcessor> processors)
|
||||
public CompositeProcessor(IEnumerable<BaseProcessor<T>> processors)
|
||||
{
|
||||
if (processors == null)
|
||||
{
|
||||
|
|
@ -42,7 +42,7 @@ namespace OpenTelemetry.Trace
|
|||
throw new ArgumentException($"{nameof(processors)} collection is empty");
|
||||
}
|
||||
|
||||
this.head = new DoublyLinkedListNode<ActivityProcessor>(iter.Current);
|
||||
this.head = new DoublyLinkedListNode(iter.Current);
|
||||
this.tail = this.head;
|
||||
|
||||
while (iter.MoveNext())
|
||||
|
|
@ -51,14 +51,14 @@ namespace OpenTelemetry.Trace
|
|||
}
|
||||
}
|
||||
|
||||
public CompositeActivityProcessor AddProcessor(ActivityProcessor processor)
|
||||
public CompositeProcessor<T> AddProcessor(BaseProcessor<T> processor)
|
||||
{
|
||||
if (processor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(processor));
|
||||
}
|
||||
|
||||
var node = new DoublyLinkedListNode<ActivityProcessor>(processor)
|
||||
var node = new DoublyLinkedListNode(processor)
|
||||
{
|
||||
Previous = this.tail,
|
||||
};
|
||||
|
|
@ -69,25 +69,25 @@ namespace OpenTelemetry.Trace
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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 @@ namespace OpenTelemetry.Trace
|
|||
this.disposed = true;
|
||||
}
|
||||
|
||||
private class DoublyLinkedListNode<T>
|
||||
private class DoublyLinkedListNode
|
||||
{
|
||||
public readonly T Value;
|
||||
public readonly BaseProcessor<T> Value;
|
||||
|
||||
public DoublyLinkedListNode(T value)
|
||||
public DoublyLinkedListNode(BaseProcessor<T> value)
|
||||
{
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public DoublyLinkedListNode<T> Previous { get; set; }
|
||||
public DoublyLinkedListNode Previous { get; set; }
|
||||
|
||||
public DoublyLinkedListNode<T> Next { get; set; }
|
||||
public DoublyLinkedListNode Next { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
// <copyright file="CircularBufferStruct.cs" company="OpenTelemetry Authors">
|
||||
// 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.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenTelemetry.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Lock-free implementation of single-reader multi-writer circular buffer.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the underlying value.</typeparam>
|
||||
internal class CircularBufferStruct<T>
|
||||
where T : struct
|
||||
{
|
||||
private readonly Trait[] trait;
|
||||
private long head;
|
||||
private long tail;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CircularBufferStruct{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The capacity of the circular buffer, must be a positive integer.</param>
|
||||
public CircularBufferStruct(int capacity)
|
||||
{
|
||||
if (capacity <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(capacity));
|
||||
}
|
||||
|
||||
this.Capacity = capacity;
|
||||
this.trait = new Trait[capacity];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the capacity of the <see cref="CircularBufferStruct{T}"/>.
|
||||
/// </summary>
|
||||
public int Capacity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of items contained in the <see cref="CircularBufferStruct{T}"/>.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
var tailSnapshot = this.tail;
|
||||
return (int)(this.head - tailSnapshot);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of items added to the <see cref="CircularBufferStruct{T}"/>.
|
||||
/// </summary>
|
||||
public long AddedCount => this.head;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of items removed from the <see cref="CircularBufferStruct{T}"/>.
|
||||
/// </summary>
|
||||
public long RemovedCount => this.tail;
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified item to the buffer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <returns>
|
||||
/// Returns <c>true</c> if the item was added to the buffer successfully;
|
||||
/// <c>false</c> if the buffer is full.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to add the specified item to the buffer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <param name="maxSpinCount">The maximum allowed spin count, when set to a negative number or zero, will spin indefinitely.</param>
|
||||
/// <returns>
|
||||
/// Returns <c>true</c> if the item was added to the buffer successfully;
|
||||
/// <c>false</c> if the buffer is full or the spin count exceeded <paramref name="maxSpinCount"/>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an item from the <see cref="CircularBufferStruct{T}"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
/// <returns>Item read.</returns>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
// <copyright file="CompositeLogProcessor.cs" company="OpenTelemetry Authors">
|
||||
// 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.
|
||||
// </copyright>
|
||||
|
||||
#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<LogProcessor> head;
|
||||
private DoublyLinkedListNode<LogProcessor> tail;
|
||||
private bool disposed;
|
||||
|
||||
public CompositeLogProcessor(IEnumerable<LogProcessor> 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<LogProcessor>(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<LogProcessor>(processor)
|
||||
{
|
||||
Previous = this.tail,
|
||||
};
|
||||
this.tail.Next = node;
|
||||
this.tail = node;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void OnEnd(LogRecord record)
|
||||
{
|
||||
var cur = this.head;
|
||||
|
||||
while (cur != null)
|
||||
{
|
||||
cur.Value.OnEnd(record);
|
||||
cur = cur.Next;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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<T>
|
||||
{
|
||||
public readonly T Value;
|
||||
|
||||
public DoublyLinkedListNode(T value)
|
||||
{
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public DoublyLinkedListNode<T> Previous { get; set; }
|
||||
|
||||
public DoublyLinkedListNode<T> Next { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// <copyright file="LogProcessor.cs" company="OpenTelemetry Authors">
|
||||
// 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.
|
||||
// </copyright>
|
||||
|
||||
#if NETSTANDARD2_0
|
||||
namespace OpenTelemetry.Logs
|
||||
{
|
||||
/// <summary>
|
||||
/// Log processor base class.
|
||||
/// </summary>
|
||||
public abstract class LogProcessor : BaseProcessor<LogRecord>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public sealed override void OnStart(LogRecord record)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -23,7 +23,7 @@ namespace OpenTelemetry.Logs
|
|||
/// <summary>
|
||||
/// Log record base class.
|
||||
/// </summary>
|
||||
public readonly struct LogRecord
|
||||
public sealed class LogRecord
|
||||
{
|
||||
internal LogRecord(DateTime timestamp, string categoryName, LogLevel logLevel, EventId eventId, object state, Exception exception)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ namespace OpenTelemetry.Logs
|
|||
{
|
||||
public class OpenTelemetryLoggerOptions
|
||||
{
|
||||
internal readonly List<LogProcessor> Processors = new List<LogProcessor>();
|
||||
internal readonly List<BaseProcessor<LogRecord>> Processors = new List<BaseProcessor<LogRecord>>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds processor to the options.
|
||||
/// </summary>
|
||||
/// <param name="processor">Log processor to add.</param>
|
||||
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
|
||||
public OpenTelemetryLoggerOptions AddProcessor(LogProcessor processor)
|
||||
public OpenTelemetryLoggerOptions AddProcessor(BaseProcessor<LogRecord> processor)
|
||||
{
|
||||
if (processor == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace OpenTelemetry.Logs
|
|||
[ProviderAlias("OpenTelemetry")]
|
||||
public class OpenTelemetryLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
{
|
||||
internal LogProcessor Processor;
|
||||
internal BaseProcessor<LogRecord> Processor;
|
||||
private readonly OpenTelemetryLoggerOptions options;
|
||||
private readonly IDictionary<string, ILogger> loggers;
|
||||
private bool disposed;
|
||||
|
|
@ -90,7 +90,7 @@ namespace OpenTelemetry.Logs
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
internal OpenTelemetryLoggerProvider AddProcessor(LogProcessor processor)
|
||||
internal OpenTelemetryLoggerProvider AddProcessor(BaseProcessor<LogRecord> processor)
|
||||
{
|
||||
if (processor == null)
|
||||
{
|
||||
|
|
@ -101,13 +101,13 @@ namespace OpenTelemetry.Logs
|
|||
{
|
||||
this.Processor = processor;
|
||||
}
|
||||
else if (this.Processor is CompositeLogProcessor compositeProcessor)
|
||||
else if (this.Processor is CompositeProcessor<LogRecord> compositeProcessor)
|
||||
{
|
||||
compositeProcessor.AddProcessor(processor);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Processor = new CompositeLogProcessor(new[]
|
||||
this.Processor = new CompositeProcessor<LogRecord>(new[]
|
||||
{
|
||||
this.Processor,
|
||||
processor,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Configuration;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Logs;
|
||||
|
||||
namespace Microsoft.Extensions.Logging
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ReentrantExportActivityProcessor.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="ReentrantExportProcessor.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -18,28 +18,30 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
namespace OpenTelemetry
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements activity processor that exports <see cref="Activity"/> at each OnEnd call without synchronization.
|
||||
/// Implements processor that exports telemetry data at each OnEnd call without synchronization.
|
||||
/// </summary>
|
||||
public class ReentrantExportActivityProcessor : BaseExportActivityProcessor
|
||||
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
|
||||
public class ReentrantExportProcessor<T> : BaseExportProcessor<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReentrantExportActivityProcessor"/> class.
|
||||
/// Initializes a new instance of the <see cref="ReentrantExportProcessor{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="exporter">Activity exporter instance.</param>
|
||||
public ReentrantExportActivityProcessor(ActivityExporter exporter)
|
||||
/// <param name="exporter">Exporter instance.</param>
|
||||
public ReentrantExportProcessor(BaseExporter<T> exporter)
|
||||
: base(exporter)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEnd(Activity activity)
|
||||
public override void OnEnd(T data)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.exporter.Export(new Batch<Activity>(activity));
|
||||
this.exporter.Export(new Batch<T>(data));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="SimpleExportActivityProcessor.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="SimpleExportProcessor.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -15,35 +15,36 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
namespace OpenTelemetry
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements activity processor that exports <see cref="Activity"/> at each OnEnd call.
|
||||
/// Implements processor that exports telemetry data at each OnEnd call.
|
||||
/// </summary>
|
||||
public class SimpleExportActivityProcessor : BaseExportActivityProcessor
|
||||
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
|
||||
public class SimpleExportProcessor<T> : BaseExportProcessor<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly object syncObject = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SimpleExportActivityProcessor"/> class.
|
||||
/// Initializes a new instance of the <see cref="SimpleExportProcessor{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="exporter">Activity exporter instance.</param>
|
||||
public SimpleExportActivityProcessor(ActivityExporter exporter)
|
||||
/// <param name="exporter">Exporter instance.</param>
|
||||
public SimpleExportProcessor(BaseExporter<T> exporter)
|
||||
: base(exporter)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEnd(Activity activity)
|
||||
public override void OnEnd(T data)
|
||||
{
|
||||
lock (this.syncObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.exporter.Export(new Batch<Activity>(activity));
|
||||
this.exporter.Export(new Batch<T>(data));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// <copyright file="ActivityProcessor.cs" company="OpenTelemetry Authors">
|
||||
// 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.
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
/// <summary>
|
||||
/// Activity processor base class.
|
||||
/// </summary>
|
||||
public abstract class ActivityProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -41,10 +41,10 @@ namespace OpenTelemetry.Trace
|
|||
private static readonly Action<Activity, ActivityKind> SetKindProperty = CreateActivityKindSetter();
|
||||
private readonly Sampler sampler;
|
||||
private readonly Resource resource;
|
||||
private ActivityProcessor activityProcessor;
|
||||
private BaseProcessor<Activity> activityProcessor;
|
||||
private Action<Activity> getRequestedDataAction;
|
||||
|
||||
internal ActivitySourceAdapter(Sampler sampler, ActivityProcessor activityProcessor, Resource resource)
|
||||
internal ActivitySourceAdapter(Sampler sampler, BaseProcessor<Activity> activityProcessor, Resource resource)
|
||||
{
|
||||
this.sampler = sampler ?? throw new ArgumentNullException(nameof(sampler));
|
||||
this.resource = resource ?? throw new ArgumentNullException(nameof(resource));
|
||||
|
|
@ -97,7 +97,7 @@ namespace OpenTelemetry.Trace
|
|||
}
|
||||
}
|
||||
|
||||
internal void UpdateProcessor(ActivityProcessor processor)
|
||||
internal void UpdateProcessor(BaseProcessor<Activity> processor)
|
||||
{
|
||||
this.activityProcessor = processor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// </copyright>
|
||||
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<InstrumentationFactory> instrumentationFactories = new List<InstrumentationFactory>();
|
||||
private readonly List<ActivityProcessor> processors = new List<ActivityProcessor>();
|
||||
private readonly List<BaseProcessor<Activity>> processors = new List<BaseProcessor<Activity>>();
|
||||
private readonly List<string> sources = new List<string>();
|
||||
private Resource resource = Resource.Empty;
|
||||
private Sampler sampler = new ParentBasedSampler(new AlwaysOnSampler());
|
||||
|
|
@ -98,7 +99,7 @@ namespace OpenTelemetry.Trace
|
|||
/// </summary>
|
||||
/// <param name="processor">Activity processor to add.</param>
|
||||
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
|
||||
public TracerProviderBuilder AddProcessor(ActivityProcessor processor)
|
||||
public TracerProviderBuilder AddProcessor(BaseProcessor<Activity> processor)
|
||||
{
|
||||
if (processor == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
// </copyright>
|
||||
|
||||
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<Activity> processor)
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace OpenTelemetry.Trace
|
|||
private readonly ActivityListener listener;
|
||||
private readonly Resource resource;
|
||||
private readonly Sampler sampler;
|
||||
private ActivityProcessor processor;
|
||||
private BaseProcessor<Activity> processor;
|
||||
private ActivitySourceAdapter adapter;
|
||||
|
||||
static TracerProviderSdk()
|
||||
|
|
@ -44,7 +44,7 @@ namespace OpenTelemetry.Trace
|
|||
IEnumerable<string> sources,
|
||||
IEnumerable<TracerProviderBuilder.InstrumentationFactory> instrumentationFactories,
|
||||
Sampler sampler,
|
||||
List<ActivityProcessor> processors)
|
||||
List<BaseProcessor<Activity>> processors)
|
||||
{
|
||||
this.resource = resource;
|
||||
this.sampler = sampler;
|
||||
|
|
@ -157,7 +157,7 @@ namespace OpenTelemetry.Trace
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
internal TracerProviderSdk AddProcessor(ActivityProcessor processor)
|
||||
internal TracerProviderSdk AddProcessor(BaseProcessor<Activity> processor)
|
||||
{
|
||||
if (processor == null)
|
||||
{
|
||||
|
|
@ -168,13 +168,13 @@ namespace OpenTelemetry.Trace
|
|||
{
|
||||
this.processor = processor;
|
||||
}
|
||||
else if (this.processor is CompositeActivityProcessor compositeProcessor)
|
||||
else if (this.processor is CompositeProcessor<Activity> compositeProcessor)
|
||||
{
|
||||
compositeProcessor.AddProcessor(processor);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.processor = new CompositeActivityProcessor(new[]
|
||||
this.processor = new CompositeProcessor<Activity>(new[]
|
||||
{
|
||||
this.processor,
|
||||
processor,
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ namespace OpenTelemetry.Logs.Benchmarks
|
|||
this.loggerWithThreeProcessors.LogInformation("Hello, World!");
|
||||
}
|
||||
|
||||
internal class DummyLogProcessor : LogProcessor
|
||||
internal class DummyLogProcessor : BaseProcessor<LogRecord>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ namespace OpenTelemetry.Trace.Benchmarks
|
|||
}
|
||||
}
|
||||
|
||||
internal class DummyActivityProcessor : ActivityProcessor
|
||||
internal class DummyActivityProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace OpenTelemetry.Trace.Benchmarks
|
|||
}
|
||||
}
|
||||
|
||||
internal class DummyActivityProcessor : ActivityProcessor
|
||||
internal class DummyActivityProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests
|
|||
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<Activity>(zipkinExporter);
|
||||
|
||||
var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
|
||||
.AddSource(ActivitySourceName)
|
||||
|
|
@ -145,7 +145,7 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests
|
|||
});
|
||||
|
||||
var activity = CreateTestActivity();
|
||||
var processor = new SimpleExportActivityProcessor(exporter);
|
||||
var processor = new SimpleExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(activity);
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Tests
|
|||
|
||||
var activity = new Activity(ActivityNameAspNet).AddBaggage("Stuff", "123");
|
||||
activity.SetParentId(expectedTraceId, expectedSpanId, ActivityTraceFlags.Recorded);
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using (openTelemetry = Sdk.CreateTracerProviderBuilder()
|
||||
.AddAspNetInstrumentation(
|
||||
(options) =>
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
public async Task SuccessfulTemplateControllerCallGeneratesASpan(bool shouldEnrich)
|
||||
{
|
||||
var expectedResource = Resources.Resources.CreateServiceResource("test-service");
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
void ConfigureTestServices(IServiceCollection services)
|
||||
{
|
||||
this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
|
||||
|
|
@ -104,7 +104,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
[Fact]
|
||||
public async Task SuccessfulTemplateControllerCallUsesParentContext()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var expectedTraceId = ActivityTraceId.CreateRandom();
|
||||
var expectedSpanId = ActivitySpanId.CreateRandom();
|
||||
|
|
@ -155,7 +155,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
[Fact]
|
||||
public async Task CustomPropagator()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var expectedTraceId = ActivityTraceId.CreateRandom();
|
||||
var expectedSpanId = ActivitySpanId.CreateRandom();
|
||||
|
|
@ -204,7 +204,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
[Fact]
|
||||
public async Task RequestNotCollectedWhenFilterIsApplied()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
void ConfigureTestServices(IServiceCollection services)
|
||||
{
|
||||
|
|
@ -243,7 +243,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
[Fact]
|
||||
public async Task RequestNotCollectedWhenFilterThrowException()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
void ConfigureTestServices(IServiceCollection services)
|
||||
{
|
||||
|
|
@ -298,7 +298,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
this.openTelemetrySdk?.Dispose();
|
||||
}
|
||||
|
||||
private static void WaitForProcessorInvocations(Mock<ActivityProcessor> activityProcessor, int invocationCount)
|
||||
private static void WaitForProcessorInvocations(Mock<BaseProcessor<Activity>> 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
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
int statusCode,
|
||||
string reasonPhrase)
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
// Arrange
|
||||
using (var client = this.factory
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
|
|
@ -61,7 +63,7 @@ namespace OpenTelemetry.Instrumentation.Grpc.Tests
|
|||
|
||||
public int Port { get; }
|
||||
|
||||
public Mock<ActivityProcessor> GrpcServerSpanProcessor { get; } = new Mock<ActivityProcessor>();
|
||||
public Mock<BaseProcessor<Activity>> GrpcServerSpanProcessor { get; } = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace OpenTelemetry.Instrumentation.Grpc.Tests
|
|||
var uriHostNameType = Uri.CheckHostName(uri.Host);
|
||||
|
||||
var expectedResource = Resources.Resources.CreateServiceResource("test-service");
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var parent = new Activity("parent")
|
||||
.Start();
|
||||
|
|
@ -107,7 +107,7 @@ namespace OpenTelemetry.Instrumentation.Grpc.Tests
|
|||
{
|
||||
var uri = new Uri($"http://localhost:{this.fixture.Port}");
|
||||
var expectedResource = Resources.Resources.CreateServiceResource("test-service");
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var parent = new Activity("parent")
|
||||
.Start();
|
||||
|
|
@ -148,7 +148,7 @@ namespace OpenTelemetry.Instrumentation.Grpc.Tests
|
|||
{
|
||||
var uri = new Uri($"http://localhost:{this.fixture.Port}");
|
||||
var expectedResource = Resources.Resources.CreateServiceResource("test-service");
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var parent = new Activity("parent")
|
||||
.Start();
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ namespace OpenTelemetry.Instrumentation.Grpc.Tests
|
|||
Assert.Null(activity.GetTagValue(GrpcTagHelper.GrpcStatusCodeTagName));
|
||||
}
|
||||
|
||||
private static void WaitForProcessorInvocations(Mock<ActivityProcessor> spanProcessor, int invocationCount)
|
||||
private static void WaitForProcessorInvocations(Mock<BaseProcessor<Activity>> 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
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[InlineData(false)]
|
||||
public async Task HttpClientInstrumentationInjectsHeadersAsync(bool shouldEnrich)
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
RequestUri = new Uri(this.url),
|
||||
|
|
@ -141,7 +141,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
action(message, "custom_tracestate", Activity.Current.TraceStateString);
|
||||
});
|
||||
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
|
|
@ -192,7 +192,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task HttpClientInstrumentation_AddViaFactory_HttpInstrumentation_CollectsSpans()
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddHttpClientInstrumentation()
|
||||
|
|
@ -211,7 +211,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task HttpClientInstrumentation_AddViaFactory_DependencyInstrumentation_CollectsSpans()
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddHttpClientInstrumentation()
|
||||
|
|
@ -230,7 +230,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented()
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
|
|
@ -255,7 +255,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async void RequestNotCollectedWhenInstrumentationFilterApplied()
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddHttpClientInstrumentation(
|
||||
(opt) => opt.Filter = (req) => !req.RequestUri.OriginalString.Contains(this.url))
|
||||
|
|
@ -272,7 +272,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async void RequestNotCollectedWhenInstrumentationFilterThrowsException()
|
||||
{
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddHttpClientInstrumentation(
|
||||
(opt) => opt.Filter = (req) => throw new Exception("From InstrumentationFilter"))
|
||||
|
|
@ -293,7 +293,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task HttpClientInstrumentationCorrelationAndBaggage()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
|
||||
using var parent = new Activity("w3c activity");
|
||||
parent.SetIdFormat(ActivityIdFormat.W3C);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
out var port);
|
||||
|
||||
var expectedResource = Resources.Resources.CreateServiceResource("test-service");
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
tc.Url = HttpTestData.NormalizeValues(tc.Url, host, port);
|
||||
|
||||
using (serverLifeTime)
|
||||
|
|
@ -181,7 +181,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
private static async Task CheckEnrichment(Sampler sampler, int expect)
|
||||
{
|
||||
Counter = 0;
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.SetSampler(sampler)
|
||||
.AddHttpClientInstrumentation(options => options.Enrich = ActivityEnrichmentCounter)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task HttpWebRequestInstrumentationInjectsHeadersAsync()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddHttpWebRequestInstrumentation()
|
||||
|
|
@ -106,7 +106,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
action(message, "custom_tracestate", Activity.Current.TraceStateString);
|
||||
});
|
||||
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddHttpWebRequestInstrumentation(options => options.Propagator = propagator.Object)
|
||||
|
|
@ -145,7 +145,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task HttpWebRequestInstrumentationBacksOffIfAlreadyInstrumented()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddHttpWebRequestInstrumentation()
|
||||
|
|
@ -168,7 +168,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task RequestNotCollectedWhenInstrumentationFilterApplied()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddHttpWebRequestInstrumentation(
|
||||
|
|
@ -184,7 +184,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
[Fact]
|
||||
public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException()
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddHttpWebRequestInstrumentation(
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace OpenTelemetry.Instrumentation.Http.Tests
|
|||
out var port);
|
||||
|
||||
var expectedResource = Resources.Resources.CreateServiceResource("test-service");
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.SetResource(expectedResource)
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
bool isFailure = false,
|
||||
bool shouldEnrich = true)
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddSqlClientInstrumentation(options =>
|
||||
|
|
@ -145,7 +145,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
using var sqlConnection = new SqlConnection(TestConnectionString);
|
||||
using var sqlCommand = sqlConnection.CreateCommand();
|
||||
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddSqlClientInstrumentation(
|
||||
(opt) =>
|
||||
|
|
@ -209,7 +209,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
using var sqlConnection = new SqlConnection(TestConnectionString);
|
||||
using var sqlCommand = sqlConnection.CreateCommand();
|
||||
|
||||
var processor = new Mock<ActivityProcessor>();
|
||||
var processor = new Mock<BaseProcessor<Activity>>();
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddSqlClientInstrumentation(options =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
[InlineData(CommandType.StoredProcedure, "sp_who", true)]
|
||||
public async Task SuccessfulCommandTest(CommandType commandType, string commandText, bool captureText, bool isFailure = false)
|
||||
{
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddSqlClientInstrumentation(options =>
|
||||
|
|
@ -101,7 +101,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
{
|
||||
using FakeBehavingSqlEventSource fakeSqlEventSource = new FakeBehavingSqlEventSource();
|
||||
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddSqlClientInstrumentation(options =>
|
||||
|
|
@ -140,7 +140,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
{
|
||||
using FakeMisbehavingSqlEventSource fakeSqlEventSource = new FakeMisbehavingSqlEventSource();
|
||||
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddSqlClientInstrumentation()
|
||||
|
|
@ -158,7 +158,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Tests
|
|||
{
|
||||
using FakeMisbehavingSqlEventSource fakeSqlEventSource = new FakeMisbehavingSqlEventSource();
|
||||
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddSqlClientInstrumentation()
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Tests
|
|||
|
||||
using var connection = ConnectionMultiplexer.Connect(connectionOptions);
|
||||
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
using (Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
.AddRedisInstrumentation(connection)
|
||||
|
|
@ -159,7 +159,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Tests
|
|||
TracerProviderBuilder builder = null;
|
||||
Assert.Throws<ArgumentNullException>(() => builder.AddRedisInstrumentation(null));
|
||||
|
||||
var activityProcessor = new Mock<ActivityProcessor>();
|
||||
var activityProcessor = new Mock<BaseProcessor<Activity>>();
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
Sdk.CreateTracerProviderBuilder()
|
||||
.AddProcessor(activityProcessor.Object)
|
||||
|
|
|
|||
|
|
@ -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<Activity>
|
||||
{
|
||||
internal readonly BlockingCollection<Activity> Exported = new BlockingCollection<Activity>();
|
||||
private bool disposed;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ using OpenTelemetry.Trace;
|
|||
|
||||
namespace OpenTelemetry.Tests
|
||||
{
|
||||
internal class TestActivityProcessor : ActivityProcessor
|
||||
internal class TestActivityProcessor : BaseProcessor<Activity>
|
||||
{
|
||||
public Action<Activity> StartAction;
|
||||
public Action<Activity> EndAction;
|
||||
|
|
|
|||
|
|
@ -27,24 +27,24 @@ namespace OpenTelemetry.Trace.Tests
|
|||
[Fact]
|
||||
public void CheckNullExporter()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new BatchExportActivityProcessor(null));
|
||||
Assert.Throws<ArgumentNullException>(() => new BatchExportProcessor<Activity>(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CheckConstructorWithInvalidValues()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportActivityProcessor(new TestActivityExporter(), maxQueueSize: 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportActivityProcessor(new TestActivityExporter(), maxExportBatchSize: 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportActivityProcessor(new TestActivityExporter(), maxQueueSize: 1, maxExportBatchSize: 2049));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportActivityProcessor(new TestActivityExporter(), scheduledDelayMilliseconds: 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportActivityProcessor(new TestActivityExporter(), exporterTimeoutMilliseconds: -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportProcessor<Activity>(new TestActivityExporter(), maxQueueSize: 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportProcessor<Activity>(new TestActivityExporter(), maxExportBatchSize: 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportProcessor<Activity>(new TestActivityExporter(), maxQueueSize: 1, maxExportBatchSize: 2049));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportProcessor<Activity>(new TestActivityExporter(), scheduledDelayMilliseconds: 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new BatchExportProcessor<Activity>(new TestActivityExporter(), exporterTimeoutMilliseconds: -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CheckIfBatchIsExportingOnQueueLimit()
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new BatchExportActivityProcessor(
|
||||
using var processor = new BatchExportProcessor<Activity>(
|
||||
exporter,
|
||||
maxQueueSize: 1,
|
||||
maxExportBatchSize: 1,
|
||||
|
|
@ -68,7 +68,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckForceFlushWithInvalidTimeout()
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new BatchExportActivityProcessor(exporter, maxQueueSize: 2, maxExportBatchSize: 1);
|
||||
using var processor = new BatchExportProcessor<Activity>(exporter, maxQueueSize: 2, maxExportBatchSize: 1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => processor.ForceFlush(-2));
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckForceFlushExport(int timeout)
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new BatchExportActivityProcessor(
|
||||
using var processor = new BatchExportProcessor<Activity>(
|
||||
exporter,
|
||||
maxQueueSize: 3,
|
||||
maxExportBatchSize: 3,
|
||||
|
|
@ -117,7 +117,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckShutdownExport(int timeout)
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new BatchExportActivityProcessor(
|
||||
using var processor = new BatchExportProcessor<Activity>(
|
||||
exporter,
|
||||
maxQueueSize: 3,
|
||||
maxExportBatchSize: 3,
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ namespace OpenTelemetry.Trace.Tests
|
|||
[Fact]
|
||||
public void CompositeActivityProcessor_BadArgs()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new CompositeActivityProcessor(null));
|
||||
Assert.Throws<ArgumentException>(() => new CompositeActivityProcessor(new ActivityProcessor[0]));
|
||||
Assert.Throws<ArgumentNullException>(() => new CompositeProcessor<Activity>(null));
|
||||
Assert.Throws<ArgumentException>(() => new CompositeProcessor<Activity>(new BaseProcessor<Activity>[0]));
|
||||
|
||||
using var p1 = new TestActivityProcessor(null, null);
|
||||
using var processor = new CompositeActivityProcessor(new[] { p1 });
|
||||
using var processor = new CompositeProcessor<Activity>(new[] { p1 });
|
||||
Assert.Throws<ArgumentNullException>(() => processor.AddProcessor(null));
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
|
||||
var activity = new Activity("test");
|
||||
|
||||
using (var processor = new CompositeActivityProcessor(new[] { p1, p2 }))
|
||||
using (var processor = new CompositeProcessor<Activity>(new[] { p1, p2 }))
|
||||
{
|
||||
processor.OnStart(activity);
|
||||
processor.OnEnd(activity);
|
||||
|
|
@ -67,7 +67,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
|
||||
var activity = new Activity("test");
|
||||
|
||||
using (var processor = new CompositeActivityProcessor(new[] { p1 }))
|
||||
using (var processor = new CompositeProcessor<Activity>(new[] { p1 }))
|
||||
{
|
||||
Assert.Throws<Exception>(() => { processor.OnStart(activity); });
|
||||
Assert.Throws<Exception>(() => { processor.OnEnd(activity); });
|
||||
|
|
@ -80,7 +80,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
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<Activity>(new[] { p1, p2 }))
|
||||
{
|
||||
processor.Shutdown();
|
||||
Assert.True(p1.ShutdownCalled);
|
||||
|
|
@ -97,7 +97,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
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<Activity>(new[] { p1, p2 }))
|
||||
{
|
||||
processor.ForceFlush(timeout);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ namespace OpenTelemetry.Trace.Tests
|
|||
[Fact]
|
||||
public void CheckNullExporter()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ReentrantExportActivityProcessor(null));
|
||||
Assert.Throws<ArgumentNullException>(() => new ReentrantExportProcessor<Activity>(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CheckExportedOnEnd()
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new ReentrantExportActivityProcessor(exporter);
|
||||
using var processor = new ReentrantExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(new Activity("start1"));
|
||||
Assert.Single(exporter.Exported);
|
||||
|
|
@ -50,7 +50,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckForceFlushExport(int timeout)
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new ReentrantExportActivityProcessor(exporter);
|
||||
using var processor = new ReentrantExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(new Activity("start1"));
|
||||
processor.OnEnd(new Activity("start2"));
|
||||
|
|
@ -70,7 +70,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckShutdownExport(int timeout)
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new ReentrantExportActivityProcessor(exporter);
|
||||
using var processor = new ReentrantExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(new Activity("start"));
|
||||
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ namespace OpenTelemetry.Trace.Tests
|
|||
[Fact]
|
||||
public void CheckNullExporter()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new SimpleExportActivityProcessor(null));
|
||||
Assert.Throws<ArgumentNullException>(() => new SimpleExportProcessor<Activity>(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CheckExportedOnEnd()
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new SimpleExportActivityProcessor(exporter);
|
||||
using var processor = new SimpleExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(new Activity("start1"));
|
||||
Assert.Single(exporter.Exported);
|
||||
|
|
@ -50,7 +50,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckForceFlushExport(int timeout)
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new SimpleExportActivityProcessor(exporter);
|
||||
using var processor = new SimpleExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(new Activity("start1"));
|
||||
processor.OnEnd(new Activity("start2"));
|
||||
|
|
@ -70,7 +70,7 @@ namespace OpenTelemetry.Trace.Tests
|
|||
public void CheckShutdownExport(int timeout)
|
||||
{
|
||||
using var exporter = new TestActivityExporter();
|
||||
using var processor = new SimpleExportActivityProcessor(exporter);
|
||||
using var processor = new SimpleExportProcessor<Activity>(exporter);
|
||||
|
||||
processor.OnEnd(new Activity("start"));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue