Skip to content

Commit fd924ab

Browse files
committed
Add "telemetry override" parameter to ConfigurationResult.
This is necessary so that we can "correct" telemetry that is overridden in the CompositeConfigurationSource
1 parent 8cb6a7b commit fd924ab

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

tracer/src/Datadog.Trace/Configuration/ConfigurationSources/DictionaryObjectConfigurationSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
142142
if (validator is null || validator(value))
143143
{
144144
telemetry.Record(key, dictAsString, recordValue: true, Origin);
145-
return ConfigurationResult<IDictionary<string, string>>.Valid(value);
145+
return ConfigurationResult<IDictionary<string, string>>.Valid(value, dictAsString);
146146
}
147147

148148
telemetry.Record(key, dictAsString, recordValue: true, Origin, TelemetryErrorCode.FailedValidation);
@@ -173,7 +173,7 @@ public ConfigurationResult<T> GetAs<T>(string key, IConfigurationTelemetry telem
173173
if (validator is null || validator(result.Result))
174174
{
175175
telemetry.Record(key, valueAsString, recordValue, Origin);
176-
return ConfigurationResult<T>.Valid(result.Result);
176+
return ConfigurationResult<T>.Valid(result.Result, valueAsString);
177177
}
178178

179179
telemetry.Record(key, valueAsString, recordValue, Origin, TelemetryErrorCode.FailedValidation);

tracer/src/Datadog.Trace/Configuration/ConfigurationSources/JsonConfigurationSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public ConfigurationResult<T> GetAs<T>(string key, IConfigurationTelemetry telem
230230
if (validator is null || validator(value.Result))
231231
{
232232
telemetry.Record(key, valueAsString, recordValue, Origin);
233-
return ConfigurationResult<T>.Valid(value.Result);
233+
return ConfigurationResult<T>.Valid(value.Result, valueAsString);
234234
}
235235

236236
telemetry.Record(key, valueAsString, recordValue, Origin, TelemetryErrorCode.FailedValidation);
@@ -321,7 +321,7 @@ ConfigurationResult<IDictionary<string, string>> Validate(IDictionary<string, st
321321
if (validator is null || validator(dictionary))
322322
{
323323
telemetry.Record(key, tokenAsString, recordValue: true, Origin);
324-
return ConfigurationResult<IDictionary<string, string>>.Valid(dictionary);
324+
return ConfigurationResult<IDictionary<string, string>>.Valid(dictionary, tokenAsString);
325325
}
326326

327327
telemetry.Record(key, tokenAsString, recordValue: true, Origin, TelemetryErrorCode.FailedValidation);
@@ -383,7 +383,7 @@ ConfigurationResult<IDictionary<string, string>> Validate(IDictionary<string, st
383383
if (validator is null || validator(dictionary))
384384
{
385385
telemetry.Record(key, tokenAsString, recordValue: true, Origin);
386-
return ConfigurationResult<IDictionary<string, string>>.Valid(dictionary);
386+
return ConfigurationResult<IDictionary<string, string>>.Valid(dictionary, tokenAsString);
387387
}
388388

389389
telemetry.Record(key, tokenAsString, recordValue: true, Origin, TelemetryErrorCode.FailedValidation);

tracer/src/Datadog.Trace/Configuration/ConfigurationSources/StringConfigurationSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public ConfigurationResult<T> GetAs<T>(string key, IConfigurationTelemetry telem
229229
if (validator is null || validator(result.Result))
230230
{
231231
telemetry.Record(key, value, recordValue, Origin);
232-
return ConfigurationResult<T>.Valid(result.Result);
232+
return ConfigurationResult<T>.Valid(result.Result, value);
233233
}
234234

235235
telemetry.Record(key, value, recordValue, Origin, TelemetryErrorCode.FailedValidation);
@@ -262,7 +262,7 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
262262
if (validator is null || validator(result))
263263
{
264264
telemetry.Record(key, value, recordValue: true, Origin);
265-
return ConfigurationResult<IDictionary<string, string>>.Valid(result);
265+
return ConfigurationResult<IDictionary<string, string>>.Valid(result, value);
266266
}
267267

268268
telemetry.Record(key, value, recordValue: true, Origin, TelemetryErrorCode.FailedValidation);
@@ -287,7 +287,7 @@ public ConfigurationResult<IDictionary<string, string>> GetDictionary(string key
287287
if (validator is null || validator(result))
288288
{
289289
telemetry.Record(key, value, recordValue: true, Origin);
290-
return ConfigurationResult<IDictionary<string, string>>.Valid(result);
290+
return ConfigurationResult<IDictionary<string, string>>.Valid(result, value);
291291
}
292292

293293
telemetry.Record(key, value, recordValue: true, Origin, TelemetryErrorCode.FailedValidation);

tracer/src/Datadog.Trace/Configuration/ConfigurationSources/Telemetry/ConfigurationResult.cs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ namespace Datadog.Trace.Configuration.ConfigurationSources.Telemetry;
1515
/// <typeparam name="T">The type of the returned value</typeparam>
1616
public readonly record struct ConfigurationResult<T>
1717
{
18-
private ConfigurationResult(T? result, ConfigurationLoadResult loadResult)
18+
private ConfigurationResult(T? result, string? telemetryOverride, ConfigurationLoadResult loadResult)
1919
{
2020
Result = result;
21+
TelemetryOverride = telemetryOverride;
2122
LoadResult = loadResult;
2223
}
2324

@@ -26,6 +27,12 @@ private ConfigurationResult(T? result, ConfigurationLoadResult loadResult)
2627
/// </summary>
2728
public T? Result { get; }
2829

30+
/// <summary>
31+
/// Gets the configuration value that represents the <see cref="Result"/> in telemetry,
32+
/// where <typeparamref name="T"/> cannot be directly stored in telemetry.
33+
/// </summary>
34+
public string? TelemetryOverride { get; }
35+
2936
/// <summary>
3037
/// Gets a value indicating whether <see cref="Result"/> result passed validation.
3138
/// If <c>true</c>, implies that <see cref="Result"/> contains a valid value. If
@@ -55,24 +62,55 @@ private ConfigurationResult(T? result, ConfigurationLoadResult loadResult)
5562
/// </summary>
5663
/// <param name="result">The value to use</param>
5764
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
58-
public static ConfigurationResult<T> Valid(T result) => new(result, ConfigurationLoadResult.Valid);
65+
public static ConfigurationResult<int> Valid(int result) => new(result, null, ConfigurationLoadResult.Valid);
66+
67+
/// <summary>
68+
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.Valid"/> value
69+
/// </summary>
70+
/// <param name="result">The value to use</param>
71+
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
72+
public static ConfigurationResult<bool> Valid(bool result) => new(result, null, ConfigurationLoadResult.Valid);
73+
74+
/// <summary>
75+
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.Valid"/> value
76+
/// </summary>
77+
/// <param name="result">The value to use</param>
78+
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
79+
public static ConfigurationResult<double> Valid(double result) => new(result, null, ConfigurationLoadResult.Valid);
80+
81+
/// <summary>
82+
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.Valid"/> value
83+
/// </summary>
84+
/// <param name="result">The value to use</param>
85+
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
86+
public static ConfigurationResult<string> Valid(string result) => new(result, null, ConfigurationLoadResult.Valid);
87+
88+
/// <summary>
89+
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.Valid"/> value
90+
/// </summary>
91+
/// <param name="result">The value to use</param>
92+
/// <param name="telemetryOverride">The telemetry value to use where the value of <paramref name="result"/> cannot be stored directly in telemetry.
93+
/// This is required if <typeparamref name="T"/> is not an int/bool/double/string</param>
94+
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
95+
public static ConfigurationResult<T> Valid(T result, string? telemetryOverride)
96+
=> new(result, telemetryOverride, ConfigurationLoadResult.Valid);
5997

6098
/// <summary>
6199
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.ValidationFailure"/> value
62100
/// </summary>
63101
/// <param name="result">The value that failed validation</param>
64102
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
65-
public static ConfigurationResult<T> Invalid(T result) => new(result, ConfigurationLoadResult.ValidationFailure);
103+
public static ConfigurationResult<T> Invalid(T result) => new(result, null, ConfigurationLoadResult.ValidationFailure);
66104

67105
/// <summary>
68106
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.NotFound"/> value
69107
/// </summary>
70108
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
71-
public static ConfigurationResult<T> NotFound() => new(default, ConfigurationLoadResult.NotFound);
109+
public static ConfigurationResult<T> NotFound() => new(default, null, ConfigurationLoadResult.NotFound);
72110

73111
/// <summary>
74112
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.ParsingError"/> value
75113
/// </summary>
76114
/// <returns>The <see cref="ConfigurationResult{T}"/></returns>
77-
public static ConfigurationResult<T> ParseFailure() => new(default, ConfigurationLoadResult.ParsingError);
115+
public static ConfigurationResult<T> ParseFailure() => new(default, null, ConfigurationLoadResult.ParsingError);
78116
}

0 commit comments

Comments
 (0)