11package dev .openfeature .sdk ;
22
3- import java .util .ArrayList ;
4- import java .util .Arrays ;
5- import java .util .Collections ;
6- import java .util .HashMap ;
7- import java .util .Map ;
8- import java .util .List ;
9- import java .util .function .Consumer ;
10-
113import dev .openfeature .sdk .exceptions .ExceptionUtils ;
124import dev .openfeature .sdk .exceptions .FatalError ;
135import dev .openfeature .sdk .exceptions .GeneralError ;
1911import lombok .Getter ;
2012import lombok .extern .slf4j .Slf4j ;
2113
14+ import javax .annotation .Nullable ;
15+ import java .util .ArrayList ;
16+ import java .util .Arrays ;
17+ import java .util .Collections ;
18+ import java .util .HashMap ;
19+ import java .util .List ;
20+ import java .util .Map ;
21+ import java .util .Objects ;
22+ import java .util .function .Consumer ;
23+
2224/**
2325 * OpenFeature Client implementation.
2426 * You should not instantiate this or reference this class.
2830 * @deprecated // TODO: eventually we will make this non-public. See issue #872
2931 */
3032@ Slf4j
31- @ SuppressWarnings ({ "PMD.DataflowAnomalyAnalysis" , "PMD.BeanMembersShouldSerialize" , "PMD.UnusedLocalVariable" ,
32- "unchecked" , "rawtypes" })
33+ @ SuppressWarnings ({"PMD.DataflowAnomalyAnalysis" , "PMD.BeanMembersShouldSerialize" , "PMD.UnusedLocalVariable" ,
34+ "unchecked" , "rawtypes" })
3335@ Deprecated () // TODO: eventually we will make this non-public. See issue #872
3436public class OpenFeatureClient implements Client {
3537
@@ -67,11 +69,56 @@ public OpenFeatureClient(
6769 this .hookSupport = new HookSupport ();
6870 }
6971
72+ /**
73+ * {@inheritDoc}
74+ */
7075 @ Override
7176 public ProviderState getProviderState () {
7277 return openfeatureApi .getFeatureProviderStateManager (domain ).getState ();
7378 }
7479
80+ /**
81+ * {@inheritDoc}
82+ */
83+ @ Override
84+ public void track (String trackingEventName ) {
85+ Objects .requireNonNull (trackingEventName );
86+ invokeTrack (trackingEventName , null , null );
87+ }
88+
89+
90+ /**
91+ * {@inheritDoc}
92+ */
93+ @ Override
94+ public void track (String trackingEventName , EvaluationContext context ) {
95+ Objects .requireNonNull (trackingEventName );
96+ Objects .requireNonNull (context );
97+ invokeTrack (trackingEventName , context , null );
98+ }
99+
100+ /**
101+ * {@inheritDoc}
102+ */
103+ @ Override
104+ public void track (String trackingEventName , TrackingEventDetails details ) {
105+ Objects .requireNonNull (trackingEventName );
106+ Objects .requireNonNull (details );
107+ invokeTrack (trackingEventName , null , details );
108+ }
109+
110+ /**
111+ * {@inheritDoc}
112+ */
113+ @ Override
114+ public void track (String trackingEventName , EvaluationContext context , TrackingEventDetails details ) {
115+ Objects .requireNonNull (trackingEventName );
116+ Objects .requireNonNull (context );
117+ Objects .requireNonNull (details );
118+ invokeTrack (trackingEventName , mergeEvaluationContext (context ), details );
119+ }
120+
121+
75122 /**
76123 * {@inheritDoc}
77124 */
@@ -115,7 +162,7 @@ public EvaluationContext getEvaluationContext() {
115162 }
116163
117164 private <T > FlagEvaluationDetails <T > evaluateFlag (FlagValueType type , String key , T defaultValue ,
118- EvaluationContext ctx , FlagEvaluationOptions options ) {
165+ EvaluationContext ctx , FlagEvaluationOptions options ) {
119166 FlagEvaluationOptions flagOptions = ObjectUtils .defaultIfNull (options ,
120167 () -> FlagEvaluationOptions .builder ().build ());
121168 Map <String , Object > hints = Collections .unmodifiableMap (flagOptions .getHookHints ());
@@ -183,6 +230,17 @@ private static <T> void enrichDetailsWithErrorDefaults(T defaultValue, FlagEvalu
183230 details .setReason (Reason .ERROR .toString ());
184231 }
185232
233+ private void invokeTrack (String trackingEventName ,
234+ @ Nullable EvaluationContext context ,
235+ @ Nullable TrackingEventDetails details ) {
236+ if ("" .equals (trackingEventName )) {
237+ throw new IllegalArgumentException ("trackingEventName cannot be empty" );
238+ }
239+ openfeatureApi .getFeatureProviderStateManager (domain )
240+ .getProvider ()
241+ .track (trackingEventName , mergeEvaluationContext (context ), details );
242+ }
243+
186244 /**
187245 * Merge invocation contexts with API, transaction and client contexts.
188246 * Does not merge before context.
@@ -244,7 +302,7 @@ public Boolean getBooleanValue(String key, Boolean defaultValue, EvaluationConte
244302
245303 @ Override
246304 public Boolean getBooleanValue (String key , Boolean defaultValue , EvaluationContext ctx ,
247- FlagEvaluationOptions options ) {
305+ FlagEvaluationOptions options ) {
248306 return getBooleanDetails (key , defaultValue , ctx , options ).getValue ();
249307 }
250308
@@ -260,7 +318,7 @@ public FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defa
260318
261319 @ Override
262320 public FlagEvaluationDetails <Boolean > getBooleanDetails (String key , Boolean defaultValue , EvaluationContext ctx ,
263- FlagEvaluationOptions options ) {
321+ FlagEvaluationOptions options ) {
264322 return this .evaluateFlag (FlagValueType .BOOLEAN , key , defaultValue , ctx , options );
265323 }
266324
@@ -276,7 +334,7 @@ public String getStringValue(String key, String defaultValue, EvaluationContext
276334
277335 @ Override
278336 public String getStringValue (String key , String defaultValue , EvaluationContext ctx ,
279- FlagEvaluationOptions options ) {
337+ FlagEvaluationOptions options ) {
280338 return getStringDetails (key , defaultValue , ctx , options ).getValue ();
281339 }
282340
@@ -292,7 +350,7 @@ public FlagEvaluationDetails<String> getStringDetails(String key, String default
292350
293351 @ Override
294352 public FlagEvaluationDetails <String > getStringDetails (String key , String defaultValue , EvaluationContext ctx ,
295- FlagEvaluationOptions options ) {
353+ FlagEvaluationOptions options ) {
296354 return this .evaluateFlag (FlagValueType .STRING , key , defaultValue , ctx , options );
297355 }
298356
@@ -308,7 +366,7 @@ public Integer getIntegerValue(String key, Integer defaultValue, EvaluationConte
308366
309367 @ Override
310368 public Integer getIntegerValue (String key , Integer defaultValue , EvaluationContext ctx ,
311- FlagEvaluationOptions options ) {
369+ FlagEvaluationOptions options ) {
312370 return getIntegerDetails (key , defaultValue , ctx , options ).getValue ();
313371 }
314372
@@ -324,7 +382,7 @@ public FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defa
324382
325383 @ Override
326384 public FlagEvaluationDetails <Integer > getIntegerDetails (String key , Integer defaultValue , EvaluationContext ctx ,
327- FlagEvaluationOptions options ) {
385+ FlagEvaluationOptions options ) {
328386 return this .evaluateFlag (FlagValueType .INTEGER , key , defaultValue , ctx , options );
329387 }
330388
@@ -340,7 +398,7 @@ public Double getDoubleValue(String key, Double defaultValue, EvaluationContext
340398
341399 @ Override
342400 public Double getDoubleValue (String key , Double defaultValue , EvaluationContext ctx ,
343- FlagEvaluationOptions options ) {
401+ FlagEvaluationOptions options ) {
344402 return this .evaluateFlag (FlagValueType .DOUBLE , key , defaultValue , ctx , options ).getValue ();
345403 }
346404
@@ -356,7 +414,7 @@ public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double default
356414
357415 @ Override
358416 public FlagEvaluationDetails <Double > getDoubleDetails (String key , Double defaultValue , EvaluationContext ctx ,
359- FlagEvaluationOptions options ) {
417+ FlagEvaluationOptions options ) {
360418 return this .evaluateFlag (FlagValueType .DOUBLE , key , defaultValue , ctx , options );
361419 }
362420
@@ -372,7 +430,7 @@ public Value getObjectValue(String key, Value defaultValue, EvaluationContext ct
372430
373431 @ Override
374432 public Value getObjectValue (String key , Value defaultValue , EvaluationContext ctx ,
375- FlagEvaluationOptions options ) {
433+ FlagEvaluationOptions options ) {
376434 return getObjectDetails (key , defaultValue , ctx , options ).getValue ();
377435 }
378436
@@ -383,13 +441,13 @@ public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultVa
383441
384442 @ Override
385443 public FlagEvaluationDetails <Value > getObjectDetails (String key , Value defaultValue ,
386- EvaluationContext ctx ) {
444+ EvaluationContext ctx ) {
387445 return getObjectDetails (key , defaultValue , ctx , FlagEvaluationOptions .builder ().build ());
388446 }
389447
390448 @ Override
391449 public FlagEvaluationDetails <Value > getObjectDetails (String key , Value defaultValue , EvaluationContext ctx ,
392- FlagEvaluationOptions options ) {
450+ FlagEvaluationOptions options ) {
393451 return this .evaluateFlag (FlagValueType .OBJECT , key , defaultValue , ctx , options );
394452 }
395453
0 commit comments