diff --git a/examples/Console/TestConsoleExporter.cs b/examples/Console/TestConsoleExporter.cs index 934236ae9f7..9929beab33b 100644 --- a/examples/Console/TestConsoleExporter.cs +++ b/examples/Console/TestConsoleExporter.cs @@ -37,7 +37,7 @@ private static object RunWithActivitySource() { // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use Console exporter. - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("console-test")) .AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter diff --git a/examples/Console/TestGrpcNetClient.cs b/examples/Console/TestGrpcNetClient.cs index a15bd6fbde3..b1d884aa789 100644 --- a/examples/Console/TestGrpcNetClient.cs +++ b/examples/Console/TestGrpcNetClient.cs @@ -41,7 +41,7 @@ internal static object Run() // // dotnet run grpc - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddGrpcClientInstrumentation() .AddSource("grpc-net-client-test") .AddConsoleExporter() diff --git a/examples/Console/TestHttpClient.cs b/examples/Console/TestHttpClient.cs index 78d0047a993..734cae06b58 100644 --- a/examples/Console/TestHttpClient.cs +++ b/examples/Console/TestHttpClient.cs @@ -32,7 +32,7 @@ internal static object Run() { System.Console.WriteLine("Hello World!"); - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation() .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("http-service-example")) .AddSource("http-client-test") diff --git a/examples/Console/TestInMemoryExporter.cs b/examples/Console/TestInMemoryExporter.cs index bbebdaf46a0..b7f0f956747 100644 --- a/examples/Console/TestInMemoryExporter.cs +++ b/examples/Console/TestInMemoryExporter.cs @@ -49,7 +49,7 @@ private static void RunWithActivitySource(ICollection exportedItems) { // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use InMemory exporter. - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("inmemory-test")) .AddInMemoryExporter(exportedItems) diff --git a/examples/Console/TestJaegerExporter.cs b/examples/Console/TestJaegerExporter.cs index 660723eb1b5..2c67e9bff66 100644 --- a/examples/Console/TestJaegerExporter.cs +++ b/examples/Console/TestJaegerExporter.cs @@ -55,7 +55,7 @@ internal static object RunWithActivity(string host, int port) { // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use the Jaeger exporter. - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("jaeger-test")) .AddSource("Samples.SampleClient", "Samples.SampleServer") .AddJaegerExporter(o => diff --git a/examples/Console/TestOpenTracingShim.cs b/examples/Console/TestOpenTracingShim.cs index a5d75eac7dc..a450a9c0360 100644 --- a/examples/Console/TestOpenTracingShim.cs +++ b/examples/Console/TestOpenTracingShim.cs @@ -29,7 +29,7 @@ internal static object Run(OpenTracingShimOptions options) { // Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer" // and use Console exporter. - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyServiceName")) .AddConsoleExporter() diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 1dafc6c8d76..423949b3bdc 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -69,7 +69,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use OTLP exporter. - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test")) .AddOtlpExporter(opt => diff --git a/examples/Console/TestRedis.cs b/examples/Console/TestRedis.cs index 12981cc7928..3306449810c 100644 --- a/examples/Console/TestRedis.cs +++ b/examples/Console/TestRedis.cs @@ -42,7 +42,7 @@ internal static object Run(string zipkinUri) var connection = ConnectionMultiplexer.Connect("localhost"); // Configure exporter to export traces to Zipkin - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddZipkinExporter(o => { o.Endpoint = new Uri(zipkinUri); diff --git a/examples/Console/TestZPagesExporter.cs b/examples/Console/TestZPagesExporter.cs index 3d70f4b447f..9d80e361f36 100644 --- a/examples/Console/TestZPagesExporter.cs +++ b/examples/Console/TestZPagesExporter.cs @@ -33,7 +33,7 @@ internal static object Run() // Start the server httpServer.Start(); - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("zpages-test") .AddZPagesExporter(o => { diff --git a/examples/Console/TestZipkinExporter.cs b/examples/Console/TestZipkinExporter.cs index 5c750f63aa2..40c44551b84 100644 --- a/examples/Console/TestZipkinExporter.cs +++ b/examples/Console/TestZipkinExporter.cs @@ -37,7 +37,7 @@ internal static object Run(string zipkinUri) // Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient" // and use the Zipkin exporter. - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("zipkin-test")) .AddZipkinExporter(o => diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs index e85cdcda231..45b11f5d543 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs @@ -246,8 +246,8 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) }; AddAttributes(metricPoint.Tags, dataPoint.Attributes); - dataPoint.Count = (ulong)metricPoint.LongValue; - dataPoint.Sum = metricPoint.DoubleValue; + dataPoint.Count = (ulong)metricPoint.GetHistogramCount(); + dataPoint.Sum = metricPoint.GetHistogramSum(); foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets()) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs index f19925b3a5b..34f55b7a3b6 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs @@ -14,18 +14,15 @@ // limitations under the License. // -using System; using System.Collections.Generic; using System.Diagnostics.Metrics; using System.Linq; -using System.Threading; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Metrics; using OpenTelemetry.Resources; using OpenTelemetry.Tests; using OpenTelemetry.Trace; using Xunit; -using GrpcCore = Grpc.Core; using OtlpCollector = Opentelemetry.Proto.Collector.Metrics.V1; using OtlpMetrics = Opentelemetry.Proto.Metrics.V1; @@ -49,99 +46,332 @@ public void ToOtlpResourceMetricsTest(bool includeServiceNameInResource) }); } - var tags = new KeyValuePair[] - { - new KeyValuePair("key1", "value1"), - new KeyValuePair("key2", "value2"), - }; + var metrics = new List(); using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{includeServiceNameInResource}", "0.0.1"); - - var exportedItems = new List(); - using var provider = Sdk.CreateMeterProviderBuilder() .SetResourceBuilder(resourceBuilder) .AddMeter(meter.Name) - .AddReader(new BaseExportingMetricReader(new InMemoryExporter(exportedItems)) - { - Temporality = AggregationTemporality.Delta, - }) + .AddInMemoryExporter(metrics) .Build(); var counter = meter.CreateCounter("counter"); + counter.Add(100); + + provider.ForceFlush(); + + var batch = new Batch(metrics.ToArray(), metrics.Count); + + var request = new OtlpCollector.ExportMetricsServiceRequest(); + request.AddMetrics(resourceBuilder.Build().ToOtlpResource(), batch); + + Assert.Single(request.ResourceMetrics); + var resourceMetric = request.ResourceMetrics.First(); + var oltpResource = resourceMetric.Resource; + + if (includeServiceNameInResource) + { + Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.StringValue == "service-name"); + Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceNamespace && kvp.Value.StringValue == "ns1"); + } + else + { + Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:")); + } - counter.Add(100, tags); + Assert.Single(resourceMetric.InstrumentationLibraryMetrics); + var instrumentationLibraryMetrics = resourceMetric.InstrumentationLibraryMetrics.First(); + Assert.Equal(string.Empty, instrumentationLibraryMetrics.SchemaUrl); + Assert.Equal(meter.Name, instrumentationLibraryMetrics.InstrumentationLibrary.Name); + Assert.Equal("0.0.1", instrumentationLibraryMetrics.InstrumentationLibrary.Version); + } + + [Theory] + [InlineData("test_gauge", null, null, 123, null)] + [InlineData("test_gauge", null, null, null, 123.45)] + [InlineData("test_gauge", "description", "unit", 123, null)] + public void TestGaugeToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue) + { + var metrics = new List(); - var testCompleted = false; + using var meter = new Meter(Utils.GetCurrentMethodName()); + using var provider = Sdk.CreateMeterProviderBuilder() + .AddMeter(meter.Name) + .AddInMemoryExporter(metrics) + .Build(); + + if (longValue.HasValue) + { + meter.CreateObservableGauge(name, () => longValue.Value, unit, description); + } + else + { + meter.CreateObservableGauge(name, () => doubleValue.Value, unit, description); + } provider.ForceFlush(); - var batch = new Batch(exportedItems.ToArray(), exportedItems.Count); - RunTest(batch); + var batch = new Batch(metrics.ToArray(), metrics.Count); + + var request = new OtlpCollector.ExportMetricsServiceRequest(); + request.AddMetrics(ResourceBuilder.CreateEmpty().Build().ToOtlpResource(), batch); + + var resourceMetric = request.ResourceMetrics.Single(); + var instrumentationLibraryMetrics = resourceMetric.InstrumentationLibraryMetrics.Single(); + var actual = instrumentationLibraryMetrics.Metrics.Single(); + + Assert.Equal(name, actual.Name); + Assert.Equal(description ?? string.Empty, actual.Description); + Assert.Equal(unit ?? string.Empty, actual.Unit); - Assert.True(testCompleted); + Assert.Equal(OtlpMetrics.Metric.DataOneofCase.Gauge, actual.DataCase); - void RunTest(Batch metrics) + Assert.NotNull(actual.Gauge); + Assert.Null(actual.Sum); + Assert.Null(actual.Histogram); + Assert.Null(actual.ExponentialHistogram); + Assert.Null(actual.Summary); + + Assert.Single(actual.Gauge.DataPoints); + var dataPoint = actual.Gauge.DataPoints.First(); + Assert.True(dataPoint.StartTimeUnixNano > 0); + Assert.True(dataPoint.TimeUnixNano > 0); + + if (longValue.HasValue) + { + Assert.Equal(OtlpMetrics.NumberDataPoint.ValueOneofCase.AsInt, dataPoint.ValueCase); + Assert.Equal(longValue, dataPoint.AsInt); + } + else { - var request = new OtlpCollector.ExportMetricsServiceRequest(); - request.AddMetrics(resourceBuilder.Build().ToOtlpResource(), metrics); + Assert.Equal(OtlpMetrics.NumberDataPoint.ValueOneofCase.AsDouble, dataPoint.ValueCase); + Assert.Equal(doubleValue, dataPoint.AsDouble); + } - Assert.Single(request.ResourceMetrics); - var resourceMetric = request.ResourceMetrics.First(); - var oltpResource = resourceMetric.Resource; + Assert.Empty(dataPoint.Attributes); - if (includeServiceNameInResource) - { - Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.StringValue == "service-name"); - Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceNamespace && kvp.Value.StringValue == "ns1"); - } - else - { - Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == ResourceSemanticConventions.AttributeServiceName && kvp.Value.ToString().Contains("unknown_service:")); - } + Assert.Empty(dataPoint.Exemplars); - Assert.Single(resourceMetric.InstrumentationLibraryMetrics); - var instrumentationLibraryMetrics = resourceMetric.InstrumentationLibraryMetrics.First(); - Assert.Equal(string.Empty, instrumentationLibraryMetrics.SchemaUrl); - Assert.Equal(meter.Name, instrumentationLibraryMetrics.InstrumentationLibrary.Name); - Assert.Equal("0.0.1", instrumentationLibraryMetrics.InstrumentationLibrary.Version); +#pragma warning disable CS0612 // Type or member is obsolete + Assert.Null(actual.IntGauge); + Assert.Null(actual.IntSum); + Assert.Null(actual.IntHistogram); + Assert.Empty(dataPoint.Labels); +#pragma warning restore CS0612 // Type or member is obsolete + } - Assert.Single(instrumentationLibraryMetrics.Metrics); + [Theory] + [InlineData("test_counter", null, null, 123, null, AggregationTemporality.Cumulative, true)] + [InlineData("test_counter", null, null, null, 123.45, AggregationTemporality.Cumulative, true)] + [InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true)] + [InlineData("test_counter", "description", "unit", 123, null, AggregationTemporality.Cumulative, true)] + [InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true, "key1", "value1", "key2", 123)] + public void TestCounterToOltpMetric(string name, string description, string unit, long? longValue, double? doubleValue, AggregationTemporality aggregationTemporality, bool isMonotonic, params object[] keysValues) + { + var metrics = new List(); - foreach (var metric in instrumentationLibraryMetrics.Metrics) - { - Assert.Equal(string.Empty, metric.Description); - Assert.Equal(string.Empty, metric.Unit); - Assert.Equal("counter", metric.Name); + using var meter = new Meter(Utils.GetCurrentMethodName()); + using var provider = Sdk.CreateMeterProviderBuilder() + .AddMeter(meter.Name) + .AddReader( + new BaseExportingMetricReader(new InMemoryExporter(metrics)) + { + Temporality = aggregationTemporality, + }) + .Build(); + + var attributes = ToAttributes(keysValues).ToArray(); + if (longValue.HasValue) + { + var counter = meter.CreateCounter(name, unit, description); + counter.Add(longValue.Value, attributes); + } + else + { + var counter = meter.CreateCounter(name, unit, description); + counter.Add(doubleValue.Value, attributes); + } + + provider.ForceFlush(); + + var batch = new Batch(metrics.ToArray(), metrics.Count); + + var request = new OtlpCollector.ExportMetricsServiceRequest(); + request.AddMetrics(ResourceBuilder.CreateEmpty().Build().ToOtlpResource(), batch); + + var resourceMetric = request.ResourceMetrics.Single(); + var instrumentationLibraryMetrics = resourceMetric.InstrumentationLibraryMetrics.Single(); + var actual = instrumentationLibraryMetrics.Metrics.Single(); - Assert.Equal(OtlpMetrics.Metric.DataOneofCase.Sum, metric.DataCase); - Assert.True(metric.Sum.IsMonotonic); - Assert.Equal(OtlpMetrics.AggregationTemporality.Delta, metric.Sum.AggregationTemporality); + Assert.Equal(name, actual.Name); + Assert.Equal(description ?? string.Empty, actual.Description); + Assert.Equal(unit ?? string.Empty, actual.Unit); - Assert.Single(metric.Sum.DataPoints); - var dataPoint = metric.Sum.DataPoints.First(); - Assert.True(dataPoint.StartTimeUnixNano > 0); - Assert.True(dataPoint.TimeUnixNano > 0); - Assert.Equal(OtlpMetrics.NumberDataPoint.ValueOneofCase.AsInt, dataPoint.ValueCase); - Assert.Equal(100, dataPoint.AsInt); + Assert.Equal(OtlpMetrics.Metric.DataOneofCase.Sum, actual.DataCase); + + Assert.Null(actual.Gauge); + Assert.NotNull(actual.Sum); + Assert.Null(actual.Histogram); + Assert.Null(actual.ExponentialHistogram); + Assert.Null(actual.Summary); + + Assert.Equal(isMonotonic, actual.Sum.IsMonotonic); + + var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative + ? OtlpMetrics.AggregationTemporality.Cumulative + : OtlpMetrics.AggregationTemporality.Delta; + Assert.Equal(otlpAggregationTemporality, actual.Sum.AggregationTemporality); + + Assert.Single(actual.Sum.DataPoints); + var dataPoint = actual.Sum.DataPoints.First(); + Assert.True(dataPoint.StartTimeUnixNano > 0); + Assert.True(dataPoint.TimeUnixNano > 0); + + if (longValue.HasValue) + { + Assert.Equal(OtlpMetrics.NumberDataPoint.ValueOneofCase.AsInt, dataPoint.ValueCase); + Assert.Equal(longValue, dataPoint.AsInt); + } + else + { + Assert.Equal(OtlpMetrics.NumberDataPoint.ValueOneofCase.AsDouble, dataPoint.ValueCase); + Assert.Equal(doubleValue, dataPoint.AsDouble); + } + + if (attributes.Length > 0) + { + OtlpTestHelpers.AssertOtlpAttributes(attributes, dataPoint.Attributes); + } + else + { + Assert.Empty(dataPoint.Attributes); + } + + Assert.Empty(dataPoint.Exemplars); #pragma warning disable CS0612 // Type or member is obsolete - Assert.Empty(dataPoint.Labels); + Assert.Null(actual.IntGauge); + Assert.Null(actual.IntSum); + Assert.Null(actual.IntHistogram); + Assert.Empty(dataPoint.Labels); #pragma warning restore CS0612 // Type or member is obsolete - OtlpTestHelpers.AssertOtlpAttributes(tags.ToList(), dataPoint.Attributes); + } + + [Theory] + [InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Cumulative)] + [InlineData("test_histogram", null, null, null, 123.45, AggregationTemporality.Cumulative)] + [InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta)] + [InlineData("test_histogram", "description", "unit", 123, null, AggregationTemporality.Cumulative)] + [InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta, "key1", "value1", "key2", 123)] + public void TestHistogramToOltpMetric(string name, string description, string unit, long? longValue, double? doubleValue, AggregationTemporality aggregationTemporality, params object[] keysValues) + { + var metrics = new List(); + + var metricReader = new BaseExportingMetricReader(new InMemoryExporter(metrics)); + metricReader.Temporality = aggregationTemporality; + + using var meter = new Meter(Utils.GetCurrentMethodName()); + using var provider = Sdk.CreateMeterProviderBuilder() + .AddMeter(meter.Name) + .AddReader(metricReader) + .Build(); + + var attributes = ToAttributes(keysValues).ToArray(); + if (longValue.HasValue) + { + var histogram = meter.CreateHistogram(name, unit, description); + histogram.Record(longValue.Value, attributes); + } + else + { + var histogram = meter.CreateHistogram(name, unit, description); + histogram.Record(doubleValue.Value, attributes); + } - Assert.Empty(dataPoint.Exemplars); + provider.ForceFlush(); + + var batch = new Batch(metrics.ToArray(), metrics.Count); + + var request = new OtlpCollector.ExportMetricsServiceRequest(); + request.AddMetrics(ResourceBuilder.CreateEmpty().Build().ToOtlpResource(), batch); + + var resourceMetric = request.ResourceMetrics.Single(); + var instrumentationLibraryMetrics = resourceMetric.InstrumentationLibraryMetrics.Single(); + var actual = instrumentationLibraryMetrics.Metrics.Single(); + + Assert.Equal(name, actual.Name); + Assert.Equal(description ?? string.Empty, actual.Description); + Assert.Equal(unit ?? string.Empty, actual.Unit); + + Assert.Equal(OtlpMetrics.Metric.DataOneofCase.Histogram, actual.DataCase); + + Assert.Null(actual.Gauge); + Assert.Null(actual.Sum); + Assert.NotNull(actual.Histogram); + Assert.Null(actual.ExponentialHistogram); + Assert.Null(actual.Summary); + + var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative + ? OtlpMetrics.AggregationTemporality.Cumulative + : OtlpMetrics.AggregationTemporality.Delta; + Assert.Equal(otlpAggregationTemporality, actual.Histogram.AggregationTemporality); + + Assert.Single(actual.Histogram.DataPoints); + var dataPoint = actual.Histogram.DataPoints.First(); + Assert.True(dataPoint.StartTimeUnixNano > 0); + Assert.True(dataPoint.TimeUnixNano > 0); + + Assert.Equal(1UL, dataPoint.Count); + + if (longValue.HasValue) + { + Assert.Equal((double)longValue, dataPoint.Sum); + } + else + { + Assert.Equal(doubleValue, dataPoint.Sum); + } + + int bucketIndex; + for (bucketIndex = 0; bucketIndex < dataPoint.ExplicitBounds.Count; ++bucketIndex) + { + if (dataPoint.Sum <= dataPoint.ExplicitBounds[bucketIndex]) + { + break; } - testCompleted = true; + Assert.Equal(0UL, dataPoint.BucketCounts[bucketIndex]); + } + + Assert.Equal(1UL, dataPoint.BucketCounts[bucketIndex]); + + if (attributes.Length > 0) + { + OtlpTestHelpers.AssertOtlpAttributes(attributes, dataPoint.Attributes); } + else + { + Assert.Empty(dataPoint.Attributes); + } + + Assert.Empty(dataPoint.Exemplars); + +#pragma warning disable CS0612 // Type or member is obsolete + Assert.Null(actual.IntGauge); + Assert.Null(actual.IntSum); + Assert.Null(actual.IntHistogram); + Assert.Empty(dataPoint.Labels); +#pragma warning restore CS0612 // Type or member is obsolete } - private class NoopMetricsServiceClient : OtlpCollector.MetricsService.IMetricsServiceClient + private static IEnumerable> ToAttributes(object[] keysValues) { - public OtlpCollector.ExportMetricsServiceResponse Export(OtlpCollector.ExportMetricsServiceRequest request, GrpcCore.Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default) + var keys = keysValues?.Where((_, index) => index % 2 == 0).ToArray(); + var values = keysValues?.Where((_, index) => index % 2 != 0).ToArray(); + + for (var i = 0; keys != null && i < keys.Length; ++i) { - return null; + yield return new KeyValuePair(keys[i].ToString(), values[i]); } } } diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs index 360fc156e45..f89f2fb2e5a 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs @@ -324,7 +324,7 @@ public void UseOpenTelemetryProtocolActivityExporterWithCustomActivityProcessor( endCalled = true; }; - var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .AddProcessor(testActivityProcessor) .AddOtlpExporter() diff --git a/test/OpenTelemetry.Exporter.ZPages.Tests/ZPagesExporterTests.cs b/test/OpenTelemetry.Exporter.ZPages.Tests/ZPagesExporterTests.cs index ac413ca0c6c..5713f3f9ef3 100644 --- a/test/OpenTelemetry.Exporter.ZPages.Tests/ZPagesExporterTests.cs +++ b/test/OpenTelemetry.Exporter.ZPages.Tests/ZPagesExporterTests.cs @@ -75,7 +75,7 @@ public void CheckingCustomActivityProcessor() endCalled = true; }; - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .AddProcessor(testActivityProcessor) .AddZPagesExporter() diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index 086685a0469..a547b09ba8a 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -112,7 +112,7 @@ public void SuppresssesInstrumentation() var zipkinExporter = new ZipkinExporter(exporterOptions); var exportActivityProcessor = new BatchActivityExportProcessor(zipkinExporter); - var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .AddProcessor(testActivityProcessor) .AddProcessor(exportActivityProcessor) diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs index d946617d849..465c3192173 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs @@ -58,7 +58,7 @@ public void AspNetRequestsAreCollectedSuccessfully( string filter = null, bool recordException = false) { - IDisposable openTelemetry = null; + IDisposable tracerProvider = null; RouteData routeData; switch (routeType) { @@ -118,7 +118,7 @@ public void AspNetRequestsAreCollectedSuccessfully( List exportedItems = new List(16); Sdk.SetDefaultTextMapPropagator(new TraceContextPropagator()); - using (openTelemetry = Sdk.CreateTracerProviderBuilder() + using (tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetInstrumentation((options) => { options.Filter = httpContext => @@ -275,7 +275,7 @@ public void ExtractContextIrrespectiveOfSamplingDecision(SamplingDecision sampli var activityProcessor = new Mock>(); Sdk.SetDefaultTextMapPropagator(propagator.Object); - using (var openTelemetry = Sdk.CreateTracerProviderBuilder() + using (var tracerProvider = Sdk.CreateTracerProviderBuilder() .SetSampler(new TestSampler(samplingDecision)) .AddAspNetInstrumentation() .AddProcessor(activityProcessor.Object).Build()) @@ -312,7 +312,7 @@ public void ExtractContextIrrespectiveOfTheFilterApplied() bool isFilterCalled = false; var activityProcessor = new Mock>(); Sdk.SetDefaultTextMapPropagator(propagator.Object); - using (var openTelemetry = Sdk.CreateTracerProviderBuilder() + using (var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetInstrumentation(options => { options.Filter = context => diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 425bce8a152..db77e75cc2c 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -50,7 +50,7 @@ public sealed class BasicTests : IClassFixture>, IDisposable { private readonly WebApplicationFactory factory; - private TracerProvider openTelemetrySdk = null; + private TracerProvider tracerProvider = null; public BasicTests(WebApplicationFactory factory) { @@ -70,7 +70,7 @@ public async Task StatusIsUnsetOn200Response() var activityProcessor = new Mock>(); void ConfigureTestServices(IServiceCollection services) { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation() .AddProcessor(activityProcessor.Object) .Build(); @@ -114,7 +114,7 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan(bool shouldEnri activityProcessor.Setup(x => x.OnStart(It.IsAny())).Callback(c => c.SetTag("enriched", "no")); void ConfigureTestServices(IServiceCollection services) { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation(options => { if (shouldEnrich) @@ -163,7 +163,7 @@ public async Task SuccessfulTemplateControllerCallUsesParentContext() .WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder().AddAspNetCoreInstrumentation() + this.tracerProvider = Sdk.CreateTracerProviderBuilder().AddAspNetCoreInstrumentation() .AddProcessor(activityProcessor.Object) .Build(); }))) @@ -225,7 +225,7 @@ public async Task CustomPropagator() builder.ConfigureTestServices(services => { Sdk.SetDefaultTextMapPropagator(propagator.Object); - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation() .AddProcessor(activityProcessor.Object) .Build(); @@ -286,7 +286,7 @@ public async Task RequestNotCollectedWhenFilterIsApplied() void ConfigureTestServices(IServiceCollection services) { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation((opt) => opt.Filter = (ctx) => ctx.Request.Path != "/api/values/2") .AddProcessor(activityProcessor.Object) .Build(); @@ -330,7 +330,7 @@ public async Task RequestNotCollectedWhenFilterThrowException() void ConfigureTestServices(IServiceCollection services) { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation((opt) => opt.Filter = (ctx) => { if (ctx.Request.Path == "/api/values/2") @@ -403,7 +403,7 @@ public async Task ExtractContextIrrespectiveOfSamplingDecision(SamplingDecision .WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .SetSampler(new TestSampler(samplingDecision)) .AddAspNetCoreInstrumentation() .Build(); @@ -462,7 +462,7 @@ public async Task ExtractContextIrrespectiveOfTheFilterApplied() .WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation(options => { options.Filter = context => @@ -522,7 +522,7 @@ public async Task BaggageClearedWhenActivityStopped() void ConfigureTestServices(IServiceCollection services) { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation(new AspNetCoreInstrumentation( new TestHttpInListener(new AspNetCoreInstrumentationOptions()) { @@ -572,7 +572,7 @@ public async Task FilterAndEnrichAreOnlyCalledWhenSampled(SamplingDecision sampl bool enrichCalled = false; void ConfigureTestServices(IServiceCollection services) { - this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .SetSampler(new TestSampler(samplingDecision)) .AddAspNetCoreInstrumentation(options => { @@ -605,7 +605,7 @@ void ConfigureTestServices(IServiceCollection services) public void Dispose() { - this.openTelemetrySdk?.Dispose(); + this.tracerProvider?.Dispose(); } private static void WaitForProcessorInvocations(Mock> activityProcessor, int invocationCount) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs index affd904cad0..620438e262e 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs @@ -61,7 +61,7 @@ public void Dispose() public async Task HttpWebRequestInstrumentationInjectsHeadersAsync() { var activityProcessor = new Mock>(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation() .Build(); @@ -108,7 +108,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsyncWhenActivityIs }); Sdk.SetDefaultTextMapPropagator(propagator.Object); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation() .Build(); @@ -155,7 +155,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat( var activityProcessor = new Mock>(); Sdk.SetDefaultTextMapPropagator(propagator.Object); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation() .Build(); @@ -199,7 +199,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat( public async Task HttpWebRequestInstrumentationBacksOffIfAlreadyInstrumented() { var activityProcessor = new Mock>(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation() .Build(); @@ -222,7 +222,7 @@ public async Task HttpWebRequestInstrumentationBacksOffIfAlreadyInstrumented() public async Task RequestNotCollectedWhenInstrumentationFilterApplied() { var activityProcessor = new Mock>(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation( c => c.Filter = (req) => !req.RequestUri.OriginalString.Contains(this.url)) @@ -238,7 +238,7 @@ public async Task RequestNotCollectedWhenInstrumentationFilterApplied() public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException() { var activityProcessor = new Mock>(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation( c => c.Filter = (req) => throw new Exception("From Instrumentation filter")) @@ -256,7 +256,7 @@ public async Task RequestNotCollectedWhenInstrumentationFilterThrowsException() public void AddHttpClientInstrumentationUsesHttpWebRequestInstrumentationOptions() { var activityProcessor = new Mock>(); - using var tracerProviderSdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation(options => { @@ -273,7 +273,7 @@ public async Task HttpWebRequestInstrumentationOnExistingInstance() await client.GetAsync(this.url).ConfigureAwait(false); var activityProcessor = new Mock>(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation() .Build(); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs index 16faa12974c..14c3347da41 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs @@ -46,7 +46,7 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc out var port); var activityProcessor = new Mock>(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .AddHttpClientInstrumentation(options => { diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index d4ab1966c2e..aa313d0717d 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs @@ -84,7 +84,7 @@ public void SuccessfulCommandTest( var activityProcessor = new Mock>(); activityProcessor.Setup(x => x.OnStart(It.IsAny())).Callback(c => c.SetTag("enriched", "no")); var sampler = new TestSampler(); - using var shutdownSignal = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddProcessor(activityProcessor.Object) .SetSampler(sampler) .AddSqlClientInstrumentation(options => diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs index a385124addb..373b8d66be0 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs @@ -30,7 +30,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation public class RedisProfilerEntryToActivityConverterTests : IDisposable { private readonly ConnectionMultiplexer connection; - private readonly IDisposable sdk; + private readonly IDisposable tracerProvider; public RedisProfilerEntryToActivityConverterTests() { @@ -42,14 +42,14 @@ public RedisProfilerEntryToActivityConverterTests() this.connection = ConnectionMultiplexer.Connect(connectionOptions); - this.sdk = Sdk.CreateTracerProviderBuilder() + this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddRedisInstrumentation(this.connection) .Build(); } public void Dispose() { - this.sdk.Dispose(); + this.tracerProvider.Dispose(); this.connection.Dispose(); } diff --git a/test/OpenTelemetry.Tests/Trace/ActivityExtensionsTest.cs b/test/OpenTelemetry.Tests/Trace/ActivityExtensionsTest.cs index a0590ebccd6..b67dc80333e 100644 --- a/test/OpenTelemetry.Tests/Trace/ActivityExtensionsTest.cs +++ b/test/OpenTelemetry.Tests/Trace/ActivityExtensionsTest.cs @@ -30,7 +30,7 @@ public class ActivityExtensionsTest [Fact] public void SetStatus() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -45,7 +45,7 @@ public void SetStatus() [Fact] public void SetStatusWithDescription() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -62,7 +62,7 @@ public void SetStatusWithDescription() [Fact] public void SetStatusWithDescriptionTwice() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -80,7 +80,7 @@ public void SetStatusWithDescriptionTwice() [Fact] public void SetStatusWithIgnoredDescription() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -97,7 +97,7 @@ public void SetStatusWithIgnoredDescription() [Fact] public void SetCancelledStatus() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -112,7 +112,7 @@ public void SetCancelledStatus() [Fact] public void GetStatusWithNoStatusInActivity() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -126,7 +126,7 @@ public void GetStatusWithNoStatusInActivity() [Fact] public void LastSetStatusWins() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); @@ -260,7 +260,7 @@ public void EnumerateLinksEmpty() [Fact] public void EnumerateLinksNonempty() { - using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .Build(); diff --git a/test/OpenTelemetry.Tests/Trace/ExportProcessorTest.cs b/test/OpenTelemetry.Tests/Trace/ExportProcessorTest.cs index 77caab6158a..879e377edce 100644 --- a/test/OpenTelemetry.Tests/Trace/ExportProcessorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/ExportProcessorTest.cs @@ -33,7 +33,7 @@ public void ExportProcessorIgnoresActivityWhenDropped() var exportedItems = new List(); var processor = new TestActivityExportProcessor(new InMemoryExporter(exportedItems)); using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(sampler) .AddProcessor(processor) @@ -55,7 +55,7 @@ public void ExportProcessorIgnoresActivityMarkedAsRecordOnly() var exportedItems = new List(); var processor = new TestActivityExportProcessor(new InMemoryExporter(exportedItems)); using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(sampler) .AddProcessor(processor) @@ -77,7 +77,7 @@ public void ExportProcessorExportsActivityMarkedAsRecordAndSample() var exportedItems = new List(); var processor = new TestActivityExportProcessor(new InMemoryExporter(exportedItems)); using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(sampler) .AddProcessor(processor) diff --git a/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs b/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs index 9f77a567e3b..e0debfd481b 100644 --- a/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs @@ -39,7 +39,7 @@ public void TracerProviderSdkInvokesSamplingWithCorrectParameters() { var testSampler = new TestSampler(); using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(testSampler) .Build(); @@ -123,7 +123,7 @@ public void TracerProviderSdkSamplerAttributesAreAppliedToActivity(SamplingDecis }; using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(testSampler) .Build(); @@ -144,7 +144,7 @@ public void TracerSdkSetsActivitySamplingResultBasedOnSamplingDecision() { var testSampler = new TestSampler(); using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(testSampler) .Build(); @@ -204,7 +204,7 @@ public void TracerSdkSetsActivitySamplingResultToNoneWhenSuppressInstrumentation var testSampler = new TestSampler(); using var activitySource = new ActivitySource(ActivitySourceName); - using var sdk = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(ActivitySourceName) .SetSampler(testSampler) .Build(); diff --git a/test/OpenTelemetry.Tests/Trace/TracerTest.cs b/test/OpenTelemetry.Tests/Trace/TracerTest.cs index ae37588ff89..5df66f9138d 100644 --- a/test/OpenTelemetry.Tests/Trace/TracerTest.cs +++ b/test/OpenTelemetry.Tests/Trace/TracerTest.cs @@ -60,7 +60,7 @@ public void TracerStartReturnsNoopSpanWhenNoSdk() [Fact] public void Tracer_StartRootSpan_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -77,7 +77,7 @@ public void Tracer_StartRootSpan_BadArgs_NullSpanName() [Fact] public void Tracer_StartSpan_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -94,7 +94,7 @@ public void Tracer_StartSpan_BadArgs_NullSpanName() [Fact] public void Tracer_StartActiveSpan_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -111,7 +111,7 @@ public void Tracer_StartActiveSpan_BadArgs_NullSpanName() [Fact] public void Tracer_StartSpan_FromParent_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -125,7 +125,7 @@ public void Tracer_StartSpan_FromParent_BadArgs_NullSpanName() [Fact] public void Tracer_StartSpan_FromParentContext_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -141,7 +141,7 @@ public void Tracer_StartSpan_FromParentContext_BadArgs_NullSpanName() [Fact] public void Tracer_StartActiveSpan_FromParent_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -155,7 +155,7 @@ public void Tracer_StartActiveSpan_FromParent_BadArgs_NullSpanName() [Fact] public void Tracer_StartActiveSpan_FromParentContext_BadArgs_NullSpanName() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -171,7 +171,7 @@ public void Tracer_StartActiveSpan_FromParentContext_BadArgs_NullSpanName() [Fact] public void Tracer_StartActiveSpan_CreatesActiveSpan() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -195,7 +195,7 @@ public void Tracer_StartActiveSpan_CreatesActiveSpan() [Fact] public void GetCurrentSpanBlank() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); Assert.False(Tracer.CurrentSpan.Context.IsValid); @@ -204,7 +204,7 @@ public void GetCurrentSpanBlank() [Fact] public void GetCurrentSpanBlankWontThrowOnEnd() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); var current = Tracer.CurrentSpan; @@ -214,7 +214,7 @@ public void GetCurrentSpanBlankWontThrowOnEnd() [Fact] public void GetCurrentSpan() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); @@ -228,7 +228,7 @@ public void GetCurrentSpan() [Fact] public void CreateSpan_Sampled() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .Build(); var span = this.tracer.StartSpan("foo"); @@ -238,7 +238,7 @@ public void CreateSpan_Sampled() [Fact] public void CreateSpan_NotSampled() { - using var openTelemetry = Sdk.CreateTracerProviderBuilder() + using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("tracername") .SetSampler(new AlwaysOffSampler()) .Build();