diff --git a/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs index 0687bd2582..5f57879521 100644 --- a/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.ElasticsearchClient/Implementation/ElasticsearchRequestPipelineDiagnosticListener.cs @@ -57,6 +57,8 @@ public override void OnEventWritten(string name, object? payload) case "CallElasticsearch.Stop": this.OnStopActivity(activity, payload); break; + default: + break; } } @@ -69,12 +71,7 @@ private static string GetDisplayName(Activity activity, object? method, string? case "CallElasticsearch" when method != null: { var methodName = MethodNameCache.GetOrAdd(method, $"Elasticsearch {method}"); - if (elasticType == null) - { - return methodName; - } - - return $"{methodName} {elasticType}"; + return elasticType == null ? methodName : $"{methodName} {elasticType}"; } default: @@ -122,7 +119,7 @@ private string ParseAndFormatRequest(string debugInformation) var request = ParseRequest.Match(debugInformation); if (request.Success) { - string? body = request.Groups[1]?.Value?.Trim(); + var body = request.Groups[1]?.Value?.Trim(); if (body == null) { return debugInformation; @@ -193,7 +190,7 @@ private void OnStartActivity(Activity activity, object? payload) } var uriHostNameType = Uri.CheckHostName(uri.Host); - if (uriHostNameType == UriHostNameType.IPv4 || uriHostNameType == UriHostNameType.IPv6) + if (uriHostNameType is UriHostNameType.IPv4 or UriHostNameType.IPv6) { activity.SetTag(SemanticConventions.AttributeNetPeerIp, uri.Host); } @@ -269,14 +266,10 @@ private void OnStopActivity(Activity activity, object? payload) if (originalException is HttpRequestException) { - if (originalException.InnerException is SocketException exception) + if (originalException.InnerException is SocketException { SocketErrorCode: SocketError.HostNotFound }) { - switch (exception.SocketErrorCode) - { - case SocketError.HostNotFound: - activity.SetStatus(Status.Error.WithDescription(originalException.Message)); - return; - } + activity.SetStatus(Status.Error.WithDescription(originalException.Message)); + return; } if (originalException.InnerException != null) diff --git a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/Customer.cs b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/Customer.cs index 2ace4b977c..a0d5bbe566 100644 --- a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/Customer.cs +++ b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/Customer.cs @@ -3,7 +3,7 @@ namespace OpenTelemetry.Instrumentation.ElasticsearchClient.Tests; -public class Customer +internal class Customer { public string? Id { get; set; } diff --git a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/DependencyInjectionConfigTests.cs b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/DependencyInjectionConfigTests.cs index fc2abb01ae..b8a3d14c34 100644 --- a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/DependencyInjectionConfigTests.cs +++ b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/DependencyInjectionConfigTests.cs @@ -15,7 +15,7 @@ public class DependencyInjectionConfigTests [InlineData("CustomName")] public async Task TestTracingOptionsDiConfig(string? name) { - bool optionsPickedFromDi = false; + var optionsPickedFromDi = false; var services = new ServiceCollection(); diff --git a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/ElasticsearchClientTests.cs b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/ElasticsearchClientTests.cs index 2d8cf5a40b..5e23f346c5 100644 --- a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/ElasticsearchClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/ElasticsearchClientTests.cs @@ -181,7 +181,7 @@ public async Task CanCaptureSearchCall() [Fact] public async Task CanRecordAndSampleSearchCall() { - bool samplerCalled = false; + var samplerCalled = false; var sampler = new TestSampler { @@ -193,10 +193,10 @@ public async Task CanRecordAndSampleSearchCall() }, }; - using TestActivityProcessor testActivityProcessor = new TestActivityProcessor(); + using var testActivityProcessor = new TestActivityProcessor(); - int startCalled = 0; - int endCalled = 0; + var startCalled = 0; + var endCalled = 0; testActivityProcessor.StartAction = (a) => @@ -239,9 +239,9 @@ public async Task CanRecordAndSampleSearchCall() } [Fact] - public async Task CanSupressDownstreamActivities() + public async Task CanSuppressDownstreamActivities() { - bool samplerCalled = false; + var samplerCalled = false; var sampler = new TestSampler { @@ -253,10 +253,10 @@ public async Task CanSupressDownstreamActivities() }, }; - using TestActivityProcessor testActivityProcessor = new TestActivityProcessor(); + using var testActivityProcessor = new TestActivityProcessor(); - int startCalled = 0; - int endCalled = 0; + var startCalled = 0; + var endCalled = 0; testActivityProcessor.StartAction = (a) => @@ -301,7 +301,7 @@ public async Task CanSupressDownstreamActivities() [Fact] public async Task CanDropSearchCall() { - bool samplerCalled = false; + var samplerCalled = false; var sampler = new TestSampler { @@ -313,10 +313,10 @@ public async Task CanDropSearchCall() }, }; - using TestActivityProcessor testActivityProcessor = new TestActivityProcessor(); + using var testActivityProcessor = new TestActivityProcessor(); - int startCalled = 0; - int endCalled = 0; + var startCalled = 0; + var endCalled = 0; testActivityProcessor.StartAction = (a) => @@ -725,8 +725,8 @@ public async Task DoesNotCaptureWhenInstrumentationIsSuppressed() public async Task CapturesBasedOnSamplingDecision(SamplingDecision samplingDecision, bool isActivityExpected) { var expectedResource = ResourceBuilder.CreateDefault().AddService("test-service"); - bool startActivityCalled = false; - bool endActivityCalled = false; + var startActivityCalled = false; + var endActivityCalled = false; var processor = new TestActivityProcessor( activity => startActivityCalled = true, activity => endActivityCalled = true); @@ -851,7 +851,7 @@ public async Task ShouldRemoveSensitiveInformation() Assert.Single(exportedItems); var searchActivity = exportedItems[0]; - string? dbUrl = (string?)searchActivity.GetTagValue(SemanticConventions.AttributeUrlFull); + var dbUrl = (string?)searchActivity.GetTagValue(SemanticConventions.AttributeUrlFull); Assert.DoesNotContain("sensitive", dbUrl); Assert.Contains("REDACTED:REDACTED", dbUrl); diff --git a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/InMemoryConnectionWithDownstreamActivity.cs b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/InMemoryConnectionWithDownstreamActivity.cs index ba9dfa1278..8fdb784976 100644 --- a/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/InMemoryConnectionWithDownstreamActivity.cs +++ b/test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/InMemoryConnectionWithDownstreamActivity.cs @@ -6,10 +6,10 @@ namespace OpenTelemetry.Instrumentation.ElasticsearchClient.Tests; -public class InMemoryConnectionWithDownstreamActivity : InMemoryConnection +internal class InMemoryConnectionWithDownstreamActivity : InMemoryConnection { - internal static readonly ActivitySource ActivitySource = new ActivitySource("Downstream"); - internal static readonly ActivitySource NestedActivitySource = new ActivitySource("NestedDownstream"); + internal static readonly ActivitySource ActivitySource = new("Downstream"); + internal static readonly ActivitySource NestedActivitySource = new("NestedDownstream"); public override Task RequestAsync(RequestData requestData, CancellationToken cancellationToken) {