@@ -15,9 +15,10 @@ namespace Datadog.Trace.Configuration.ConfigurationSources.Telemetry;
15
15
/// <typeparam name="T">The type of the returned value</typeparam>
16
16
public readonly record struct ConfigurationResult < T >
17
17
{
18
- private ConfigurationResult ( T ? result , ConfigurationLoadResult loadResult )
18
+ private ConfigurationResult ( T ? result , string ? telemetryOverride , ConfigurationLoadResult loadResult )
19
19
{
20
20
Result = result ;
21
+ TelemetryOverride = telemetryOverride ;
21
22
LoadResult = loadResult ;
22
23
}
23
24
@@ -26,6 +27,12 @@ private ConfigurationResult(T? result, ConfigurationLoadResult loadResult)
26
27
/// </summary>
27
28
public T ? Result { get ; }
28
29
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
+
29
36
/// <summary>
30
37
/// Gets a value indicating whether <see cref="Result"/> result passed validation.
31
38
/// If <c>true</c>, implies that <see cref="Result"/> contains a valid value. If
@@ -55,24 +62,55 @@ private ConfigurationResult(T? result, ConfigurationLoadResult loadResult)
55
62
/// </summary>
56
63
/// <param name="result">The value to use</param>
57
64
/// <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 ) ;
59
97
60
98
/// <summary>
61
99
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.ValidationFailure"/> value
62
100
/// </summary>
63
101
/// <param name="result">The value that failed validation</param>
64
102
/// <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 ) ;
66
104
67
105
/// <summary>
68
106
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.NotFound"/> value
69
107
/// </summary>
70
108
/// <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 ) ;
72
110
73
111
/// <summary>
74
112
/// Creates an instance of <see cref="ConfigurationResult{T}" /> with a <see cref="ConfigurationLoadResult.ParsingError"/> value
75
113
/// </summary>
76
114
/// <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 ) ;
78
116
}
0 commit comments