diff --git a/src/NBomber.Sinks.OpenTelemetry/OpenTelemetrySink.cs b/src/NBomber.Sinks.OpenTelemetry/OpenTelemetrySink.cs index 86ab479..cc57925 100644 --- a/src/NBomber.Sinks.OpenTelemetry/OpenTelemetrySink.cs +++ b/src/NBomber.Sinks.OpenTelemetry/OpenTelemetrySink.cs @@ -25,6 +25,7 @@ public class OpenTelemetrySink : IReportingSink private Meter _meter = null!; private EmptyMetricsReader _customMetricsReader = null!; private OtlpExporterOptions _config = null!; + private MetricReaderTemporalityPreference _readerTemporalityPreference; /// /// Gets the name of the sink. @@ -32,20 +33,25 @@ public class OpenTelemetrySink : IReportingSink public string SinkName => nameof(OpenTelemetrySink); /// - /// Initializes a new instance of the class with default configuration. + /// Initializes a new instance of the class with default configuration: + /// protocol and temporality preference. /// public OpenTelemetrySink() { _config = new OtlpExporterOptions(); + _config.Protocol = OtlpExportProtocol.HttpProtobuf; + _readerTemporalityPreference = MetricReaderTemporalityPreference.Cumulative; } /// /// Initializes a new instance of the class using the specified configuration. /// /// The OTLP exporter configuration used for OpenTelemetry export. - public OpenTelemetrySink(OtlpExporterOptions config) + /// The temporality preference for the metrics reader. Defaults to . + public OpenTelemetrySink(OtlpExporterOptions config, MetricReaderTemporalityPreference readerTemporalityPreference = MetricReaderTemporalityPreference.Cumulative) { _config = config; + _readerTemporalityPreference = readerTemporalityPreference; } /// @@ -63,8 +69,10 @@ public Task Init(IBaseContext context, IConfiguration infraConfig) var config = infraConfig?.GetSection("OpenTelemetrySink").Get(); if (config != null) _config = config; - + _customMetricsReader = new EmptyMetricsReader(new OtlpMetricExporter(_config)); + _customMetricsReader.TemporalityPreference = _readerTemporalityPreference; + _meter = new Meter("nbomber"); _meterProvider = Sdk.CreateMeterProviderBuilder()