@@ -21,211 +21,82 @@ namespace Datadog.Trace.Configuration
21
21
/// <summary>
22
22
/// Represents one or more configuration sources.
23
23
/// </summary>
24
- public class CompositeConfigurationSource : IConfigurationSource , IEnumerable < IConfigurationSource > , ITelemeteredConfigurationSource
24
+ internal class CompositeConfigurationSource : IConfigurationSource , IEnumerable < IConfigurationSource >
25
25
{
26
- private readonly List < ITelemeteredConfigurationSource > _sources = new ( ) ;
27
-
28
- /// <summary>
29
- /// Initializes a new instance of the <see cref="CompositeConfigurationSource"/> class.
30
- /// </summary>
31
- [ PublicApi ]
32
- public CompositeConfigurationSource ( )
33
- {
34
- TelemetryFactory . Metrics . Record ( PublicApiUsage . CompositeConfigurationSource_Ctor ) ;
35
- }
36
-
37
- private protected CompositeConfigurationSource ( bool unusedParamNotToUsePublicApi )
38
- {
39
- // unused parameter is to give us a non-public API we can use
40
- }
26
+ private readonly List < IConfigurationSource > _sources = new ( ) ;
41
27
42
28
/// <summary>
43
29
/// Adds a new configuration source to this instance.
44
30
/// </summary>
45
31
/// <param name="source">The configuration source to add.</param>
46
- [ PublicApi ]
47
32
public void Add ( IConfigurationSource source )
48
33
{
49
- TelemetryFactory . Metrics . Record ( PublicApiUsage . CompositeConfigurationSource_Add ) ;
50
34
if ( source == null ) { ThrowHelper . ThrowArgumentNullException ( nameof ( source ) ) ; }
51
35
52
- AddInternal ( source ) ;
36
+ _sources . Add ( source ) ;
53
37
}
54
38
55
39
/// <summary>
56
- /// Inserts an element into the <see cref="CompositeConfigurationSource"/> at the specified index.
40
+ /// Inserts an element into the <see cref="Datadog.Trace.Configuration. CompositeConfigurationSource"/> at the specified index.
57
41
/// </summary>
58
42
/// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
59
43
/// <param name="item">The configuration source to insert.</param>
60
- [ PublicApi ]
61
44
public void Insert ( int index , IConfigurationSource item )
62
45
{
63
- TelemetryFactory . Metrics . Record ( PublicApiUsage . CompositeConfigurationSource_Insert ) ;
64
46
if ( item == null ) { ThrowHelper . ThrowArgumentNullException ( nameof ( item ) ) ; }
65
47
66
- InsertInternal ( index , item ) ;
67
- }
68
-
69
- /// <summary>
70
- /// Gets the <see cref="string"/> value of the first setting found with
71
- /// the specified key from the current list of configuration sources.
72
- /// Sources are queried in the order in which they were added.
73
- /// </summary>
74
- /// <param name="key">The key that identifies the setting.</param>
75
- /// <returns>The value of the setting, or <c>null</c> if not found.</returns>
76
- [ PublicApi ]
77
- public string ? GetString ( string key )
78
- {
79
- var value = _sources
80
- . Select ( source => source . GetString ( key , NullConfigurationTelemetry . Instance , validator : null , recordValue : true ) )
81
- . FirstOrDefault ( value => value . IsValid , ConfigurationResult < string > . NotFound ( ) ) ;
82
- return value . IsValid ? value . Result : null ;
83
- }
84
-
85
- /// <summary>
86
- /// Gets the <see cref="int"/> value of the first setting found with
87
- /// the specified key from the current list of configuration sources.
88
- /// Sources are queried in the order in which they were added.
89
- /// </summary>
90
- /// <param name="key">The key that identifies the setting.</param>
91
- /// <returns>The value of the setting, or <c>null</c> if not found.</returns>
92
- [ PublicApi ]
93
- public int ? GetInt32 ( string key )
94
- {
95
- var value = _sources
96
- . Select ( source => source . GetInt32 ( key , NullConfigurationTelemetry . Instance , validator : null ) )
97
- . FirstOrDefault ( value => value . IsValid , ConfigurationResult < int > . NotFound ( ) ) ;
98
- return value . IsValid ? value . Result : null ;
99
- }
100
-
101
- /// <summary>
102
- /// Gets the <see cref="double"/> value of the first setting found with
103
- /// the specified key from the current list of configuration sources.
104
- /// Sources are queried in the order in which they were added.
105
- /// </summary>
106
- /// <param name="key">The key that identifies the setting.</param>
107
- /// <returns>The value of the setting, or <c>null</c> if not found.</returns>
108
- [ PublicApi ]
109
- public double ? GetDouble ( string key )
110
- {
111
- var value = _sources
112
- . Select ( source => source . GetDouble ( key , NullConfigurationTelemetry . Instance , validator : null ) )
113
- . FirstOrDefault ( value => value . IsValid , ConfigurationResult < double > . NotFound ( ) ) ;
114
- return value . IsValid ? value . Result : null ;
115
- }
116
-
117
- /// <summary>
118
- /// Gets the <see cref="bool"/> value of the first setting found with
119
- /// the specified key from the current list of configuration sources.
120
- /// Sources are queried in the order in which they were added.
121
- /// </summary>
122
- /// <param name="key">The key that identifies the setting.</param>
123
- /// <returns>The value of the setting, or <c>null</c> if not found.</returns>
124
- [ PublicApi ]
125
- public bool ? GetBool ( string key )
126
- {
127
- var value = _sources
128
- . Select ( source => source . GetBool ( key , NullConfigurationTelemetry . Instance , validator : null ) )
129
- . FirstOrDefault ( value => value . IsValid , ConfigurationResult < bool > . NotFound ( ) ) ;
130
- return value . IsValid ? value . Result : null ;
131
- }
132
-
133
- internal void AddInternal ( IConfigurationSource source )
134
- {
135
- var telemeteredSource = source as ITelemeteredConfigurationSource ?? new CustomTelemeteredConfigurationSource ( source ) ;
136
- _sources . Add ( telemeteredSource ) ;
137
- }
138
-
139
- internal void InsertInternal ( int index , IConfigurationSource source )
140
- {
141
- var telemeteredSource = source as ITelemeteredConfigurationSource ?? new CustomTelemeteredConfigurationSource ( source ) ;
142
- _sources . Insert ( index , telemeteredSource ) ;
143
- }
144
-
145
- /// <inheritdoc />
146
- [ PublicApi ]
147
- IEnumerator < IConfigurationSource > IEnumerable < IConfigurationSource > . GetEnumerator ( )
148
- {
149
- return _sources
150
- . Select (
151
- x => x as IConfigurationSource
152
- ?? ( ( CustomTelemeteredConfigurationSource ) x ) . Source )
153
- . GetEnumerator ( ) ;
154
- }
155
-
156
- /// <inheritdoc />
157
- [ PublicApi ]
158
- IEnumerator IEnumerable . GetEnumerator ( )
159
- {
160
- return _sources
161
- . Select (
162
- x => x as IConfigurationSource
163
- ?? ( ( CustomTelemeteredConfigurationSource ) x ) . Source )
164
- . GetEnumerator ( ) ;
48
+ _sources . Insert ( index , item ) ;
165
49
}
166
50
167
51
/// <inheritdoc />
168
- [ PublicApi ]
169
- public IDictionary < string , string > ? GetDictionary ( string key )
170
- {
171
- var value = _sources
172
- . Select ( source => source . GetDictionary ( key , NullConfigurationTelemetry . Instance , validator : null ) )
173
- . FirstOrDefault ( value => value . IsValid , ConfigurationResult < IDictionary < string , string > > . NotFound ( ) ) ;
174
- return value . IsValid ? value . Result : null ;
175
- }
52
+ IEnumerator < IConfigurationSource > IEnumerable < IConfigurationSource > . GetEnumerator ( ) => _sources . GetEnumerator ( ) ;
176
53
177
54
/// <inheritdoc />
178
55
[ PublicApi ]
179
- public IDictionary < string , string > ? GetDictionary ( string key , bool allowOptionalMappings )
180
- {
181
- var value = _sources
182
- . Select ( source => source . GetDictionary ( key , NullConfigurationTelemetry . Instance , validator : null , allowOptionalMappings , separator : ':' ) )
183
- . FirstOrDefault ( value => value . IsValid , ConfigurationResult < IDictionary < string , string > > . NotFound ( ) ) ;
184
- return value . IsValid ? value . Result : null ;
185
- }
56
+ IEnumerator IEnumerable . GetEnumerator ( ) => _sources . GetEnumerator ( ) ;
186
57
187
58
/// <inheritdoc />
188
- bool ITelemeteredConfigurationSource . IsPresent ( string key )
59
+ public bool IsPresent ( string key )
189
60
=> _sources . Select ( source => source . IsPresent ( key ) ) . FirstOrDefault ( value => value ) ;
190
61
191
62
/// <inheritdoc />
192
- ConfigurationResult < string > ITelemeteredConfigurationSource . GetString ( string key , IConfigurationTelemetry telemetry , Func < string , bool > ? validator , bool recordValue )
63
+ public ConfigurationResult < string > GetString ( string key , IConfigurationTelemetry telemetry , Func < string , bool > ? validator , bool recordValue )
193
64
=> _sources
194
65
. Select ( source => source . GetString ( key , telemetry , validator , recordValue ) )
195
66
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < string > . NotFound ( ) ) ;
196
67
197
68
/// <inheritdoc />
198
- ConfigurationResult < int > ITelemeteredConfigurationSource . GetInt32 ( string key , IConfigurationTelemetry telemetry , Func < int , bool > ? validator )
69
+ public ConfigurationResult < int > GetInt32 ( string key , IConfigurationTelemetry telemetry , Func < int , bool > ? validator )
199
70
=> _sources
200
71
. Select ( source => source . GetInt32 ( key , telemetry , validator ) )
201
72
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < int > . NotFound ( ) ) ;
202
73
203
74
/// <inheritdoc />
204
- ConfigurationResult < double > ITelemeteredConfigurationSource . GetDouble ( string key , IConfigurationTelemetry telemetry , Func < double , bool > ? validator )
75
+ public ConfigurationResult < double > GetDouble ( string key , IConfigurationTelemetry telemetry , Func < double , bool > ? validator )
205
76
=> _sources
206
77
. Select ( source => source . GetDouble ( key , telemetry , validator ) )
207
78
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < double > . NotFound ( ) ) ;
208
79
209
80
/// <inheritdoc />
210
- ConfigurationResult < bool > ITelemeteredConfigurationSource . GetBool ( string key , IConfigurationTelemetry telemetry , Func < bool , bool > ? validator )
81
+ public ConfigurationResult < bool > GetBool ( string key , IConfigurationTelemetry telemetry , Func < bool , bool > ? validator )
211
82
=> _sources
212
83
. Select ( source => source . GetBool ( key , telemetry , validator ) )
213
84
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < bool > . NotFound ( ) ) ;
214
85
215
86
/// <inheritdoc />
216
- ConfigurationResult < IDictionary < string , string > > ITelemeteredConfigurationSource . GetDictionary ( string key , IConfigurationTelemetry telemetry , Func < IDictionary < string , string > , bool > ? validator )
87
+ public ConfigurationResult < IDictionary < string , string > > GetDictionary ( string key , IConfigurationTelemetry telemetry , Func < IDictionary < string , string > , bool > ? validator )
217
88
=> _sources
218
89
. Select ( source => source . GetDictionary ( key , telemetry , validator ) )
219
90
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < IDictionary < string , string > > . NotFound ( ) ) ;
220
91
221
92
/// <inheritdoc />
222
- ConfigurationResult < IDictionary < string , string > > ITelemeteredConfigurationSource . GetDictionary ( string key , IConfigurationTelemetry telemetry , Func < IDictionary < string , string > , bool > ? validator , bool allowOptionalMappings , char separator )
93
+ public ConfigurationResult < IDictionary < string , string > > GetDictionary ( string key , IConfigurationTelemetry telemetry , Func < IDictionary < string , string > , bool > ? validator , bool allowOptionalMappings , char separator )
223
94
=> _sources
224
95
. Select ( source => source . GetDictionary ( key , telemetry , validator , allowOptionalMappings , separator ) )
225
96
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < IDictionary < string , string > > . NotFound ( ) ) ;
226
97
227
98
/// <inheritdoc />
228
- ConfigurationResult < T > ITelemeteredConfigurationSource . GetAs < T > ( string key , IConfigurationTelemetry telemetry , Func < string , ParsingResult < T > > converter , Func < T , bool > ? validator , bool recordValue )
99
+ public ConfigurationResult < T > GetAs < T > ( string key , IConfigurationTelemetry telemetry , Func < string , ParsingResult < T > > converter , Func < T , bool > ? validator , bool recordValue )
229
100
=> _sources
230
101
. Select ( source => source . GetAs < T > ( key , telemetry , converter , validator , recordValue ) )
231
102
. FirstOrDefault ( value => value . IsValid , ConfigurationResult < T > . NotFound ( ) ) ;
0 commit comments