@@ -28,7 +28,6 @@ internal class JsonConfigurationSource : IConfigurationSource
28
28
{
29
29
private static readonly IDatadogLogger Log = DatadogLogging . GetLoggerFor ( typeof ( JsonConfigurationSource ) ) ;
30
30
private readonly JToken ? _configuration ;
31
- private readonly ConfigurationOrigins _origin ;
32
31
33
32
/// <summary>
34
33
/// Initializes a new instance of the <see cref="JsonConfigurationSource"/>
@@ -60,9 +59,11 @@ private protected JsonConfigurationSource(string json, ConfigurationOrigins orig
60
59
if ( deserialize is null ) { ThrowHelper . ThrowArgumentNullException ( nameof ( deserialize ) ) ; }
61
60
62
61
_configuration = deserialize ( json ) ;
63
- _origin = origin ;
62
+ Origin = origin ;
64
63
}
65
64
65
+ public ConfigurationOrigins Origin { get ; }
66
+
66
67
internal string ? JsonConfigurationFilePath { get ; }
67
68
68
69
internal bool TreatNullDictionaryAsEmpty { get ; set ; } = true ;
@@ -108,17 +109,17 @@ public ConfigurationResult<string> GetString(string key, IConfigurationTelemetry
108
109
{
109
110
if ( validator is null || validator ( value ) )
110
111
{
111
- telemetry . Record ( key , value , recordValue , _origin ) ;
112
+ telemetry . Record ( key , value , recordValue , Origin ) ;
112
113
return ConfigurationResult < string > . Valid ( value ) ;
113
114
}
114
115
115
- telemetry . Record ( key , value , recordValue , _origin , TelemetryErrorCode . FailedValidation ) ;
116
+ telemetry . Record ( key , value , recordValue , Origin , TelemetryErrorCode . FailedValidation ) ;
116
117
return ConfigurationResult < string > . Invalid ( value ) ;
117
118
}
118
119
}
119
120
catch ( Exception )
120
121
{
121
- telemetry . Record ( key , token ? . ToString ( ) , recordValue , _origin , TelemetryErrorCode . JsonStringError ) ;
122
+ telemetry . Record ( key , token ? . ToString ( ) , recordValue , Origin , TelemetryErrorCode . JsonStringError ) ;
122
123
throw ; // Existing behaviour
123
124
}
124
125
@@ -137,17 +138,17 @@ public ConfigurationResult<int> GetInt32(string key, IConfigurationTelemetry tel
137
138
{
138
139
if ( validator is null || validator ( value . Value ) )
139
140
{
140
- telemetry . Record ( key , value . Value , _origin ) ;
141
+ telemetry . Record ( key , value . Value , Origin ) ;
141
142
return ConfigurationResult < int > . Valid ( value . Value ) ;
142
143
}
143
144
144
- telemetry . Record ( key , value . Value , _origin , TelemetryErrorCode . FailedValidation ) ;
145
+ telemetry . Record ( key , value . Value , Origin , TelemetryErrorCode . FailedValidation ) ;
145
146
return ConfigurationResult < int > . Invalid ( value . Value ) ;
146
147
}
147
148
}
148
149
catch ( Exception )
149
150
{
150
- telemetry . Record ( key , token ? . ToString ( ) , recordValue : true , _origin , TelemetryErrorCode . JsonInt32Error ) ;
151
+ telemetry . Record ( key , token ? . ToString ( ) , recordValue : true , Origin , TelemetryErrorCode . JsonInt32Error ) ;
151
152
throw ; // Exising behaviour
152
153
}
153
154
@@ -166,17 +167,17 @@ public ConfigurationResult<double> GetDouble(string key, IConfigurationTelemetry
166
167
{
167
168
if ( validator is null || validator ( value . Value ) )
168
169
{
169
- telemetry . Record ( key , value . Value , _origin ) ;
170
+ telemetry . Record ( key , value . Value , Origin ) ;
170
171
return ConfigurationResult < double > . Valid ( value . Value ) ;
171
172
}
172
173
173
- telemetry . Record ( key , value . Value , _origin , TelemetryErrorCode . FailedValidation ) ;
174
+ telemetry . Record ( key , value . Value , Origin , TelemetryErrorCode . FailedValidation ) ;
174
175
return ConfigurationResult < double > . Invalid ( value . Value ) ;
175
176
}
176
177
}
177
178
catch ( Exception )
178
179
{
179
- telemetry . Record ( key , token ? . ToString ( ) , recordValue : true , _origin , TelemetryErrorCode . JsonDoubleError ) ;
180
+ telemetry . Record ( key , token ? . ToString ( ) , recordValue : true , Origin , TelemetryErrorCode . JsonDoubleError ) ;
180
181
throw ; // Exising behaviour
181
182
}
182
183
@@ -195,17 +196,17 @@ public ConfigurationResult<bool> GetBool(string key, IConfigurationTelemetry tel
195
196
{
196
197
if ( validator is null || validator ( value . Value ) )
197
198
{
198
- telemetry . Record ( key , value . Value , _origin ) ;
199
+ telemetry . Record ( key , value . Value , Origin ) ;
199
200
return ConfigurationResult < bool > . Valid ( value . Value ) ;
200
201
}
201
202
202
- telemetry . Record ( key , value . Value , _origin , TelemetryErrorCode . FailedValidation ) ;
203
+ telemetry . Record ( key , value . Value , Origin , TelemetryErrorCode . FailedValidation ) ;
203
204
return ConfigurationResult < bool > . Invalid ( value . Value ) ;
204
205
}
205
206
}
206
207
catch ( Exception )
207
208
{
208
- telemetry . Record ( key , token ? . ToString ( ) , recordValue : true , _origin , TelemetryErrorCode . JsonBooleanError ) ;
209
+ telemetry . Record ( key , token ? . ToString ( ) , recordValue : true , Origin , TelemetryErrorCode . JsonBooleanError ) ;
209
210
throw ; // Exising behaviour
210
211
}
211
212
@@ -228,20 +229,20 @@ public ConfigurationResult<T> GetAs<T>(string key, IConfigurationTelemetry telem
228
229
{
229
230
if ( validator is null || validator ( value . Result ) )
230
231
{
231
- telemetry . Record ( key , valueAsString , recordValue , _origin ) ;
232
+ telemetry . Record ( key , valueAsString , recordValue , Origin ) ;
232
233
return ConfigurationResult < T > . Valid ( value . Result ) ;
233
234
}
234
235
235
- telemetry . Record ( key , valueAsString , recordValue , _origin , TelemetryErrorCode . FailedValidation ) ;
236
+ telemetry . Record ( key , valueAsString , recordValue , Origin , TelemetryErrorCode . FailedValidation ) ;
236
237
return ConfigurationResult < T > . Invalid ( value . Result ) ;
237
238
}
238
239
239
- telemetry . Record ( key , valueAsString , recordValue , _origin , TelemetryErrorCode . ParsingCustomError ) ;
240
+ telemetry . Record ( key , valueAsString , recordValue , Origin , TelemetryErrorCode . ParsingCustomError ) ;
240
241
}
241
242
}
242
243
catch ( Exception )
243
244
{
244
- telemetry . Record ( key , token ? . ToString ( ) , recordValue , _origin , TelemetryErrorCode . JsonStringError ) ;
245
+ telemetry . Record ( key , token ? . ToString ( ) , recordValue , Origin , TelemetryErrorCode . JsonStringError ) ;
245
246
throw ; // Exising behaviour
246
247
}
247
248
@@ -301,7 +302,7 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
301
302
catch ( Exception e )
302
303
{
303
304
Log . Error ( e , "Unable to parse configuration value for {ConfigurationKey} as key-value pairs of strings." , key ) ;
304
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin , TelemetryErrorCode . JsonStringError ) ;
305
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin , TelemetryErrorCode . JsonStringError ) ;
305
306
return ConfigurationResult < IDictionary < string , string > > . ParseFailure ( ) ;
306
307
}
307
308
}
@@ -311,19 +312,19 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
311
312
}
312
313
catch ( InvalidCastException )
313
314
{
314
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin , TelemetryErrorCode . JsonStringError ) ;
315
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin , TelemetryErrorCode . JsonStringError ) ;
315
316
throw ; // Exising behaviour
316
317
}
317
318
318
319
ConfigurationResult < IDictionary < string , string > > Validate ( IDictionary < string , string > dictionary )
319
320
{
320
321
if ( validator is null || validator ( dictionary ) )
321
322
{
322
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin ) ;
323
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin ) ;
323
324
return ConfigurationResult < IDictionary < string , string > > . Valid ( dictionary ) ;
324
325
}
325
326
326
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin , TelemetryErrorCode . FailedValidation ) ;
327
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin , TelemetryErrorCode . FailedValidation ) ;
327
328
return ConfigurationResult < IDictionary < string , string > > . Invalid ( dictionary ) ;
328
329
}
329
330
}
@@ -363,7 +364,7 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
363
364
catch ( Exception e )
364
365
{
365
366
Log . Error ( e , "Unable to parse configuration value for {ConfigurationKey} as key-value pairs of strings." , key ) ;
366
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin , TelemetryErrorCode . JsonStringError ) ;
367
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin , TelemetryErrorCode . JsonStringError ) ;
367
368
return ConfigurationResult < IDictionary < string , string > > . ParseFailure ( ) ;
368
369
}
369
370
}
@@ -373,19 +374,19 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
373
374
}
374
375
catch ( InvalidCastException )
375
376
{
376
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin , TelemetryErrorCode . JsonStringError ) ;
377
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin , TelemetryErrorCode . JsonStringError ) ;
377
378
throw ; // Exising behaviour
378
379
}
379
380
380
381
ConfigurationResult < IDictionary < string , string > > Validate ( IDictionary < string , string > dictionary )
381
382
{
382
383
if ( validator is null || validator ( dictionary ) )
383
384
{
384
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin ) ;
385
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin ) ;
385
386
return ConfigurationResult < IDictionary < string , string > > . Valid ( dictionary ) ;
386
387
}
387
388
388
- telemetry . Record ( key , tokenAsString , recordValue : true , _origin , TelemetryErrorCode . FailedValidation ) ;
389
+ telemetry . Record ( key , tokenAsString , recordValue : true , Origin , TelemetryErrorCode . FailedValidation ) ;
389
390
return ConfigurationResult < IDictionary < string , string > > . Invalid ( dictionary ) ;
390
391
}
391
392
}
0 commit comments