Skip to content

Commit 052771d

Browse files
committed
chore: Move to BatchLogRecordExportProcessorOptions and PeriodicExportingMetricReaderOptions
This avoids introducing a potentially ambiguous constructor, restores the original shipped API signatures.
1 parent 2b6d37c commit 052771d

11 files changed

+130
-113
lines changed

src/OpenTelemetry/.publicApi/Stable/PublicAPI.Shipped.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ OpenTelemetry.Batch<T>.Enumerator.Enumerator() -> void
3131
OpenTelemetry.Batch<T>.Enumerator.MoveNext() -> bool
3232
OpenTelemetry.Batch<T>.Enumerator.Reset() -> void
3333
OpenTelemetry.BatchActivityExportProcessor
34-
OpenTelemetry.BatchActivityExportProcessor.BatchActivityExportProcessor(OpenTelemetry.BaseExporter<System.Diagnostics.Activity!>! exporter, int maxQueueSize, int scheduledDelayMilliseconds, int exporterTimeoutMilliseconds, int maxExportBatchSize) -> void
34+
OpenTelemetry.BatchActivityExportProcessor.BatchActivityExportProcessor(OpenTelemetry.BaseExporter<System.Diagnostics.Activity!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512) -> void
3535
OpenTelemetry.BatchExportProcessor<T>
36-
OpenTelemetry.BatchExportProcessor<T>.BatchExportProcessor(OpenTelemetry.BaseExporter<T!>! exporter, int maxQueueSize, int scheduledDelayMilliseconds, int exporterTimeoutMilliseconds, int maxExportBatchSize) -> void
36+
OpenTelemetry.BatchExportProcessor<T>.BatchExportProcessor(OpenTelemetry.BaseExporter<T!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512) -> void
3737
OpenTelemetry.BatchExportProcessorOptions<T>
3838
OpenTelemetry.BatchExportProcessorOptions<T>.BatchExportProcessorOptions() -> void
3939
OpenTelemetry.BatchExportProcessorOptions<T>.ExporterTimeoutMilliseconds.get -> int
@@ -45,7 +45,7 @@ OpenTelemetry.BatchExportProcessorOptions<T>.MaxQueueSize.set -> void
4545
OpenTelemetry.BatchExportProcessorOptions<T>.ScheduledDelayMilliseconds.get -> int
4646
OpenTelemetry.BatchExportProcessorOptions<T>.ScheduledDelayMilliseconds.set -> void
4747
OpenTelemetry.BatchLogRecordExportProcessor
48-
OpenTelemetry.BatchLogRecordExportProcessor.BatchLogRecordExportProcessor(OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, int maxQueueSize, int scheduledDelayMilliseconds, int exporterTimeoutMilliseconds, int maxExportBatchSize) -> void
48+
OpenTelemetry.BatchLogRecordExportProcessor.BatchLogRecordExportProcessor(OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512) -> void
4949
OpenTelemetry.CompositeProcessor<T>
5050
OpenTelemetry.CompositeProcessor<T>.AddProcessor(OpenTelemetry.BaseProcessor<T>! processor) -> OpenTelemetry.CompositeProcessor<T>!
5151
OpenTelemetry.CompositeProcessor<T>.CompositeProcessor(System.Collections.Generic.IEnumerable<OpenTelemetry.BaseProcessor<T>!>! processors) -> void
@@ -256,7 +256,7 @@ OpenTelemetry.Metrics.MetricType.LongSum = 26 -> OpenTelemetry.Metrics.MetricTyp
256256
OpenTelemetry.Metrics.MetricType.LongSumNonMonotonic = 138 -> OpenTelemetry.Metrics.MetricType
257257
OpenTelemetry.Metrics.MetricTypeExtensions
258258
OpenTelemetry.Metrics.PeriodicExportingMetricReader
259-
OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric!>! exporter, int exportIntervalMilliseconds, int exportTimeoutMilliseconds) -> void
259+
OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric!>! exporter, int exportIntervalMilliseconds = 60000, int exportTimeoutMilliseconds = 30000) -> void
260260
OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
261261
OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds.get -> int?
262262
OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds.set -> void
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
OpenTelemetry.BatchActivityExportProcessor.BatchActivityExportProcessor(OpenTelemetry.BaseExporter<System.Diagnostics.Activity!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512, bool useThreads = true) -> void
2-
OpenTelemetry.BatchExportProcessor<T>.BatchExportProcessor(OpenTelemetry.BaseExporter<T!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512, bool useThreads = true) -> void
3-
OpenTelemetry.BatchLogRecordExportProcessor.BatchLogRecordExportProcessor(OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, int maxQueueSize = 2048, int scheduledDelayMilliseconds = 5000, int exporterTimeoutMilliseconds = 30000, int maxExportBatchSize = 512, bool useThreads = true) -> void
4-
OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric!>! exporter, int exportIntervalMilliseconds = 60000, int exportTimeoutMilliseconds = 30000, bool useThreads = true) -> void
1+
OpenTelemetry.BatchActivityExportProcessor.BatchActivityExportProcessor(OpenTelemetry.BaseExporter<System.Diagnostics.Activity!>! exporter, OpenTelemetry.BatchExportProcessorOptions<System.Diagnostics.Activity!>! options) -> void
2+
OpenTelemetry.BatchExportProcessor<T>.BatchExportProcessor(OpenTelemetry.BaseExporter<T!>! exporter, OpenTelemetry.BatchExportProcessorOptions<T!>! options) -> void
3+
OpenTelemetry.BatchExportProcessorOptions<T>.UseThreads.get -> bool
4+
OpenTelemetry.BatchExportProcessorOptions<T>.UseThreads.set -> void
5+
OpenTelemetry.BatchLogRecordExportProcessor.BatchLogRecordExportProcessor(OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, OpenTelemetry.BatchExportProcessorOptions<OpenTelemetry.Logs.LogRecord!>! options) -> void
6+
OpenTelemetry.Metrics.PeriodicExportingMetricReader.PeriodicExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric!>! exporter, OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions! options) -> void
7+
OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.UseThreads.get -> bool
8+
OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions.UseThreads.set -> void

src/OpenTelemetry/BatchExportProcessor.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,44 @@ public abstract class BatchExportProcessor<T> : BaseExportProcessor<T>
3939
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
4040
protected BatchExportProcessor(
4141
BaseExporter<T> exporter,
42-
int maxQueueSize,
43-
int scheduledDelayMilliseconds,
44-
int exporterTimeoutMilliseconds,
45-
int maxExportBatchSize)
46-
: this(exporter, maxQueueSize, scheduledDelayMilliseconds, exporterTimeoutMilliseconds, maxExportBatchSize, true)
42+
int maxQueueSize = DefaultMaxQueueSize,
43+
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
44+
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
45+
int maxExportBatchSize = DefaultMaxExportBatchSize)
46+
: this(exporter, new BatchExportProcessorOptions<T>
47+
{
48+
MaxQueueSize = maxQueueSize,
49+
ScheduledDelayMilliseconds = scheduledDelayMilliseconds,
50+
ExporterTimeoutMilliseconds = exporterTimeoutMilliseconds,
51+
MaxExportBatchSize = maxExportBatchSize,
52+
UseThreads = true,
53+
})
4754
{
4855
}
4956

5057
/// <summary>
5158
/// Initializes a new instance of the <see cref="BatchExportProcessor{T}"/> class.
5259
/// </summary>
5360
/// <param name="exporter">Exporter instance.</param>
54-
/// <param name="maxQueueSize">The maximum queue size. After the size is reached data are dropped. The default value is 2048.</param>
55-
/// <param name="scheduledDelayMilliseconds">The delay interval in milliseconds between two consecutive exports. The default value is 5000.</param>
56-
/// <param name="exporterTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
57-
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
58-
/// <param name="useThreads">Enables the use of <see cref="Thread" /> when true, <see cref="Task"/> when false.</param>
61+
/// <param name="options">Configuration options for the batch export processor.</param>
5962
protected BatchExportProcessor(
6063
BaseExporter<T> exporter,
61-
int maxQueueSize = DefaultMaxQueueSize,
62-
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
63-
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
64-
int maxExportBatchSize = DefaultMaxExportBatchSize,
65-
bool useThreads = true)
64+
BatchExportProcessorOptions<T> options)
6665
: base(exporter)
6766
{
68-
Guard.ThrowIfOutOfRange(maxQueueSize, min: 1);
69-
Guard.ThrowIfOutOfRange(maxExportBatchSize, min: 1, max: maxQueueSize, maxName: nameof(maxQueueSize));
70-
Guard.ThrowIfOutOfRange(scheduledDelayMilliseconds, min: 1);
71-
Guard.ThrowIfOutOfRange(exporterTimeoutMilliseconds, min: 0);
72-
73-
this.circularBuffer = new CircularBuffer<T>(maxQueueSize);
74-
this.ScheduledDelayMilliseconds = scheduledDelayMilliseconds;
75-
this.ExporterTimeoutMilliseconds = exporterTimeoutMilliseconds;
76-
this.MaxExportBatchSize = maxExportBatchSize;
77-
this.useThreads = useThreads;
67+
Guard.ThrowIfNull(options);
68+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
69+
Guard.ThrowIfOutOfRange(options.MaxQueueSize, min: 1);
70+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
71+
Guard.ThrowIfOutOfRange(options.MaxExportBatchSize, min: 1, max: options.MaxQueueSize, maxName: nameof(options.MaxQueueSize));
72+
Guard.ThrowIfOutOfRange(options.ScheduledDelayMilliseconds, min: 1);
73+
Guard.ThrowIfOutOfRange(options.ExporterTimeoutMilliseconds, min: 0);
74+
75+
this.circularBuffer = new CircularBuffer<T>(options.MaxQueueSize);
76+
this.ScheduledDelayMilliseconds = options.ScheduledDelayMilliseconds;
77+
this.ExporterTimeoutMilliseconds = options.ExporterTimeoutMilliseconds;
78+
this.MaxExportBatchSize = options.MaxExportBatchSize;
79+
this.useThreads = options.UseThreads;
7880

7981
this.worker = this.CreateWorker();
8082
this.worker.Start();

src/OpenTelemetry/BatchExportProcessorOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public class BatchExportProcessorOptions<T>
2929
/// Gets or sets the maximum batch size of every export. It must be smaller or equal to <see cref="MaxQueueSize"/>. The default value is 512.
3030
/// </summary>
3131
public int MaxExportBatchSize { get; set; } = BatchExportProcessor<T>.DefaultMaxExportBatchSize;
32+
33+
/// <summary>
34+
/// Gets or sets a value indicating whether to use threads. Enables the use of <see cref="Thread" /> when true, <see cref="Task"/> when false. The default value is true.
35+
/// </summary>
36+
public bool UseThreads { get; set; } = true;
3237
}

src/OpenTelemetry/Logs/Processor/BatchLogRecordExportProcessor.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,32 @@ public class BatchLogRecordExportProcessor : BatchExportProcessor<LogRecord>
2121
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
2222
public BatchLogRecordExportProcessor(
2323
BaseExporter<LogRecord> exporter,
24-
int maxQueueSize,
25-
int scheduledDelayMilliseconds,
26-
int exporterTimeoutMilliseconds,
27-
int maxExportBatchSize)
24+
int maxQueueSize = DefaultMaxQueueSize,
25+
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
26+
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
27+
int maxExportBatchSize = DefaultMaxExportBatchSize)
2828
: this(
2929
exporter,
30-
maxQueueSize,
31-
scheduledDelayMilliseconds,
32-
exporterTimeoutMilliseconds,
33-
maxExportBatchSize,
34-
true)
30+
new BatchExportProcessorOptions<LogRecord>
31+
{
32+
MaxQueueSize = maxQueueSize,
33+
ScheduledDelayMilliseconds = scheduledDelayMilliseconds,
34+
ExporterTimeoutMilliseconds = exporterTimeoutMilliseconds,
35+
MaxExportBatchSize = maxExportBatchSize,
36+
UseThreads = true,
37+
})
3538
{
3639
}
3740

3841
/// <summary>
3942
/// Initializes a new instance of the <see cref="BatchLogRecordExportProcessor"/> class.
4043
/// </summary>
4144
/// <param name="exporter">Log record exporter.</param>
42-
/// <param name="maxQueueSize">The maximum queue size. After the size is reached data are dropped. The default value is 2048.</param>
43-
/// <param name="scheduledDelayMilliseconds">The delay interval in milliseconds between two consecutive exports. The default value is 5000.</param>
44-
/// <param name="exporterTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
45-
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
46-
/// <param name="useThreads">Enables the use of <see cref="Thread" /> when true, <see cref="Task"/> when false.</param>
45+
/// <param name="options">Configuration options for the batch export processor.</param>
4746
public BatchLogRecordExportProcessor(
4847
BaseExporter<LogRecord> exporter,
49-
int maxQueueSize = DefaultMaxQueueSize,
50-
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
51-
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
52-
int maxExportBatchSize = DefaultMaxExportBatchSize,
53-
bool useThreads = true)
54-
: base(
55-
exporter,
56-
maxQueueSize,
57-
scheduledDelayMilliseconds,
58-
exporterTimeoutMilliseconds,
59-
maxExportBatchSize,
60-
useThreads)
48+
BatchExportProcessorOptions<LogRecord> options)
49+
: base(exporter, options)
6150
{
6251
}
6352

src/OpenTelemetry/Metrics/Reader/PeriodicExportingMetricReader.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,34 @@ public class PeriodicExportingMetricReader : BaseExportingMetricReader
3030
/// <param name="exportTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
3131
public PeriodicExportingMetricReader(
3232
BaseExporter<Metric> exporter,
33-
int exportIntervalMilliseconds,
34-
int exportTimeoutMilliseconds)
35-
: this(exporter, exportIntervalMilliseconds, exportTimeoutMilliseconds, true)
33+
int exportIntervalMilliseconds = DefaultExportIntervalMilliseconds,
34+
int exportTimeoutMilliseconds = DefaultExportTimeoutMilliseconds)
35+
: this(exporter, new PeriodicExportingMetricReaderOptions
36+
{
37+
ExportIntervalMilliseconds = exportIntervalMilliseconds,
38+
ExportTimeoutMilliseconds = exportTimeoutMilliseconds,
39+
UseThreads = true,
40+
})
3641
{
3742
}
3843

3944
/// <summary>
4045
/// Initializes a new instance of the <see cref="PeriodicExportingMetricReader"/> class.
4146
/// </summary>
4247
/// <param name="exporter">Exporter instance to export Metrics to.</param>
43-
/// <param name="exportIntervalMilliseconds">The interval in milliseconds between two consecutive exports. The default value is 60000.</param>
44-
/// <param name="exportTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
45-
/// <param name="useThreads">Enables the use of <see cref="Thread" /> when true, <see cref="Task"/> when false.</param>
48+
/// <param name="options">Configuration options for the periodic exporting metric reader.</param>
4649
public PeriodicExportingMetricReader(
4750
BaseExporter<Metric> exporter,
48-
int exportIntervalMilliseconds = DefaultExportIntervalMilliseconds,
49-
int exportTimeoutMilliseconds = DefaultExportTimeoutMilliseconds,
50-
bool useThreads = true)
51+
PeriodicExportingMetricReaderOptions options)
5152
: base(exporter)
5253
{
54+
Guard.ThrowIfNull(options);
55+
56+
#pragma warning disable CA1062 // Validate arguments of public methods - needed for netstandard2.1
57+
var exportIntervalMilliseconds = options!.ExportIntervalMilliseconds ?? DefaultExportIntervalMilliseconds;
58+
#pragma warning restore CA1062 // Validate arguments of public methods - needed for netstandard2.1
59+
var exportTimeoutMilliseconds = options.ExportTimeoutMilliseconds ?? DefaultExportTimeoutMilliseconds;
60+
5361
Guard.ThrowIfInvalidTimeout(exportIntervalMilliseconds);
5462
Guard.ThrowIfZero(exportIntervalMilliseconds);
5563
Guard.ThrowIfInvalidTimeout(exportTimeoutMilliseconds);
@@ -61,7 +69,7 @@ public PeriodicExportingMetricReader(
6169

6270
this.ExportIntervalMilliseconds = exportIntervalMilliseconds;
6371
this.ExportTimeoutMilliseconds = exportTimeoutMilliseconds;
64-
this.useThreads = useThreads;
72+
this.useThreads = options.UseThreads;
6573

6674
this.worker = this.CreateWorker();
6775
this.worker.Start();

src/OpenTelemetry/Metrics/Reader/PeriodicExportingMetricReaderOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ internal PeriodicExportingMetricReaderOptions(IConfiguration configuration)
5252
/// associated with the metric reader.
5353
/// </summary>
5454
public int? ExportTimeoutMilliseconds { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets a value indicating whether to use threads. Enables the use of <see cref="Thread" /> when true, <see cref="Task"/> when false. The default value is true.
58+
/// </summary>
59+
public bool UseThreads { get; set; } = true;
5560
}

0 commit comments

Comments
 (0)