Skip to content

Commit 41e1a59

Browse files
SimonCroppKielekrajkumar-rangaraj
authored
Increase use of NotNullWhen polyfill (#6090)
Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com> Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
1 parent 720d610 commit 41e1a59

File tree

8 files changed

+11
-28
lines changed

8 files changed

+11
-28
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ExperimentalOptions(IConfiguration configuration)
2929
this.EmitLogEventAttributes = emitLogEventAttributes;
3030
}
3131

32-
if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy) && retryPolicy != null)
32+
if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy))
3333
{
3434
if (retryPolicy.Equals("in_memory", StringComparison.OrdinalIgnoreCase))
3535
{
@@ -38,7 +38,7 @@ public ExperimentalOptions(IConfiguration configuration)
3838
else if (retryPolicy.Equals("disk", StringComparison.OrdinalIgnoreCase))
3939
{
4040
this.EnableDiskRetry = true;
41-
if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path) && path != null)
41+
if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path))
4242
{
4343
this.DiskRetryDirectoryPath = path;
4444
}

src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal ZipkinExporterOptions(
4242

4343
if (configuration!.TryGetUriValue(ZipkinExporterEventSource.Log, ZipkinEndpointEnvVar, out var endpoint))
4444
{
45-
this.Endpoint = endpoint!;
45+
this.Endpoint = endpoint;
4646
}
4747

4848
this.BatchExportProcessorOptions = defaultBatchOptions!;

src/OpenTelemetry/Logs/LoggerProviderSdk.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5-
#if NETSTANDARD2_1_OR_GREATER || NET
65
using System.Diagnostics.CodeAnalysis;
7-
#endif
86
using System.Text;
97
using Microsoft.Extensions.DependencyInjection;
108
using OpenTelemetry.Internal;
@@ -201,9 +199,7 @@ public bool ContainsBatchProcessor(BaseProcessor<LogRecord> processor)
201199
#endif
202200
override bool TryCreateLogger(
203201
string? name,
204-
#if NETSTANDARD2_1_OR_GREATER || NET
205202
[NotNullWhen(true)]
206-
#endif
207203
out Logger? logger)
208204
{
209205
logger = new LoggerSdk(this, name);

src/OpenTelemetry/Resources/OtelEnvResourceDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Resource Detect()
2424

2525
if (this.configuration.TryGetStringValue(EnvVarKey, out string? envResourceAttributeValue))
2626
{
27-
var attributes = ParseResourceAttributes(envResourceAttributeValue!);
27+
var attributes = ParseResourceAttributes(envResourceAttributeValue);
2828
resource = new Resource(attributes);
2929
}
3030

src/OpenTelemetry/Resources/OtelServiceNameEnvVarDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Resource Detect()
2424
{
2525
resource = new Resource(new Dictionary<string, object>
2626
{
27-
[ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue!,
27+
[ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue,
2828
});
2929
}
3030

src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5-
#if !NETFRAMEWORK && !NETSTANDARD2_0
65
using System.Diagnostics.CodeAnalysis;
7-
#endif
86
using System.Globalization;
97

108
namespace Microsoft.Extensions.Configuration;
@@ -13,17 +11,13 @@ internal static class OpenTelemetryConfigurationExtensions
1311
{
1412
public delegate bool TryParseFunc<T>(
1513
string value,
16-
#if !NETFRAMEWORK && !NETSTANDARD2_0
1714
[NotNullWhen(true)]
18-
#endif
1915
out T? parsedValue);
2016

2117
public static bool TryGetStringValue(
2218
this IConfiguration configuration,
2319
string key,
24-
#if !NETFRAMEWORK && !NETSTANDARD2_0
2520
[NotNullWhen(true)]
26-
#endif
2721
out string? value)
2822
{
2923
Debug.Assert(configuration != null, "configuration was null");
@@ -37,9 +31,7 @@ public static bool TryGetUriValue(
3731
this IConfiguration configuration,
3832
IConfigurationExtensionsLogger logger,
3933
string key,
40-
#if !NETFRAMEWORK && !NETSTANDARD2_0
4134
[NotNullWhen(true)]
42-
#endif
4335
out Uri? value)
4436
{
4537
Debug.Assert(logger != null, "logger was null");
@@ -52,7 +44,7 @@ public static bool TryGetUriValue(
5244

5345
if (!Uri.TryCreate(stringValue, UriKind.Absolute, out value))
5446
{
55-
logger!.LogInvalidConfigurationValue(key, stringValue!);
47+
logger!.LogInvalidConfigurationValue(key, stringValue);
5648
return false;
5749
}
5850

@@ -75,7 +67,7 @@ public static bool TryGetIntValue(
7567

7668
if (!int.TryParse(stringValue, NumberStyles.None, CultureInfo.InvariantCulture, out value))
7769
{
78-
logger!.LogInvalidConfigurationValue(key, stringValue!);
70+
logger!.LogInvalidConfigurationValue(key, stringValue);
7971
return false;
8072
}
8173

@@ -98,7 +90,7 @@ public static bool TryGetBoolValue(
9890

9991
if (!bool.TryParse(stringValue, out value))
10092
{
101-
logger!.LogInvalidConfigurationValue(key, stringValue!);
93+
logger!.LogInvalidConfigurationValue(key, stringValue);
10294
return false;
10395
}
10496

@@ -110,9 +102,7 @@ public static bool TryGetValue<T>(
110102
IConfigurationExtensionsLogger logger,
111103
string key,
112104
TryParseFunc<T> tryParseFunc,
113-
#if !NETFRAMEWORK && !NETSTANDARD2_0
114105
[NotNullWhen(true)]
115-
#endif
116106
out T? value)
117107
{
118108
Debug.Assert(logger != null, "logger was null");
@@ -123,9 +113,9 @@ public static bool TryGetValue<T>(
123113
return false;
124114
}
125115

126-
if (!tryParseFunc(stringValue!, out value))
116+
if (!tryParseFunc(stringValue, out value))
127117
{
128-
logger!.LogInvalidConfigurationValue(key, stringValue!);
118+
logger!.LogInvalidConfigurationValue(key, stringValue);
129119
return false;
130120
}
131121

test/OpenTelemetry.Api.Tests/Logs/LoggerProviderTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
#if NETSTANDARD2_1_OR_GREATER || NET
54
using System.Diagnostics.CodeAnalysis;
6-
#endif
75
using Xunit;
86

97
namespace OpenTelemetry.Logs.Tests;
@@ -66,9 +64,7 @@ protected override bool TryCreateLogger(
6664
internal override bool TryCreateLogger(
6765
#endif
6866
string? name,
69-
#if NETSTANDARD2_1_OR_GREATER || NET
7067
[NotNullWhen(true)]
71-
#endif
7268
out Logger? logger)
7369
{
7470
logger = new TestLogger(name);

test/OpenTelemetry.Api.Tests/OpenTelemetry.Api.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\SkipUnlessEnvVarFoundFactAttribute.cs" Link="Includes\SkipUnlessEnvVarFoundFactAttribute.cs" />
1818
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestEventListener.cs" Link="Includes\TestEventListener.cs" />
1919
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\Utils.cs" Link="Includes\Utils.cs" />
20+
<Compile Include="$(RepoRoot)\src\Shared\Shims\NullableAttributes.cs" Link="Includes\Shims\NullableAttributes.cs" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

0 commit comments

Comments
 (0)