Support named options in the logger provider builder AddExporter API. (#3660)

This commit is contained in:
Mikel Blanchard 2022-09-14 11:02:13 -07:00 committed by GitHub
parent faf5bb5dfb
commit ef46e827a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 97 additions and 58 deletions

View File

@ -18,8 +18,10 @@ OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void
OpenTelemetry.Logs.LogRecord.TraceId.set -> void
OpenTelemetry.Logs.LogRecord.TraceState.set -> void
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor<T>() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action<System.IServiceProvider!, OpenTelemetry.Logs.OpenTelemetryLoggerProvider!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!

View File

@ -18,8 +18,10 @@ OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void
OpenTelemetry.Logs.LogRecord.TraceId.set -> void
OpenTelemetry.Logs.LogRecord.TraceState.set -> void
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor<T>() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action<System.IServiceProvider!, OpenTelemetry.Logs.OpenTelemetryLoggerProvider!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!

View File

@ -18,8 +18,10 @@ OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void
OpenTelemetry.Logs.LogRecord.TraceId.set -> void
OpenTelemetry.Logs.LogRecord.TraceState.set -> void
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor<T>() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action<System.IServiceProvider!, OpenTelemetry.Logs.OpenTelemetryLoggerProvider!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!

View File

@ -18,8 +18,10 @@ OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void
OpenTelemetry.Logs.LogRecord.TraceId.set -> void
OpenTelemetry.Logs.LogRecord.TraceState.set -> void
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter(OpenTelemetry.ExportProcessorType exportProcessorType, OpenTelemetry.BaseExporter<OpenTelemetry.Logs.LogRecord!>! exporter, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, string? name, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>? configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddExporter<T>(OpenTelemetry.ExportProcessorType exportProcessorType, System.Action<OpenTelemetry.Logs.ExportLogRecordProcessorOptions!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.AddProcessor<T>() -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureProvider(System.Action<System.IServiceProvider!, OpenTelemetry.Logs.OpenTelemetryLoggerProvider!>! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!

View File

@ -141,26 +141,37 @@ namespace OpenTelemetry.Logs
/// <param name="exporter">LogRecord exporter to add.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddExporter(ExportProcessorType exportProcessorType, BaseExporter<LogRecord> exporter)
=> this.AddExporter(exportProcessorType, exporter, o => { });
=> this.AddExporter(exportProcessorType, exporter, name: null, configure: null);
/// <summary>
/// Adds an exporter to the provider.
/// </summary>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="exporter">LogRecord exporter to add.</param>
/// <param name="configure">Callback action to configure <see
/// cref="ExportLogRecordProcessorOptions"/>. Only invoked when <paramref
/// name="exportProcessorType"/> is <see
/// cref="ExportProcessorType.Batch"/>.</param>
/// <param name="configure"><inheritdoc cref="AddExporter{T}(ExportProcessorType, string?, Action{ExportLogRecordProcessorOptions}?)" path="/param[@name='configure']"/></param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddExporter(ExportProcessorType exportProcessorType, BaseExporter<LogRecord> exporter, Action<ExportLogRecordProcessorOptions> configure)
=> this.AddExporter(exportProcessorType, exporter, name: null, configure);
/// <summary>
/// Adds an exporter to the provider.
/// </summary>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="exporter">LogRecord exporter to add.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure"><inheritdoc cref="AddExporter{T}(ExportProcessorType, string?, Action{ExportLogRecordProcessorOptions}?)" path="/param[@name='configure']"/></param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddExporter(
ExportProcessorType exportProcessorType,
BaseExporter<LogRecord> exporter,
string? name,
Action<ExportLogRecordProcessorOptions>? configure)
{
Guard.ThrowIfNull(exporter);
Guard.ThrowIfNull(configure);
this.ConfigureProvider((sp, provider)
=> provider.AddProcessor(
BuildExportProcessor(sp, exportProcessorType, exporter, configure)));
BuildExportProcessor(sp, exportProcessorType, exporter, name, configure)));
return this;
}
@ -168,16 +179,25 @@ namespace OpenTelemetry.Logs
/// <summary>
/// Adds an exporter to the provider which will be retrieved using dependency injection.
/// </summary>
/// <remarks>
/// Note: The type specified by <typeparamref name="T"/> will be
/// registered as a singleton service into application services.
/// </remarks>
/// <remarks><inheritdoc cref="AddExporter{T}(ExportProcessorType, string?, Action{ExportLogRecordProcessorOptions}?)" path="/remarks"/></remarks>
/// <typeparam name="T">Exporter type.</typeparam>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddExporter<T>(ExportProcessorType exportProcessorType)
where T : BaseExporter<LogRecord>
=> this.AddExporter<T>(exportProcessorType, o => { });
=> this.AddExporter<T>(exportProcessorType, name: null, configure: null);
/// <summary>
/// Adds an exporter to the provider which will be retrieved using dependency injection.
/// </summary>
/// <remarks><inheritdoc cref="AddExporter{T}(ExportProcessorType, string?, Action{ExportLogRecordProcessorOptions}?)" path="/remarks"/></remarks>
/// <typeparam name="T">Exporter type.</typeparam>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="configure"><inheritdoc cref="AddExporter{T}(ExportProcessorType, string?, Action{ExportLogRecordProcessorOptions}?)" path="/param[@name='configure']"/></param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddExporter<T>(ExportProcessorType exportProcessorType, Action<ExportLogRecordProcessorOptions> configure)
where T : BaseExporter<LogRecord>
=> this.AddExporter<T>(exportProcessorType, name: null, configure);
/// <summary>
/// Adds an exporter to the provider which will be retrieved using dependency injection.
@ -188,20 +208,22 @@ namespace OpenTelemetry.Logs
/// </remarks>
/// <typeparam name="T">Exporter type.</typeparam>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure">Callback action to configure <see
/// cref="ExportLogRecordProcessorOptions"/>. Only invoked when <paramref
/// name="exportProcessorType"/> is <see
/// cref="ExportProcessorType.Batch"/>.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddExporter<T>(ExportProcessorType exportProcessorType, Action<ExportLogRecordProcessorOptions> configure)
public OpenTelemetryLoggerOptions AddExporter<T>(
ExportProcessorType exportProcessorType,
string? name,
Action<ExportLogRecordProcessorOptions>? configure)
where T : BaseExporter<LogRecord>
{
Guard.ThrowIfNull(configure);
this.TryAddSingleton<T>();
this.ConfigureProvider((sp, provider)
=> provider.AddProcessor(
BuildExportProcessor(sp, exportProcessorType, sp.GetRequiredService<T>(), configure)));
BuildExportProcessor(sp, exportProcessorType, sp.GetRequiredService<T>(), name, configure)));
return this;
}
@ -393,20 +415,21 @@ namespace OpenTelemetry.Logs
IServiceProvider serviceProvider,
ExportProcessorType exportProcessorType,
BaseExporter<LogRecord> exporter,
Action<ExportLogRecordProcessorOptions> configure)
string? name,
Action<ExportLogRecordProcessorOptions>? configure)
{
name ??= Options.DefaultName;
switch (exportProcessorType)
{
case ExportProcessorType.Simple:
return new SimpleLogRecordExportProcessor(exporter);
case ExportProcessorType.Batch:
var options = new ExportLogRecordProcessorOptions
{
ExportProcessorType = ExportProcessorType.Batch,
BatchExportProcessorOptions = serviceProvider.GetRequiredService<IOptions<BatchExportLogRecordProcessorOptions>>().Value,
};
var options = serviceProvider.GetRequiredService<IOptionsSnapshot<ExportLogRecordProcessorOptions>>().Get(name);
configure(options);
options.ExportProcessorType = ExportProcessorType.Batch;
configure?.Invoke(options);
var batchOptions = options.BatchExportProcessorOptions;
@ -426,10 +449,7 @@ namespace OpenTelemetry.Logs
{
var services = this.services;
if (services != null)
{
services.TryAddSingleton<T>();
}
services?.TryAddSingleton<T>();
}
}
}

View File

@ -278,11 +278,9 @@ namespace OpenTelemetry.Trace
case ExportProcessorType.Simple:
return new SimpleActivityExportProcessor(exporter);
case ExportProcessorType.Batch:
var options = new ExportActivityProcessorOptions
{
ExportProcessorType = ExportProcessorType.Batch,
BatchExportProcessorOptions = serviceProvider.GetRequiredService<IOptionsSnapshot<BatchExportActivityProcessorOptions>>().Get(name),
};
var options = serviceProvider.GetRequiredService<IOptionsSnapshot<ExportActivityProcessorOptions>>().Get(name);
options.ExportProcessorType = ExportProcessorType.Batch;
configure?.Invoke(options);

View File

@ -174,10 +174,7 @@ namespace OpenTelemetry.Trace
/// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/>.</param>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="exporter">Activity exporter to add.</param>
/// <param name="configure">Callback action to configure <see
/// cref="ExportActivityProcessorOptions"/>. Only invoked when <paramref
/// name="exportProcessorType"/> is <see
/// cref="ExportProcessorType.Batch"/>.</param>
/// <param name="configure"><inheritdoc cref="AddExporter{T}(TracerProviderBuilder, ExportProcessorType, string?, Action{ExportActivityProcessorOptions}?)" path="/param[@name='configure']"/></param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder AddExporter(
this TracerProviderBuilder tracerProviderBuilder,
@ -193,10 +190,7 @@ namespace OpenTelemetry.Trace
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="exporter">Activity exporter to add.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure">Callback action to configure <see
/// cref="ExportActivityProcessorOptions"/>. Only invoked when <paramref
/// name="exportProcessorType"/> is <see
/// cref="ExportProcessorType.Batch"/>.</param>
/// <param name="configure"><inheritdoc cref="AddExporter{T}(TracerProviderBuilder, ExportProcessorType, string?, Action{ExportActivityProcessorOptions}?)" path="/param[@name='configure']"/></param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder AddExporter(
this TracerProviderBuilder tracerProviderBuilder,
@ -216,10 +210,7 @@ namespace OpenTelemetry.Trace
/// <summary>
/// Adds an exporter to the provider which will be retrieved using dependency injection.
/// </summary>
/// <remarks>
/// Note: The type specified by <typeparamref name="T"/> will be
/// registered as a singleton service into application services.
/// </remarks>
/// <remarks><inheritdoc cref="AddExporter{T}(TracerProviderBuilder, ExportProcessorType, string?, Action{ExportActivityProcessorOptions}?)" path="/remarks"/></remarks>
/// <typeparam name="T">Exporter type.</typeparam>
/// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/>.</param>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
@ -233,17 +224,11 @@ namespace OpenTelemetry.Trace
/// <summary>
/// Adds an exporter to the provider which will be retrieved using dependency injection.
/// </summary>
/// <remarks>
/// Note: The type specified by <typeparamref name="T"/> will be
/// registered as a singleton service into application services.
/// </remarks>
/// <remarks><inheritdoc cref="AddExporter{T}(TracerProviderBuilder, ExportProcessorType, string?, Action{ExportActivityProcessorOptions}?)" path="/remarks"/></remarks>
/// <typeparam name="T">Exporter type.</typeparam>
/// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/>.</param>
/// <param name="exportProcessorType"><see cref="ExportProcessorType"/>.</param>
/// <param name="configure">Callback action to configure <see
/// cref="ExportActivityProcessorOptions"/>. Only invoked when <paramref
/// name="exportProcessorType"/> is <see
/// cref="ExportProcessorType.Batch"/>.</param>
/// <param name="configure"><inheritdoc cref="AddExporter{T}(TracerProviderBuilder, ExportProcessorType, string?, Action{ExportActivityProcessorOptions}?)" path="/param[@name='configure']"/></param>
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder AddExporter<T>(
this TracerProviderBuilder tracerProviderBuilder,

View File

@ -502,13 +502,13 @@ public sealed class OpenTelemetryLoggingExtensionsTests
builder.ConfigureServices(services =>
{
services.Configure<BatchExportLogRecordProcessorOptions>(options =>
services.Configure<ExportLogRecordProcessorOptions>(options =>
{
// Note: This is testing options integration
optionsInvocations++;
options.MaxExportBatchSize = 18;
options.BatchExportProcessorOptions.MaxExportBatchSize = 18;
});
});
@ -550,6 +550,34 @@ public sealed class OpenTelemetryLoggingExtensionsTests
&& batchProcessor.MaxExportBatchSize == 100);
}
[Fact]
public void LoggingBuilderAddOpenTelemetryAddExporterNamedOptionsTest()
{
var builder = Sdk.CreateLoggerProviderBuilder();
int defaultOptionsConfigureInvocations = 0;
int namedOptionsConfigureInvocations = 0;
builder.ConfigureServices(services =>
{
services.Configure<ExportLogRecordProcessorOptions>(o => defaultOptionsConfigureInvocations++);
services.Configure<ExportLogRecordProcessorOptions>("Exporter2", o => namedOptionsConfigureInvocations++);
});
builder.AddExporter(ExportProcessorType.Batch, new CustomExporter());
builder.AddExporter(ExportProcessorType.Batch, new CustomExporter(), name: "Exporter2", configure: null);
builder.AddExporter<CustomExporter>(ExportProcessorType.Batch);
builder.AddExporter<CustomExporter>(ExportProcessorType.Batch, name: "Exporter2", configure: null);
using var provider = builder.Build();
Assert.NotNull(provider);
Assert.Equal(1, defaultOptionsConfigureInvocations);
Assert.Equal(1, namedOptionsConfigureInvocations);
}
private sealed class WrappedOpenTelemetryLoggerProvider : OpenTelemetryLoggerProvider
{
public bool Disposed { get; private set; }

View File

@ -317,13 +317,13 @@ namespace OpenTelemetry.Trace.Tests
builder.ConfigureServices(services =>
{
services.Configure<BatchExportActivityProcessorOptions>(options =>
services.Configure<ExportActivityProcessorOptions>(options =>
{
// Note: This is testing options integration
optionsInvocations++;
options.MaxExportBatchSize = 18;
options.BatchExportProcessorOptions.MaxExportBatchSize = 18;
});
});
@ -375,9 +375,9 @@ namespace OpenTelemetry.Trace.Tests
builder.ConfigureServices(services =>
{
services.Configure<BatchExportActivityProcessorOptions>(o => defaultOptionsConfigureInvocations++);
services.Configure<ExportActivityProcessorOptions>(o => defaultOptionsConfigureInvocations++);
services.Configure<BatchExportActivityProcessorOptions>("Exporter2", o => namedOptionsConfigureInvocations++);
services.Configure<ExportActivityProcessorOptions>("Exporter2", o => namedOptionsConfigureInvocations++);
});
builder.AddExporter(ExportProcessorType.Batch, new MyExporter());