Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/NBomber.Sinks.OpenTelemetry/OpenTelemetrySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,33 @@ public class OpenTelemetrySink : IReportingSink
private Meter _meter = null!;
private EmptyMetricsReader _customMetricsReader = null!;
private OtlpExporterOptions _config = null!;
private MetricReaderTemporalityPreference _readerTemporalityPreference;

/// <summary>
/// Gets the name of the sink.
/// </summary>
public string SinkName => nameof(OpenTelemetrySink);

/// <summary>
/// Initializes a new instance of the <see cref="OpenTelemetrySink"/> class with default configuration.
/// Initializes a new instance of the <see cref="OpenTelemetrySink"/> class with default configuration:
/// <see cref="OtlpExportProtocol.HttpProtobuf"/> protocol and <see cref="MetricReaderTemporalityPreference.Cumulative"/> temporality preference.
/// </summary>
public OpenTelemetrySink()
{
_config = new OtlpExporterOptions();
_config.Protocol = OtlpExportProtocol.HttpProtobuf;
_readerTemporalityPreference = MetricReaderTemporalityPreference.Cumulative;
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenTelemetrySink"/> class using the specified configuration.
/// </summary>
/// <param name="config">The OTLP exporter configuration used for OpenTelemetry export.</param>
public OpenTelemetrySink(OtlpExporterOptions config)
/// <param name="readerTemporalityPreference">The temporality preference for the metrics reader. Defaults to <see cref="MetricReaderTemporalityPreference.Cumulative"/>.</param>
public OpenTelemetrySink(OtlpExporterOptions config, MetricReaderTemporalityPreference readerTemporalityPreference = MetricReaderTemporalityPreference.Cumulative)
{
_config = config;
_readerTemporalityPreference = readerTemporalityPreference;
}

/// <summary>
Expand All @@ -63,8 +69,10 @@ public Task Init(IBaseContext context, IConfiguration infraConfig)
var config = infraConfig?.GetSection("OpenTelemetrySink").Get<OtlpExporterOptions>();
if (config != null)
_config = config;

_customMetricsReader = new EmptyMetricsReader(new OtlpMetricExporter(_config));
_customMetricsReader.TemporalityPreference = _readerTemporalityPreference;

_meter = new Meter("nbomber");

_meterProvider = Sdk.CreateMeterProviderBuilder()
Expand Down
Loading