@@ -15,13 +15,13 @@ namespace LaunchDarkly.Sdk.Server.Telemetry
15
15
public class TracingHookBuilder
16
16
{
17
17
private bool _createActivities ;
18
- private bool _includeVariant ;
18
+ private bool _includeValue ;
19
19
private string _environmentId ;
20
20
21
21
internal TracingHookBuilder ( )
22
22
{
23
23
_createActivities = false ;
24
- _includeVariant = false ;
24
+ _includeValue = false ;
25
25
_environmentId = null ;
26
26
}
27
27
@@ -41,15 +41,28 @@ public TracingHookBuilder CreateActivities(bool createActivities = true)
41
41
return this ;
42
42
}
43
43
44
+ /// <summary>
45
+ /// The TracingHook will include the flag value in the current activity, if one exists.
46
+ /// The value representation is a JSON string. Disabled by default.
47
+ /// </summary>
48
+ /// <param name="includeValue">true to include value, false otherwise</param>
49
+ /// <returns>this builder</returns>
50
+ public TracingHookBuilder IncludeValue ( bool includeValue = true )
51
+ {
52
+ _includeValue = includeValue ;
53
+ return this ;
54
+ }
55
+
44
56
/// <summary>
45
57
/// The TracingHook will include the flag variant in the current activity, if one exists.
46
58
/// The variant representation is a JSON string. Disabled by default.
47
59
/// </summary>
48
60
/// <param name="includeVariant">true to include variants, false otherwise</param>
49
61
/// <returns>this builder</returns>
62
+ [ System . Obsolete ( "IncludeVariant is deprecated. Use IncludeValue instead." ) ]
50
63
public TracingHookBuilder IncludeVariant ( bool includeVariant = true )
51
64
{
52
- _includeVariant = includeVariant ;
65
+ _includeValue = includeVariant ;
53
66
return this ;
54
67
}
55
68
@@ -77,7 +90,7 @@ public TracingHookBuilder EnvironmentId(string environmentId)
77
90
/// <returns>the new hook</returns>
78
91
public TracingHook Build ( )
79
92
{
80
- return new TracingHook ( new TracingHook . Options ( _createActivities , _includeVariant , _environmentId ) ) ;
93
+ return new TracingHook ( new TracingHook . Options ( _createActivities , _includeValue , _environmentId ) ) ;
81
94
}
82
95
}
83
96
@@ -107,23 +120,25 @@ private static class SemanticAttributes
107
120
{
108
121
public const string EventName = "feature_flag" ;
109
122
public const string FeatureFlagKey = "feature_flag.key" ;
110
- public const string FeatureFlagProviderName = "feature_flag.provider_name" ;
111
- public const string FeatureFlagVariant = "feature_flag.variant" ;
112
- public const string FeatureFlagContextKeyAttributeName = "feature_flag.context.key" ;
123
+ public const string FeatureFlagProviderName = "feature_flag.provider.name" ;
124
+ public const string FeatureFlagValue = "feature_flag.result.value" ;
125
+ public const string FeatureFlagVariationIndex = "feature_flag.result.variationIndex" ;
126
+ public const string FeatureFlagInExperiment = "feature_flag.result.reason.inExperiment" ;
127
+ public const string FeatureFlagContextKeyAttributeName = "feature_flag.context.id" ;
113
128
public const string FeatureFlagSetId = "feature_flag.set.id" ;
114
129
}
115
130
116
131
internal struct Options
117
132
{
118
133
public bool CreateActivities { get ; }
119
- public bool IncludeVariant { get ; }
134
+ public bool IncludeValue { get ; }
120
135
121
136
public string EnvironmentId { get ; }
122
137
123
- public Options ( bool createActivities , bool includeVariant , string environmentId = null )
138
+ public Options ( bool createActivities , bool includeValue , string environmentId = null )
124
139
{
125
140
CreateActivities = createActivities ;
126
- IncludeVariant = includeVariant ;
141
+ IncludeValue = includeValue ;
127
142
EnvironmentId = environmentId ;
128
143
}
129
144
}
@@ -179,7 +194,7 @@ public override SeriesData BeforeEvaluation(EvaluationSeriesContext context, Ser
179
194
180
195
/// <summary>
181
196
/// Ends the activity created in BeforeEvaluation, if it exists. Adds the feature flag key, provider name, and context key
182
- /// to the existing activity. If IncludeVariant is enabled, also adds the variant.
197
+ /// to the existing activity. If includeValue is enabled, also adds the variant.
183
198
/// </summary>
184
199
/// <param name="context">the evaluation parameters</param>
185
200
/// <param name="data">the series data</param>
@@ -216,9 +231,19 @@ public override SeriesData AfterEvaluation(EvaluationSeriesContext context, Seri
216
231
attributes [ SemanticAttributes . FeatureFlagSetId ] = context . EnvironmentId ;
217
232
}
218
233
219
- if ( _options . IncludeVariant )
234
+ if ( _options . IncludeValue )
235
+ {
236
+ attributes . Add ( SemanticAttributes . FeatureFlagValue , detail . Value . ToJsonString ( ) ) ;
237
+ }
238
+
239
+ if ( detail . Reason . InExperiment )
240
+ {
241
+ attributes . Add ( SemanticAttributes . FeatureFlagInExperiment , detail . Reason . InExperiment ) ;
242
+ }
243
+
244
+ if ( detail . VariationIndex . HasValue )
220
245
{
221
- attributes . Add ( SemanticAttributes . FeatureFlagVariant , detail . Value . ToJsonString ( ) ) ;
246
+ attributes . Add ( SemanticAttributes . FeatureFlagVariationIndex , detail . VariationIndex . Value ) ;
222
247
}
223
248
224
249
Activity . Current ? . AddEvent ( new ActivityEvent ( name : SemanticAttributes . EventName , tags : attributes ) ) ;
0 commit comments