From 35a75d553768ed317b88f8d04d805ffd8a0f3399 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:40:34 -0800 Subject: [PATCH 1/9] Fix code analysis warnings --- examples/AspNet/Global.asax.cs | 4 ++-- examples/wcf/server-aspnetframework/Global.asax.cs | 2 +- .../TracerProviderBuilderExtensions.cs | 4 ++++ .../Implementation/AWSLambdaHttpUtils.cs | 2 ++ .../HangfireInstrumentationJobFilterAttribute.cs | 4 ++-- .../AWSECSResourceDetector.cs | 2 ++ .../InfluxDBMetricsExporterTests.cs | 5 +++-- .../Tools/MockWebResponse.cs | 4 +++- .../Implementation/AWSLambdaHttpUtilsTests.cs | 6 ++++++ .../EntityFrameworkDiagnosticListenerTests.cs | 2 +- .../RedisProfilerEntryToActivityConverterTests.cs | 2 +- .../StackExchangeRedisCallsInstrumentationTests.cs | 2 +- .../AWSECSResourceDetectorTests.cs | 4 ++++ 13 files changed, 32 insertions(+), 11 deletions(-) diff --git a/examples/AspNet/Global.asax.cs b/examples/AspNet/Global.asax.cs index e8318035b9..ba77e849f4 100644 --- a/examples/AspNet/Global.asax.cs +++ b/examples/AspNet/Global.asax.cs @@ -31,8 +31,8 @@ namespace Examples.AspNet; public class WebApiApplication : HttpApplication #pragma warning restore SA1649 // File name should match first type name { - private IDisposable? tracerProvider; - private IDisposable? meterProvider; + private TracerProvider? tracerProvider; + private MeterProvider? meterProvider; protected void Application_Start() { diff --git a/examples/wcf/server-aspnetframework/Global.asax.cs b/examples/wcf/server-aspnetframework/Global.asax.cs index 692259cc99..0546cd33fb 100644 --- a/examples/wcf/server-aspnetframework/Global.asax.cs +++ b/examples/wcf/server-aspnetframework/Global.asax.cs @@ -29,7 +29,7 @@ namespace Examples.Wcf.Server.AspNetFramework; public class WebApiApplication : HttpApplication #pragma warning restore SA1649 // File name should match first type name { - private IDisposable? tracerProvider; + private TracerProvider? tracerProvider; protected void Application_Start() { diff --git a/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs index a21b3af4d8..f105c9243b 100644 --- a/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs @@ -47,10 +47,14 @@ public static TracerProviderBuilder AddAutoFlushActivityProcessor( Func predicate, int timeoutMilliseconds = 10000) { +#if NET6_0_OR_GREATER + ArgumentNullException.ThrowIfNull(builder); +#else if (builder == null) { throw new ArgumentNullException(nameof(builder)); } +#endif #pragma warning disable CA2000 // Dispose objects before losing scope return builder.AddProcessor(new AutoFlushActivityProcessor(predicate, timeoutMilliseconds)); diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs index dc1d068658..d0633e2979 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs @@ -124,7 +124,9 @@ internal static (string? Host, int? Port) GetHostAndPort(string? httpScheme, str return (null, null); } +#pragma warning disable CA1861 // Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array var hostAndPort = hostHeader.Split(new char[] { ':' }, 2); +#pragma warning restore CA1861 // Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array if (hostAndPort.Length > 1) { var host = hostAndPort[0]; diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs index b161bfe284..3312ec136b 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs +++ b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs @@ -76,12 +76,12 @@ public void OnPerforming(PerformingContext performingContext) public void OnPerformed(PerformedContext performedContext) { // Short-circuit if nobody is listening - if (!HangfireInstrumentation.ActivitySource.HasListeners() || !performedContext.Items.ContainsKey(HangfireInstrumentationConstants.ActivityKey)) + if (!HangfireInstrumentation.ActivitySource.HasListeners() || !performedContext.Items.TryGetValue(HangfireInstrumentationConstants.ActivityKey, out var value)) { return; } - if (performedContext.Items[HangfireInstrumentationConstants.ActivityKey] is Activity activity) + if (value is Activity activity) { if (performedContext.Exception != null) { diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/AWSECSResourceDetector.cs b/src/OpenTelemetry.ResourceDetectors.AWS/AWSECSResourceDetector.cs index 5e59597d3e..2784b94c47 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/AWSECSResourceDetector.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/AWSECSResourceDetector.cs @@ -106,7 +106,9 @@ internal static List> ExtractMetadataV4ResourceAttr if (!clusterArn.StartsWith("arn:", StringComparison.Ordinal)) { +#pragma warning disable CA1865 // Use string.LastIndexOf(char) instead of string.LastIndexOf(string) when you have string with a single char var baseArn = containerArn.Substring(containerArn.LastIndexOf(":", StringComparison.Ordinal)); +#pragma warning restore CA1865 // Use string.LastIndexOf(char) instead of string.LastIndexOf(string) when you have string with a single char clusterArn = $"{baseArn}:cluster/{clusterArn}"; } diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs index c65d10534b..d2b6ff6332 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/InfluxDBMetricsExporterTests.cs @@ -25,6 +25,7 @@ namespace OpenTelemetry.Exporter.InfluxDB.Tests; public class InfluxDBMetricsExporterTests { private static readonly string OpenTelemetrySdkVersion; + private static readonly double[] TestBoundaries = new[] { 10D, 20D, 100D, 200D }; #pragma warning disable CA1810 // Initialize reference type static fields inline static InfluxDBMetricsExporterTests() @@ -312,7 +313,7 @@ public void ExportHistogramMetricWhenTelegrafPrometheusV1MetricsSchemaUsed() .AddMeter(meter.Name) .AddView("histogram_metric", new ExplicitBucketHistogramConfiguration { - Boundaries = new[] { 10D, 20D, 100D, 200D }, + Boundaries = TestBoundaries, RecordMinMax = true, }) .ConfigureDefaultTestResource() @@ -403,7 +404,7 @@ public void ExportHistogramMetricWhenTelegrafPrometheusV2MetricsSchemaUsed() .AddMeter(meter.Name) .AddView("histogram_metric", new ExplicitBucketHistogramConfiguration { - Boundaries = new[] { 10D, 20D, 100D, 200D }, + Boundaries = TestBoundaries, RecordMinMax = true, }) .ConfigureDefaultTestResource() diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs index 89c4206bf8..7f89215775 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs @@ -115,7 +115,7 @@ public static HttpResponseMessage Create(HttpStatusCode statusCode, IDictionary< } } - httpResponseMessage.StatusCode = statusCode; + httpResponseMessage!.StatusCode = statusCode; string dummyJson = "{\"key1\":\"value1\"}"; httpResponseMessage.Content = new StringContent(body ?? dummyJson); // Content should be in Json format else we get exception from downstream unmarshalling return httpResponseMessage; @@ -152,7 +152,9 @@ public static HttpResponse ParseRawReponse(string rawResponse) break; } +#pragma warning disable CA1865 // Use char overload var index = currentLine.IndexOf(":", StringComparison.Ordinal); +#pragma warning restore CA1865 // Use char overload if (index != -1) { var headerKey = currentLine.Substring(0, index); diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs index 5b1ed55399..8b89ded1e0 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs @@ -40,7 +40,9 @@ public void GetHttpTags_APIGatewayProxyRequest_ReturnsCorrectTags() }, MultiValueQueryStringParameters = new Dictionary> { +#pragma warning disable CA1861 // Avoid constant arrays as arguments { "q1", new[] { "value1" } }, +#pragma warning restore CA1861 // Avoid constant arrays as arguments }, RequestContext = new APIGatewayProxyRequest.ProxyRequestContext { @@ -70,7 +72,9 @@ public void GetHttpTags_APIGatewayProxyRequestWithEmptyContext_ReturnsTagsFromRe { MultiValueQueryStringParameters = new Dictionary> { +#pragma warning disable CA1861 // Avoid constant arrays as arguments { "q1", new[] { "value1" } }, +#pragma warning restore CA1861 // Avoid constant arrays as arguments }, HttpMethod = "POST", Path = "/path/test", @@ -251,11 +255,13 @@ public void GetHostAndPort_HostHeader_ReturnsCorrectHostAndPort(string httpSchem [Theory] [InlineData(null, "")] +#pragma warning disable CA1861 // Avoid constant arrays as arguments [InlineData(new string[] { }, "")] [InlineData(new[] { "value1" }, "?name=value1")] [InlineData(new[] { "value$a" }, "?name=value%24a")] [InlineData(new[] { "value 1" }, "?name=value+1")] [InlineData(new[] { "value1", "value2" }, "?name=value1&name=value2")] +#pragma warning restore CA1861 // Avoid constant arrays as arguments public void GetQueryString_APIGatewayProxyRequest_CorrectQueryString(IList values, string expectedQueryString) { var request = new APIGatewayProxyRequest(); diff --git a/test/OpenTelemetry.Instrumentation.EntityFrameworkCore.Tests/EntityFrameworkDiagnosticListenerTests.cs b/test/OpenTelemetry.Instrumentation.EntityFrameworkCore.Tests/EntityFrameworkDiagnosticListenerTests.cs index 2d8f653c64..e162527a20 100644 --- a/test/OpenTelemetry.Instrumentation.EntityFrameworkCore.Tests/EntityFrameworkDiagnosticListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.EntityFrameworkCore.Tests/EntityFrameworkDiagnosticListenerTests.cs @@ -248,7 +248,7 @@ public void ShouldCollectTelemetryWhenFilterEvaluatesToTrueByProviderName() public void Dispose() => this.connection.Dispose(); - private static DbConnection CreateInMemoryDatabase() + private static SqliteConnection CreateInMemoryDatabase() { var connection = new SqliteConnection("Filename=:memory:"); diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs index 84aa7076a4..65df35d8d6 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Implementation/RedisProfilerEntryToActivityConverterTests.cs @@ -33,7 +33,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation; public class RedisProfilerEntryToActivityConverterTests : IDisposable { private readonly ConnectionMultiplexer connection; - private readonly IDisposable tracerProvider; + private readonly TracerProvider tracerProvider; public RedisProfilerEntryToActivityConverterTests() { diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index 4ac9568f8c..25372ff51f 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -108,7 +108,7 @@ public void SuccessfulCommandTest(string value) }; connectionOptions.EndPoints.Add(RedisEndPoint); - IConnectionMultiplexer? connection = null; + ConnectionMultiplexer? connection = null; var activityProcessor = new Mock>(); var sampler = new TestSampler(); using (Sdk.CreateTracerProviderBuilder() diff --git a/test/OpenTelemetry.ResourceDetectors.AWS.Tests/AWSECSResourceDetectorTests.cs b/test/OpenTelemetry.ResourceDetectors.AWS.Tests/AWSECSResourceDetectorTests.cs index 816505a9e5..16e1c5602a 100644 --- a/test/OpenTelemetry.ResourceDetectors.AWS.Tests/AWSECSResourceDetectorTests.cs +++ b/test/OpenTelemetry.ResourceDetectors.AWS.Tests/AWSECSResourceDetectorTests.cs @@ -91,10 +91,12 @@ public async void TestEcsMetadataV4Ec2() Assert.Equal(resourceAttributes[AWSSemanticConventions.AttributeEcsTaskArn], "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c"); Assert.Equal(resourceAttributes[AWSSemanticConventions.AttributeEcsTaskFamily], "curltest"); Assert.Equal(resourceAttributes[AWSSemanticConventions.AttributeEcsTaskRevision], "26"); +#pragma warning disable CA1861 // Avoid constant arrays as arguments Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogGroupNames], new string[] { "/ecs/metadata" }); Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogGroupArns], new string[] { "arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata" }); Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogStreamNames], new string[] { "ecs/curl/8f03e41243824aea923aca126495f665" }); Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogStreamArns], new string[] { "arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665" }); +#pragma warning restore CA1861 // Avoid constant arrays as arguments } } @@ -117,10 +119,12 @@ public async void TestEcsMetadataV4Fargate() Assert.Equal(resourceAttributes[AWSSemanticConventions.AttributeEcsTaskArn], "arn:aws:ecs:us-west-2:111122223333:task/default/e9028f8d5d8e4f258373e7b93ce9a3c3"); Assert.Equal(resourceAttributes[AWSSemanticConventions.AttributeEcsTaskFamily], "curltest"); Assert.Equal(resourceAttributes[AWSSemanticConventions.AttributeEcsTaskRevision], "3"); +#pragma warning disable CA1861 // Avoid constant arrays as arguments Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogGroupNames], new string[] { "/ecs/containerlogs" }); Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogGroupArns], new string[] { "arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs" }); Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogStreamNames], new string[] { "ecs/curl/cd189a933e5849daa93386466019ab50" }); Assert.NotStrictEqual(resourceAttributes[AWSSemanticConventions.AttributeLogStreamArns], new string[] { "arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:log-stream:ecs/curl/cd189a933e5849daa93386466019ab50" }); +#pragma warning restore CA1861 // Avoid constant arrays as arguments } } From 573a85429d37fe75d25be729ece0365042e08bda Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:15:33 -0800 Subject: [PATCH 2/9] Code changes --- .../Internal/Transports/HttpJsonPostTransport.cs | 3 +++ .../Internal/Transports/IHttpClient.cs | 4 ++++ .../Logs/OneCollectorLogExportProcessorBuilder.cs | 3 +++ .../Utils/LineProtocolParser.cs | 2 ++ .../LogRecordCommonSchemaJsonHttpPostBenchmarks.cs | 3 +++ .../HttpJsonPostTransportTests.cs | 3 +++ 6 files changed, 18 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs index 4df899a238..c9754c1752 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs @@ -17,6 +17,9 @@ using System.Diagnostics; using System.IO.Compression; using System.Net; +#if NETFRAMEWORK +using System.Net.Http; +#endif using System.Net.Http.Headers; using OpenTelemetry.Internal; diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs index 66dff2933b..ec344e7826 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs @@ -14,6 +14,10 @@ // limitations under the License. // +#if NETFRAMEWORK +using System.Net.Http; +#endif + namespace OpenTelemetry.Exporter.OneCollector; internal interface IHttpClient diff --git a/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExportProcessorBuilder.cs b/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExportProcessorBuilder.cs index 28528d8297..99d9b23398 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExportProcessorBuilder.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Logs/OneCollectorLogExportProcessorBuilder.cs @@ -14,6 +14,9 @@ // limitations under the License. // +#if NETFRAMEWORK +using System.Net.Http; +#endif using Microsoft.Extensions.Configuration; using OpenTelemetry.Exporter.OneCollector; using OpenTelemetry.Internal; diff --git a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs index 97764fbbdf..bca009a4f1 100644 --- a/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs +++ b/test/OpenTelemetry.Exporter.InfluxDB.Tests/Utils/LineProtocolParser.cs @@ -75,11 +75,13 @@ private static object ParseFieldValue(string fieldValue) return boolValue; } +#pragma warning disable CA1865 // Use char overload if (fieldValue.EndsWith("i", StringComparison.Ordinal) && long.TryParse(fieldValue.AsSpan(0, fieldValue.Length - 1).ToString(), out long intValue)) { return intValue; } +#pragma warning restore CA1865 // Use char overload if (double.TryParse(fieldValue, NumberStyles.Float, CultureInfo.InvariantCulture, out double doubleValue)) { diff --git a/test/OpenTelemetry.Exporter.OneCollector.Benchmarks/LogRecordCommonSchemaJsonHttpPostBenchmarks.cs b/test/OpenTelemetry.Exporter.OneCollector.Benchmarks/LogRecordCommonSchemaJsonHttpPostBenchmarks.cs index 05762f02a2..21c2c60ead 100644 --- a/test/OpenTelemetry.Exporter.OneCollector.Benchmarks/LogRecordCommonSchemaJsonHttpPostBenchmarks.cs +++ b/test/OpenTelemetry.Exporter.OneCollector.Benchmarks/LogRecordCommonSchemaJsonHttpPostBenchmarks.cs @@ -16,6 +16,9 @@ using System.Diagnostics; using System.Net; +#if NETFRAMEWORK +using System.Net.Http; +#endif using System.Reflection; using BenchmarkDotNet.Attributes; using Microsoft.Extensions.Logging; diff --git a/test/OpenTelemetry.Exporter.OneCollector.Tests/HttpJsonPostTransportTests.cs b/test/OpenTelemetry.Exporter.OneCollector.Tests/HttpJsonPostTransportTests.cs index 736ef9a848..25f535d6e8 100644 --- a/test/OpenTelemetry.Exporter.OneCollector.Tests/HttpJsonPostTransportTests.cs +++ b/test/OpenTelemetry.Exporter.OneCollector.Tests/HttpJsonPostTransportTests.cs @@ -16,6 +16,9 @@ using System.IO.Compression; using System.Net; +#if NETFRAMEWORK +using System.Net.Http; +#endif using System.Text; using OpenTelemetry.Tests; using Xunit; From c32ead928f35eff3c8185540b9b0d02a75a4f4a2 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:35:01 -0800 Subject: [PATCH 3/9] Update global.json --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index aeb8ae7b1e..0aca8b1293 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "rollForward": "latestFeature", - "version": "7.0.400" + "version": "8.0.100" } } From 4905edbdda0ca7a3ab3af302e64648a2f71ad0a3 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:50:51 -0800 Subject: [PATCH 4/9] Fix CI --- .github/workflows/integration.yml | 2 +- ...penTelemetry.Instrumentation.StackExchangeRedis.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 050da674c3..17fc8a9da9 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - version: [net6.0,net7.0] + version: [net6.0, net7.0, net8.0] steps: - uses: actions/checkout@v4 diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests.csproj b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests.csproj index 54185af2cd..71970f56c2 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests.csproj +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests.csproj @@ -2,7 +2,7 @@ Unit test project for OpenTelemetry StackExchangeRedis instrumentation - net7.0;net6.0 + net8.0;net7.0;net6.0 $(TargetFrameworks);net462 $(TARGET_FRAMEWORK) From 76e610238740e69bb44fbf5b171c61095b19b6ef Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:00:10 -0800 Subject: [PATCH 5/9] Fix CI --- build/docker-compose.net6.0.yml | 4 ++-- build/docker-compose.net7.0.yml | 4 ++-- build/docker-compose.net8.0.yml | 9 +++++++++ opentelemetry-dotnet-contrib.sln | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 build/docker-compose.net8.0.yml diff --git a/build/docker-compose.net6.0.yml b/build/docker-compose.net6.0.yml index 0d59259753..099f100727 100644 --- a/build/docker-compose.net6.0.yml +++ b/build/docker-compose.net6.0.yml @@ -5,5 +5,5 @@ services: build: args: PUBLISH_FRAMEWORK: net6.0 - TEST_SDK_VERSION: 6.0 - BUILD_SDK_VERSION: 7.0 + TEST_SDK_VERSION: "6.0" + BUILD_SDK_VERSION: "8.0" diff --git a/build/docker-compose.net7.0.yml b/build/docker-compose.net7.0.yml index d79fa366bb..48a2589cda 100644 --- a/build/docker-compose.net7.0.yml +++ b/build/docker-compose.net7.0.yml @@ -5,5 +5,5 @@ services: build: args: PUBLISH_FRAMEWORK: net7.0 - TEST_SDK_VERSION: 7.0 - BUILD_SDK_VERSION: 7.0 + TEST_SDK_VERSION: "7.0" + BUILD_SDK_VERSION: "8.0" diff --git a/build/docker-compose.net8.0.yml b/build/docker-compose.net8.0.yml new file mode 100644 index 0000000000..a5ac999e43 --- /dev/null +++ b/build/docker-compose.net8.0.yml @@ -0,0 +1,9 @@ +version: '3.7' + +services: + tests: + build: + args: + PUBLISH_FRAMEWORK: net8.0 + TEST_SDK_VERSION: "8.0" + BUILD_SDK_VERSION: "8.0" diff --git a/opentelemetry-dotnet-contrib.sln b/opentelemetry-dotnet-contrib.sln index 6435228624..e58e0c5f4c 100644 --- a/opentelemetry-dotnet-contrib.sln +++ b/opentelemetry-dotnet-contrib.sln @@ -75,6 +75,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{824BD1DE build\debug.snk = build\debug.snk build\docker-compose.net6.0.yml = build\docker-compose.net6.0.yml build\docker-compose.net7.0.yml = build\docker-compose.net7.0.yml + build\docker-compose.net8.0.yml = build\docker-compose.net8.0.yml build\opentelemetry-icon-color.png = build\opentelemetry-icon-color.png build\OpenTelemetryContrib.prod.ruleset = build\OpenTelemetryContrib.prod.ruleset build\OpenTelemetryContrib.test.ruleset = build\OpenTelemetryContrib.test.ruleset From a0616dbca2de845e977d0415c5a934d5cc0b6f76 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:17:06 -0800 Subject: [PATCH 6/9] Fix CI --- .../Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Dockerfile b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Dockerfile index 945e7a4d9d..a8f86395df 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Dockerfile +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Dockerfile @@ -2,12 +2,12 @@ # This should be run from the root of the repo: # docker build --file test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/Dockerfile . -ARG BUILD_SDK_VERSION=7.0 -ARG TEST_SDK_VERSION=7.0 +ARG BUILD_SDK_VERSION=8.0 +ARG TEST_SDK_VERSION=8.0 FROM mcr.microsoft.com/dotnet/sdk:${BUILD_SDK_VERSION} AS build ARG PUBLISH_CONFIGURATION=Release -ARG PUBLISH_FRAMEWORK=net7.0 +ARG PUBLISH_FRAMEWORK=net8.0 WORKDIR /repo COPY . ./ WORKDIR "/repo/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests" From 5305f67426f81ec40c6c2fd7e6aac9e51b0abd4e Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:28:35 -0800 Subject: [PATCH 7/9] Fix unit test --- .../StackExchangeRedisCallsInstrumentationTests.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index 25372ff51f..cedfd5c093 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -108,17 +108,10 @@ public void SuccessfulCommandTest(string value) }; connectionOptions.EndPoints.Add(RedisEndPoint); - ConnectionMultiplexer? connection = null; + using var connection = ConnectionMultiplexer.Connect(connectionOptions); var activityProcessor = new Mock>(); var sampler = new TestSampler(); using (Sdk.CreateTracerProviderBuilder() - .ConfigureServices(services => - { - services.TryAddSingleton(sp => - { - return connection = ConnectionMultiplexer.Connect(connectionOptions); - }); - }) .AddProcessor(activityProcessor.Object) .SetSampler(sampler) .AddRedisInstrumentation(c => c.SetVerboseDatabaseStatements = false) From fe5694b6ad6b44f1e41c5319d9c4064596f1b7ec Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:35:59 -0800 Subject: [PATCH 8/9] Fix unit test --- .../StackExchangeRedisCallsInstrumentationTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index cedfd5c093..985acf6268 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -19,7 +19,6 @@ using System.Net; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Moq; using OpenTelemetry.Tests; using OpenTelemetry.Trace; From 871571ee702105454356aa94750789bd922e5d03 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 30 Nov 2023 13:06:36 -0800 Subject: [PATCH 9/9] Fix redis integration test. --- .../StackExchangeRedisCallsInstrumentationTests.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index 985acf6268..d80d1a0f47 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -19,6 +19,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Moq; using OpenTelemetry.Tests; using OpenTelemetry.Trace; @@ -107,10 +108,17 @@ public void SuccessfulCommandTest(string value) }; connectionOptions.EndPoints.Add(RedisEndPoint); - using var connection = ConnectionMultiplexer.Connect(connectionOptions); + ConnectionMultiplexer? connection = null; var activityProcessor = new Mock>(); var sampler = new TestSampler(); using (Sdk.CreateTracerProviderBuilder() + .ConfigureServices(services => + { + services.TryAddSingleton(sp => + { + return connection = ConnectionMultiplexer.Connect(connectionOptions); + }); + }) .AddProcessor(activityProcessor.Object) .SetSampler(sampler) .AddRedisInstrumentation(c => c.SetVerboseDatabaseStatements = false)