Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase use of NotNullWhen polyfill #6090

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ExperimentalOptions(IConfiguration configuration)
this.EmitLogEventAttributes = emitLogEventAttributes;
}

if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy) && retryPolicy != null)
if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy))
{
if (retryPolicy.Equals("in_memory", StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -38,7 +38,7 @@ public ExperimentalOptions(IConfiguration configuration)
else if (retryPolicy.Equals("disk", StringComparison.OrdinalIgnoreCase))
{
this.EnableDiskRetry = true;
if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path) && path != null)
if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path))
{
this.DiskRetryDirectoryPath = path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal ZipkinExporterOptions(

if (configuration!.TryGetUriValue(ZipkinExporterEventSource.Log, ZipkinEndpointEnvVar, out var endpoint))
{
this.Endpoint = endpoint!;
this.Endpoint = endpoint;
}

this.BatchExportProcessorOptions = defaultBatchOptions!;
Expand Down
1 change: 1 addition & 0 deletions src/OpenTelemetry/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Api.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Tests.Stress.Metrics" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("Benchmarks" + AssemblyInfo.PublicKey)]

Expand Down
4 changes: 0 additions & 4 deletions src/OpenTelemetry/Logs/LoggerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
#if NETSTANDARD2_1_OR_GREATER || NET
using System.Diagnostics.CodeAnalysis;
#endif
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Internal;
Expand Down Expand Up @@ -201,9 +199,7 @@ public bool ContainsBatchProcessor(BaseProcessor<LogRecord> processor)
#endif
override bool TryCreateLogger(
string? name,
#if NETSTANDARD2_1_OR_GREATER || NET
[NotNullWhen(true)]
#endif
out Logger? logger)
{
logger = new LoggerSdk(this, name);
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Resources/OtelEnvResourceDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Resource Detect()

if (this.configuration.TryGetStringValue(EnvVarKey, out string? envResourceAttributeValue))
{
var attributes = ParseResourceAttributes(envResourceAttributeValue!);
var attributes = ParseResourceAttributes(envResourceAttributeValue);
resource = new Resource(attributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Resource Detect()
{
resource = new Resource(new Dictionary<string, object>
{
[ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue!,
[ResourceSemanticConventions.AttributeServiceName] = envResourceAttributeValue,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
#if !NETFRAMEWORK && !NETSTANDARD2_0
using System.Diagnostics.CodeAnalysis;
#endif
using System.Globalization;

namespace Microsoft.Extensions.Configuration;
Expand All @@ -13,17 +11,13 @@ internal static class OpenTelemetryConfigurationExtensions
{
public delegate bool TryParseFunc<T>(
string value,
#if !NETFRAMEWORK && !NETSTANDARD2_0
[NotNullWhen(true)]
#endif
out T? parsedValue);

public static bool TryGetStringValue(
this IConfiguration configuration,
string key,
#if !NETFRAMEWORK && !NETSTANDARD2_0
[NotNullWhen(true)]
#endif
out string? value)
{
Debug.Assert(configuration != null, "configuration was null");
Expand All @@ -37,9 +31,7 @@ public static bool TryGetUriValue(
this IConfiguration configuration,
IConfigurationExtensionsLogger logger,
string key,
#if !NETFRAMEWORK && !NETSTANDARD2_0
[NotNullWhen(true)]
#endif
out Uri? value)
{
Debug.Assert(logger != null, "logger was null");
Expand All @@ -52,7 +44,7 @@ public static bool TryGetUriValue(

if (!Uri.TryCreate(stringValue, UriKind.Absolute, out value))
{
logger!.LogInvalidConfigurationValue(key, stringValue!);
logger!.LogInvalidConfigurationValue(key, stringValue);
return false;
}

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

if (!int.TryParse(stringValue, NumberStyles.None, CultureInfo.InvariantCulture, out value))
{
logger!.LogInvalidConfigurationValue(key, stringValue!);
logger!.LogInvalidConfigurationValue(key, stringValue);
return false;
}

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

if (!bool.TryParse(stringValue, out value))
{
logger!.LogInvalidConfigurationValue(key, stringValue!);
logger!.LogInvalidConfigurationValue(key, stringValue);
return false;
}

Expand All @@ -110,9 +102,7 @@ public static bool TryGetValue<T>(
IConfigurationExtensionsLogger logger,
string key,
TryParseFunc<T> tryParseFunc,
#if !NETFRAMEWORK && !NETSTANDARD2_0
[NotNullWhen(true)]
#endif
out T? value)
{
Debug.Assert(logger != null, "logger was null");
Expand All @@ -123,9 +113,9 @@ public static bool TryGetValue<T>(
return false;
}

if (!tryParseFunc(stringValue!, out value))
if (!tryParseFunc(stringValue, out value))
{
logger!.LogInvalidConfigurationValue(key, stringValue!);
logger!.LogInvalidConfigurationValue(key, stringValue);
return false;
}

Expand Down
4 changes: 0 additions & 4 deletions test/OpenTelemetry.Api.Tests/Logs/LoggerProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if NETSTANDARD2_1_OR_GREATER || NET
using System.Diagnostics.CodeAnalysis;
#endif
using Xunit;

namespace OpenTelemetry.Logs.Tests;
Expand Down Expand Up @@ -66,9 +64,7 @@ protected override bool TryCreateLogger(
internal override bool TryCreateLogger(
#endif
string? name,
#if NETSTANDARD2_1_OR_GREATER || NET
[NotNullWhen(true)]
#endif
out Logger? logger)
{
logger = new TestLogger(name);
Expand Down
Loading