Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 11 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="[3.1.0,)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[3.1.0,)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="[2.1.0,)" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="[3.1.0,)" />

<!--
Typically, the latest stable version of Microsoft.Extensions.Logging should be used here because:
1) Each major version bump will have some new API capabilities (e.g. .NET 6 introduced Compile-time logging
source generation, .NET 8 introduced automatic event id generation).
2) Each minor version bump is normally security hotfixes or critical bug fixes.
3) Since version 3.1.0, the .NET runtime team provides extra backward compatibility guarantee to
Microsoft.Extensions.Logging even during major version bumps, so compatibility is not a concern here.
-->
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0-rc.1.23419.4" />

<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="[3.1.0,)" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="[3.1.0,)" />
<PackageVersion Include="OpenTelemetry" Version="$(OTelLatestStableVer)" />
Expand Down
3 changes: 0 additions & 3 deletions docs/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Packages.props, $(MSBuildThisFileDirectory)..))" />
<ItemGroup>
<PackageVersion Update="Microsoft.Extensions.Logging" Version="[6.0.0,)" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion examples/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Packages.props, $(MSBuildThisFileDirectory)..))" />
<ItemGroup>
<PackageVersion Update="Microsoft.Extensions.Logging" Version="[6.0.0,)" />
<PackageVersion Update="System.Text.Json" Version="6.0.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<PackageReference Include="Grpc.Tools" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\PeriodicExportingMetricReaderHelper.cs" Link="Includes\PeriodicExportingMetricReaderHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\PeerServiceResolver.cs" Link="Includes\PeerServiceResolver.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(TargetFrameworksForLibraries)</TargetFrameworks>
<Description>Http instrumentation for OpenTelemetry .NET</Description>
Expand Down Expand Up @@ -27,4 +26,7 @@
<PackageReference Include="OpenTelemetry" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static IServiceCollection AddOpenTelemetrySharedProviderBuilderServices(t
// which sets default Propagators and default Activity Id format
_ = Sdk.SuppressInstrumentation;

services.AddOptions();
services!.AddOptions();

// Note: When using a host builder IConfiguration is automatically
// registered and this registration will no-op. This only runs for
Expand Down
3 changes: 2 additions & 1 deletion src/OpenTelemetry/Logs/ILogger/OpenTelemetryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public bool IsEnabled(LogLevel logLevel)
return logLevel != LogLevel.None;
}

public IDisposable BeginScope<TState>(TState state) => this.ScopeProvider?.Push(state) ?? NullScope.Instance;
public IDisposable BeginScope<TState>(TState state)
where TState : notnull => this.ScopeProvider?.Push(state) ?? NullScope.Instance;

internal static void SetLogRecordSeverityFields(ref LogRecordData logRecordData, LogLevel logLevel)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/HttpSemanticConventionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static bool TryGetConfiguredValues(IConfiguration configuration, [NotNul
return false;
}

var stringValues = stringValue.Split(separator: new[] { ',', ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
var stringValues = stringValue!.Split(separator: new[] { ',', ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
values = new HashSet<string>(stringValues, StringComparer.OrdinalIgnoreCase);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/Options/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static IServiceCollection RegisterOptionsFactory<T>(
Debug.Assert(services != null, "services was null");
Debug.Assert(optionsFactoryFunc != null, "optionsFactoryFunc was null");

services.TryAddSingleton<IOptionsFactory<T>>(sp =>
services!.TryAddSingleton<IOptionsFactory<T>>(sp =>
{
return new DelegatingOptionsFactory<T>(
(c, n) => optionsFactoryFunc!(c),
Expand All @@ -168,7 +168,7 @@ public static IServiceCollection RegisterOptionsFactory<T>(
Debug.Assert(services != null, "services was null");
Debug.Assert(optionsFactoryFunc != null, "optionsFactoryFunc was null");

services.TryAddSingleton<IOptionsFactory<T>>(sp =>
services!.TryAddSingleton<IOptionsFactory<T>>(sp =>
{
return new DelegatingOptionsFactory<T>(
(c, n) => optionsFactoryFunc!(sp, c, n),
Expand Down
1 change: 0 additions & 1 deletion test/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Packages.props, $(MSBuildThisFileDirectory)..))" />
<ItemGroup>
<PackageVersion Update="Microsoft.Extensions.Logging" Version="[6.0.0,)" />
<PackageVersion Update="System.Text.Json" Version="6.0.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Prometheus.HttpListener\OpenTelemetry.Exporter.Prometheus.HttpListener.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.InMemory\OpenTelemetry.Exporter.InMemory.csproj" />
Expand Down
9 changes: 9 additions & 0 deletions test/OpenTelemetry.Tests.Stress/Skeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ public static void Stress(int concurrency = 0, int prometheusPort = 0)
description: "The rate of `Run()` invocations based on a small sliding window of few hundreds of milliseconds.");
var dCpuCyclesPerLoop = 0D;

#if NETFRAMEWORK
meter.CreateObservableGauge(
"OpenTelemetry.Tests.Stress.CpuCyclesPerLoop",
() => dCpuCyclesPerLoop,
description: "The average CPU cycles for each `Run()` invocation, based on a small sliding window of few hundreds of milliseconds.");
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
meter.CreateObservableGauge(
"OpenTelemetry.Tests.Stress.CpuCyclesPerLoop",
() => dCpuCyclesPerLoop,
description: "The average CPU cycles for each `Run()` invocation, based on a small sliding window of few hundreds of milliseconds.");
}
#endif

using var meterProvider = prometheusPort != 0 ? Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
Expand Down Expand Up @@ -170,10 +177,12 @@ public static void Stress(int concurrency = 0, int prometheusPort = 0)

private static ulong GetCpuCycles()
{
#if !NETFRAMEWORK
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return 0;
}
#endif

if (!QueryProcessCycleTime((IntPtr)(-1), out var cycles))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void CreatePeriodicExportingMetricReader_ExportTimeoutMilliseconds_FromEn
[Fact]
public void CreatePeriodicExportingMetricReader_FromIConfiguration()
{
var values = new Dictionary<string, string>()
var values = new Dictionary<string, string?>()
{
[PeriodicExportingMetricReaderOptions.OTelMetricExportIntervalEnvVarKey] = "18",
[PeriodicExportingMetricReaderOptions.OTelMetricExportTimeoutEnvVarKey] = "19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void BatchExportLogRecordProcessorOptions_EnvironmentVariableOverride()
[Fact]
public void ExportLogRecordProcessorOptions_UsingIConfiguration()
{
var values = new Dictionary<string, string>()
var values = new Dictionary<string, string?>()
{
[BatchExportLogRecordProcessorOptions.MaxQueueSizeEnvVarKey] = "1",
[BatchExportLogRecordProcessorOptions.MaxExportBatchSizeEnvVarKey] = "2",
Expand Down
2 changes: 1 addition & 1 deletion test/OpenTelemetry.Tests/Logs/LoggerProviderSdkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void ResourceDetectionUsingIConfigurationTest()
.ConfigureServices(services =>
{
services.AddSingleton<IConfiguration>(
new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string> { ["OTEL_SERVICE_NAME"] = "TestServiceName" }).Build());
new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?> { ["OTEL_SERVICE_NAME"] = "TestServiceName" }).Build());
})
.Build() as LoggerProviderSdk;

Expand Down