Skip to content

Commit 34daa1f

Browse files
CodeBlanchmartincostelloeerhardtreyang
authored
[main-1.8.0] Backport fixes for 1.8.1 core release (#5543)
Co-authored-by: Martin Costello <[email protected]> Co-authored-by: Eric Erhardt <[email protected]> Co-authored-by: Reiley Yang <[email protected]>
1 parent fb74013 commit 34daa1f

File tree

14 files changed

+217
-16
lines changed

14 files changed

+217
-16
lines changed

.github/workflows/verifyaotcompat.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
1313
matrix:
14-
os: [ ubuntu-latest ]
14+
os: [ ubuntu-latest, windows-latest ]
1515
version: [ net8.0 ]
1616

1717
runs-on: ${{ matrix.os }}
@@ -24,4 +24,3 @@ jobs:
2424
- name: publish AOT testApp, assert static analysis warning count, and run the app
2525
shell: pwsh
2626
run: .\build\test-aot-compatibility.ps1 ${{ matrix.version }}
27-

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
-->
2929

3030
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
31+
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
3132
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
3233
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Abstractions" Version="8.0.0" />
3334
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />

OpenTelemetry.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Options", "Options", "{4949
299299
ProjectSection(SolutionItems) = preProject
300300
src\Shared\Options\DelegatingOptionsFactory.cs = src\Shared\Options\DelegatingOptionsFactory.cs
301301
src\Shared\Options\DelegatingOptionsFactoryServiceCollectionExtensions.cs = src\Shared\Options\DelegatingOptionsFactoryServiceCollectionExtensions.cs
302+
src\Shared\Options\SingletonOptionsManager.cs = src\Shared\Options\SingletonOptionsManager.cs
302303
EndProjectSection
303304
EndProject
304305
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shims", "Shims", "{A0CB9A10-F22D-4E66-A449-74B3D0361A9C}"

build/test-aot-compatibility.ps1

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
param([string]$targetNetFramework)
22

33
$rootDirectory = Split-Path $PSScriptRoot -Parent
4-
$publishOutput = dotnet publish $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
4+
$publishOutput = dotnet publish $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj --framework $targetNetFramework -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
55

66
$actualWarningCount = 0
77

88
foreach ($line in $($publishOutput -split "`r`n"))
99
{
10-
if ($line -like "*analysis warning IL*")
10+
if (($line -like "*analysis warning IL*") -or ($line -like "*analysis error IL*"))
1111
{
1212
Write-Host $line
13-
1413
$actualWarningCount += 1
1514
}
1615
}
1716

18-
pushd $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/bin/Release/$targetNetFramework/linux-x64
17+
Write-Host "Actual warning count is:", $actualWarningCount
18+
$expectedWarningCount = 0
19+
20+
if ($LastExitCode -ne 0)
21+
{
22+
Write-Host "There was an error while publishing AotCompatibility Test App. LastExitCode is:", $LastExitCode
23+
Write-Host $publishOutput
24+
}
25+
26+
$runtime = $IsWindows ? "win-x64" : ($IsMacOS ? "macos-x64" : "linux-x64")
27+
$app = $IsWindows ? "./OpenTelemetry.AotCompatibility.TestApp.exe" : "./OpenTelemetry.AotCompatibility.TestApp"
28+
29+
Push-Location $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/bin/Release/$targetNetFramework/$runtime
1930

2031
Write-Host "Executing test App..."
21-
./OpenTelemetry.AotCompatibility.TestApp
32+
$app
2233
Write-Host "Finished executing test App"
2334

2435
if ($LastExitCode -ne 0)
2536
{
2637
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
2738
}
2839

29-
popd
30-
31-
Write-Host "Actual warning count is:", $actualWarningCount
32-
$expectedWarningCount = 0
40+
Pop-Location
3341

3442
$testPassed = 0
3543
if ($actualWarningCount -ne $expectedWarningCount)

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* Fix native AoT warnings in `OpenTelemetry.Exporter.OpenTelemetryProtocol`.
6+
([#5520](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5520))
7+
58
## 1.8.0
69

710
Released 2024-Apr-02

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<!-- this is temporary. will remove in future PR. -->
99
<Nullable>disable</Nullable>
1010
<DefineConstants>BUILDING_INTERNAL_PERSISTENT_STORAGE;$(DefineConstants)</DefineConstants>
11+
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
12+
<!-- SYSLIB1100;SYSLIB1101 - Configuration.Binder: can't create instance and unsupported type -->
13+
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
1114
</PropertyGroup>
1215

1316
<ItemGroup>
@@ -19,6 +22,7 @@
1922
<PackageReference Include="Grpc" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'" />
2023
<PackageReference Include="Google.Protobuf" />
2124
<PackageReference Include="Grpc.Tools" PrivateAssets="All" />
25+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
2226
</ItemGroup>
2327

2428
<ItemGroup>

src/OpenTelemetry/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
* Fixed an issue in Logging where unwanted objects (processors, exporters, etc.)
6+
could be created inside delegates automatically executed by the Options API
7+
during configuration reload.
8+
([#5514](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5514))
9+
510
## 1.8.0
611

712
Released 2024-Apr-02

src/OpenTelemetry/Logs/ILogger/OpenTelemetryLoggerOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public OpenTelemetryLoggerOptions SetResourceBuilder(ResourceBuilder resourceBui
117117
Guard.ThrowIfNull(resourceBuilder);
118118

119119
this.ResourceBuilder = resourceBuilder;
120+
120121
return this;
121122
}
122123

src/OpenTelemetry/Logs/ILogger/OpenTelemetryLoggingExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ private static ILoggingBuilder AddOpenTelemetryInternal(
173173
// Note: This will bind logger options element (e.g., "Logging:OpenTelemetry") to OpenTelemetryLoggerOptions
174174
RegisterLoggerProviderOptions(services);
175175

176+
// Note: We disable built-in IOptionsMonitor and IOptionsSnapshot
177+
// features for OpenTelemetryLoggerOptions as a workaround to prevent
178+
// unwanted objects (processors, exporters, etc.) being created by
179+
// configuration delegates being re-run during reload of IConfiguration
180+
// or from options created while under scopes.
181+
services.DisableOptionsReloading<OpenTelemetryLoggerOptions>();
182+
176183
/* Note: This ensures IConfiguration is available when using
177184
* IServiceCollections NOT attached to a host. For example when
178185
* performing:
@@ -192,7 +199,7 @@ private static ILoggingBuilder AddOpenTelemetryInternal(
192199
var loggingBuilder = new LoggerProviderBuilderBase(services).ConfigureBuilder(
193200
(sp, logging) =>
194201
{
195-
var options = sp.GetRequiredService<IOptionsMonitor<OpenTelemetryLoggerOptions>>().CurrentValue;
202+
var options = sp.GetRequiredService<IOptions<OpenTelemetryLoggerOptions>>().Value;
196203

197204
if (options.ResourceBuilder != null)
198205
{
@@ -249,7 +256,7 @@ private static ILoggingBuilder AddOpenTelemetryInternal(
249256

250257
return new OpenTelemetryLoggerProvider(
251258
provider,
252-
sp.GetRequiredService<IOptionsMonitor<OpenTelemetryLoggerOptions>>().CurrentValue,
259+
sp.GetRequiredService<IOptions<OpenTelemetryLoggerOptions>>().Value,
253260
disposeProvider: false);
254261
}));
255262

src/Shared/Options/DelegatingOptionsFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ example of how that works.
1616
#nullable enable
1717

1818
using System.Diagnostics;
19+
#if NET6_0_OR_GREATER
20+
using System.Diagnostics.CodeAnalysis;
21+
#endif
1922
using Microsoft.Extensions.Configuration;
2023

2124
namespace Microsoft.Extensions.Options;
@@ -24,7 +27,11 @@ namespace Microsoft.Extensions.Options;
2427
/// Implementation of <see cref="IOptionsFactory{TOptions}"/>.
2528
/// </summary>
2629
/// <typeparam name="TOptions">The type of options being requested.</typeparam>
30+
#if NET6_0_OR_GREATER
31+
internal sealed class DelegatingOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> :
32+
#else
2733
internal sealed class DelegatingOptionsFactory<TOptions> :
34+
#endif
2835
IOptionsFactory<TOptions>
2936
where TOptions : class
3037
{
@@ -74,6 +81,7 @@ public DelegatingOptionsFactory(
7481
public TOptions Create(string name)
7582
{
7683
TOptions options = this.optionsFactoryFunc(this.configuration, name);
84+
7785
foreach (IConfigureOptions<TOptions> setup in _setups)
7886
{
7987
if (setup is IConfigureNamedOptions<TOptions> namedSetup)

0 commit comments

Comments
 (0)