Skip to content

Commit 040012b

Browse files
authored
[shared] Split options and configuration extensions into separate files (#5466)
1 parent 0969437 commit 040012b

23 files changed

+150
-157
lines changed

OpenTelemetry.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EnvironmentVariables", "Env
297297
EndProject
298298
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Options", "Options", "{494902DD-C63F-48E0-BED3-B58EFB4051C8}"
299299
ProjectSection(SolutionItems) = preProject
300-
src\Shared\Options\ConfigurationExtensions.cs = src\Shared\Options\ConfigurationExtensions.cs
301300
src\Shared\Options\DelegatingOptionsFactory.cs = src\Shared\Options\DelegatingOptionsFactory.cs
301+
src\Shared\Options\DelegatingOptionsFactoryServiceCollectionExtensions.cs = src\Shared\Options\DelegatingOptionsFactoryServiceCollectionExtensions.cs
302302
EndProjectSection
303303
EndProject
304304
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shims", "Shims", "{A0CB9A10-F22D-4E66-A449-74B3D0361A9C}"
@@ -342,6 +342,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "extending-the-sdk", "docs\r
342342
EndProject
343343
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dedicated-pipeline", "docs\logs\dedicated-pipeline\dedicated-pipeline.csproj", "{19545B37-8518-4BDD-AD49-00C031FB3C2A}"
344344
EndProject
345+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configuration", "Configuration", "{87A20A76-D524-4AAC-AF92-8725BFED0415}"
346+
ProjectSection(SolutionItems) = preProject
347+
src\Shared\Configuration\OpenTelemetryConfigurationExtensions.cs = src\Shared\Configuration\OpenTelemetryConfigurationExtensions.cs
348+
EndProjectSection
349+
EndProject
345350
Global
346351
GlobalSection(SolutionConfigurationPlatforms) = preSolution
347352
Debug|Any CPU = Debug|Any CPU
@@ -687,6 +692,7 @@ Global
687692
{A115CE4C-71A8-4B95-96A5-C1DF46FD94C2} = {7C87CAF9-79D7-4C26-9FFB-F3F1FB6911F1}
688693
{7BE494FC-4B0D-4340-A62A-9C9F3E7389FE} = {A115CE4C-71A8-4B95-96A5-C1DF46FD94C2}
689694
{19545B37-8518-4BDD-AD49-00C031FB3C2A} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
695+
{87A20A76-D524-4AAC-AF92-8725BFED0415} = {A49299FB-C5CD-4E0E-B7E1-B7867BBD67CC}
690696
EndGlobalSection
691697
GlobalSection(ExtensibilityGlobals) = postSolution
692698
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}

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

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#nullable enable
55

66
using Microsoft.Extensions.Configuration;
7-
using OpenTelemetry.Internal;
87

98
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
109

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

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.DependencyInjection;
99
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
10-
using OpenTelemetry.Internal;
1110
using OpenTelemetry.Metrics;
1211

1312
namespace OpenTelemetry.Exporter;

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

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5-
using OpenTelemetry.Internal;
65

76
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
87

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#nullable enable
55

66
using System.Diagnostics;
7+
using Microsoft.Extensions.Configuration;
78
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
89
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
9-
using OpenTelemetry.Internal;
1010
using OpenTelemetry.Logs;
1111
using OtlpCollector = OpenTelemetry.Proto.Collector.Logs.V1;
1212
using OtlpResource = OpenTelemetry.Proto.Resource.V1;
@@ -57,10 +57,7 @@ internal OtlpLogExporter(
5757
OpenTelemetryProtocolExporterEventSource.Log.UnsupportedAttributeType(tagValueType, tagKey);
5858
};
5959

60-
ConfigurationExtensions.LogInvalidEnvironmentVariable = (string key, string value) =>
61-
{
62-
OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable(key, value);
63-
};
60+
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
6461

6562
this.transmissionHandler = transmissionHandler ?? exporterOptions.GetLogsExportTransmissionHandler(experimentalOptions!);
6663

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporter.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
using Microsoft.Extensions.Configuration;
45
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
56
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
6-
using OpenTelemetry.Internal;
77
using OpenTelemetry.Metrics;
88
using OtlpCollector = OpenTelemetry.Proto.Collector.Metrics.V1;
99
using OtlpResource = OpenTelemetry.Proto.Resource.V1;
@@ -47,10 +47,7 @@ internal OtlpMetricExporter(
4747
OpenTelemetryProtocolExporterEventSource.Log.UnsupportedAttributeType(tagValueType, tagKey);
4848
};
4949

50-
ConfigurationExtensions.LogInvalidEnvironmentVariable = (string key, string value) =>
51-
{
52-
OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable(key, value);
53-
};
50+
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
5451

5552
this.transmissionHandler = transmissionHandler ?? options.GetMetricsExportTransmissionHandler(experimentalOptions);
5653
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5+
using Microsoft.Extensions.Configuration;
56
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
67
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
7-
using OpenTelemetry.Internal;
88
using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1;
99
using OtlpResource = OpenTelemetry.Proto.Resource.V1;
1010

@@ -50,7 +50,7 @@ internal OtlpTraceExporter(
5050

5151
OtlpKeyValueTransformer.LogUnsupportedAttributeType = OpenTelemetryProtocolExporterEventSource.Log.UnsupportedAttributeType;
5252

53-
ConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
53+
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
5454

5555
this.transmissionHandler = transmissionHandler ?? exporterOptions.GetTraceExportTransmissionHandler(experimentalOptions);
5656
}

src/OpenTelemetry.Exporter.Zipkin/OpenTelemetry.Exporter.Zipkin.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13+
<Compile Include="$(RepoRoot)\src\Shared\Configuration\*.cs" Link="Includes\Configuration\%(Filename).cs" />
1314
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
1415
<Compile Include="$(RepoRoot)\src\Shared\PooledList.cs" Link="Includes\PooledList.cs" />
1516
<Compile Include="$(RepoRoot)\src\Shared\ResourceSemanticConventions.cs" Link="Includes\ResourceSemanticConventions.cs" />

src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Net.Sockets;
1111
using System.Runtime.CompilerServices;
1212
using System.Text.Json;
13+
using Microsoft.Extensions.Configuration;
1314
using OpenTelemetry.Exporter.Zipkin.Implementation;
1415
using OpenTelemetry.Internal;
1516
using OpenTelemetry.Resources;
@@ -43,10 +44,7 @@ public ZipkinExporter(ZipkinExporterOptions options, HttpClient client = null)
4344
ZipkinExporterEventSource.Log.UnsupportedAttributeType(tagValueType, tagKey);
4445
};
4546

46-
ConfigurationExtensions.LogInvalidEnvironmentVariable = (string key, string value) =>
47-
{
48-
ZipkinExporterEventSource.Log.InvalidEnvironmentVariable(key, value);
49-
};
47+
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = ZipkinExporterEventSource.Log.InvalidEnvironmentVariable;
5048
}
5149

5250
internal ZipkinEndpoint LocalEndpoint { get; private set; }

src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Net.Http;
77
#endif
88
using Microsoft.Extensions.Configuration;
9-
using OpenTelemetry.Internal;
109
using OpenTelemetry.Trace;
1110

1211
namespace OpenTelemetry.Exporter;

src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Diagnostics;
55
using Microsoft.AspNetCore.Http;
66
using Microsoft.Extensions.Configuration;
7-
using OpenTelemetry.Internal;
87

98
namespace OpenTelemetry.Instrumentation.AspNetCore;
109

src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15+
<Compile Include="$(RepoRoot)\src\Shared\Configuration\*.cs" Link="Includes\Configuration\%(Filename).cs" />
1516
<Compile Include="$(RepoRoot)\src\Shared\EnvironmentVariables\*.cs" Link="Includes\EnvironmentVariables\%(Filename).cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
1617
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.GrpcNetClient\GrpcTagHelper.cs" Link="Includes\GrpcTagHelper.cs" />
1718
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.GrpcNetClient\StatusCanonicalCode.cs" Link="Includes\StatusCanonicalCode.cs" />

src/OpenTelemetry/Internal/Builder/ProviderBuilderServiceCollectionExtensions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.Extensions.DependencyInjection.Extensions;
77
using Microsoft.Extensions.Options;
88
using OpenTelemetry;
9-
using OpenTelemetry.Internal;
109
using OpenTelemetry.Logs;
1110
using OpenTelemetry.Metrics;
1211
using OpenTelemetry.Trace;

src/OpenTelemetry/Logs/BatchExportLogRecordProcessorOptions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5-
using OpenTelemetry.Internal;
65

76
namespace OpenTelemetry.Logs;
87

src/OpenTelemetry/Metrics/PeriodicExportingMetricReaderOptions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5-
using OpenTelemetry.Internal;
65

76
namespace OpenTelemetry.Metrics;
87

src/OpenTelemetry/OpenTelemetry.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19+
<Compile Include="$(RepoRoot)\src\Shared\Configuration\*.cs" Link="Includes\Configuration\%(Filename).cs" />
1920
<Compile Include="$(RepoRoot)\src\Shared\EnvironmentVariables\*.cs" Link="Includes\EnvironmentVariables\%(Filename).cs" />
2021
<Compile Include="$(RepoRoot)\src\Shared\MathHelper.cs" Link="Includes\MathHelper.cs" />
2122
<Compile Include="$(RepoRoot)\src\Shared\Options\*.cs" Link="Includes\Options\%(Filename).cs" />

src/OpenTelemetry/Resources/OtelEnvResourceDetector.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5-
using OpenTelemetry.Internal;
65

76
namespace OpenTelemetry.Resources;
87

src/OpenTelemetry/Resources/OtelServiceNameEnvVarDetector.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5-
using OpenTelemetry.Internal;
65

76
namespace OpenTelemetry.Resources;
87

src/OpenTelemetry/Sdk.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics.CodeAnalysis;
77
#endif
88
using System.Reflection;
9+
using Microsoft.Extensions.Configuration;
910
using OpenTelemetry.Context.Propagation;
1011
using OpenTelemetry.Internal;
1112
using OpenTelemetry.Logs;
@@ -34,10 +35,7 @@ static Sdk()
3435
var assemblyInformationalVersion = typeof(Sdk).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
3536
InformationalVersion = ParseAssemblyInformationalVersion(assemblyInformationalVersion);
3637

37-
ConfigurationExtensions.LogInvalidEnvironmentVariable = (string key, string value) =>
38-
{
39-
OpenTelemetrySdkEventSource.Log.InvalidEnvironmentVariable(key, value);
40-
};
38+
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetrySdkEventSource.Log.InvalidEnvironmentVariable;
4139
}
4240

4341
/// <summary>

src/OpenTelemetry/Trace/BatchExportActivityProcessorOptions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Diagnostics;
55
using Microsoft.Extensions.Configuration;
6-
using OpenTelemetry.Internal;
76

87
namespace OpenTelemetry.Trace;
98

src/Shared/Options/ConfigurationExtensions.cs src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs

+2-49
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33

44
#nullable enable
55

6-
using System.Diagnostics;
76
#if !NETFRAMEWORK && !NETSTANDARD2_0
87
using System.Diagnostics.CodeAnalysis;
98
#endif
109
using System.Globalization;
11-
using Microsoft.Extensions.Configuration;
12-
using Microsoft.Extensions.DependencyInjection;
13-
using Microsoft.Extensions.DependencyInjection.Extensions;
14-
using Microsoft.Extensions.Options;
1510

16-
namespace OpenTelemetry.Internal;
11+
namespace Microsoft.Extensions.Configuration;
1712

18-
internal static class ConfigurationExtensions
13+
internal static class OpenTelemetryConfigurationExtensions
1914
{
2015
public static Action<string, string>? LogInvalidEnvironmentVariable = null;
2116

@@ -125,46 +120,4 @@ public static bool TryGetValue<T>(
125120

126121
return true;
127122
}
128-
129-
public static IServiceCollection RegisterOptionsFactory<T>(
130-
this IServiceCollection services,
131-
Func<IConfiguration, T> optionsFactoryFunc)
132-
where T : class
133-
{
134-
Debug.Assert(services != null, "services was null");
135-
Debug.Assert(optionsFactoryFunc != null, "optionsFactoryFunc was null");
136-
137-
services!.TryAddSingleton<IOptionsFactory<T>>(sp =>
138-
{
139-
return new DelegatingOptionsFactory<T>(
140-
(c, n) => optionsFactoryFunc!(c),
141-
sp.GetRequiredService<IConfiguration>(),
142-
sp.GetServices<IConfigureOptions<T>>(),
143-
sp.GetServices<IPostConfigureOptions<T>>(),
144-
sp.GetServices<IValidateOptions<T>>());
145-
});
146-
147-
return services!;
148-
}
149-
150-
public static IServiceCollection RegisterOptionsFactory<T>(
151-
this IServiceCollection services,
152-
Func<IServiceProvider, IConfiguration, string, T> optionsFactoryFunc)
153-
where T : class
154-
{
155-
Debug.Assert(services != null, "services was null");
156-
Debug.Assert(optionsFactoryFunc != null, "optionsFactoryFunc was null");
157-
158-
services!.TryAddSingleton<IOptionsFactory<T>>(sp =>
159-
{
160-
return new DelegatingOptionsFactory<T>(
161-
(c, n) => optionsFactoryFunc!(sp, c, n),
162-
sp.GetRequiredService<IConfiguration>(),
163-
sp.GetServices<IConfigureOptions<T>>(),
164-
sp.GetServices<IPostConfigureOptions<T>>(),
165-
sp.GetServices<IValidateOptions<T>>());
166-
});
167-
168-
return services!;
169-
}
170123
}

0 commit comments

Comments
 (0)