1717-export ([stop_instance /1 ]).
1818-export ([evaluate /3 ]).
1919-export ([evaluate /4 ]).
20+ -export ([variation /3 ]).
21+ -export ([variation /4 ]).
22+ -export ([variation_detail /3 ]).
23+ -export ([variation_detail /4 ]).
2024-export ([all_flags_state /1 ]).
2125-export ([all_flags_state /2 ]).
2226-export ([identify /1 ]).
@@ -93,6 +97,33 @@ stop_instance(Tag) when is_atom(Tag) ->
9397
9498% % @doc Evaluate given flag key for given user
9599% %
100+ % % Evaluates the flag and returns the resulting variation value. The default
101+ % % value will be returned in case of any errors.
102+ % % @end
103+ -spec variation (FlagKey :: binary (), User :: eld_user :user (), DefaultValue :: eld_eval :result_value ()) ->
104+ eld_eval :result_value ().
105+ variation (FlagKey , User , DefaultValue ) when is_binary (FlagKey ), is_map (User ) ->
106+ variation (FlagKey , User , DefaultValue , ? DEFAULT_INSTANCE_NAME ).
107+
108+ % % @doc Evaluate given flag key for given user and given client instance
109+ % %
110+ % % Evaluates the flag and returns the resulting variation value. The default
111+ % % value will be returned in case of any errors.
112+ % % @end
113+ -spec variation (FlagKey :: binary (), User :: eld_user :user (), DefaultValue :: eld_eval :result_value (), Tag :: atom ()) ->
114+ eld_eval :result_value ().
115+ variation (FlagKey , User , DefaultValue , Tag ) when is_binary (FlagKey ), is_map (User ) ->
116+ % Get evaluation result detail
117+ {{_Index , Value , _Reason }, Events } = eld_eval :flag_key_for_user (Tag , FlagKey , User , DefaultValue ),
118+ % Send events
119+ SendEventsFun = fun (Event ) -> eld_event_server :add_event (Tag , Event , #{}) end ,
120+ lists :foreach (SendEventsFun , Events ),
121+ % Return evaluation result
122+ Value .
123+
124+ % % @doc Evaluate given flag key for given user
125+ % % @deprecated
126+ % %
96127% % Evaluation iterates through flag's prerequisites, targets, rules, associated
97128% % clauses and percentage rollouts. It returns the flag variation index, value
98129% % and reason, explaining why the specific result was chosen.
@@ -103,6 +134,7 @@ evaluate(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
103134 evaluate (? DEFAULT_INSTANCE_NAME , FlagKey , User , DefaultValue ).
104135
105136% % @doc Evaluate given flag key for given user and given client instance
137+ % % @deprecated
106138% %
107139% % Evaluation iterates through flag's prerequisites, targets, rules, associated
108140% % clauses and percentage rollouts. It returns the flag variation index, value
@@ -111,10 +143,33 @@ evaluate(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
111143-spec evaluate (Tag :: atom (), FlagKey :: binary (), User :: eld_user :user (), DefaultValue :: eld_eval :result_value ()) ->
112144 eld_eval :detail ().
113145evaluate (Tag , FlagKey , User , DefaultValue ) when is_binary (FlagKey ), is_map (User ) ->
146+ error_logger :info_msg (" eld:evaluate/3-4 is deprecated, use eld:variation_detail/3-4 instead." ),
147+ variation_detail (FlagKey , User , DefaultValue , Tag ).
148+
149+ % % @doc Evaluate given flag key for given user
150+ % %
151+ % % Evaluates the flag and returns the result detail containing the variation
152+ % % index, value, and reason why the specific result was chosen. The default
153+ % % value will be returned in case of any errors.
154+ % % @end
155+ -spec variation_detail (FlagKey :: binary (), User :: eld_user :user (), DefaultValue :: eld_eval :result_value ()) ->
156+ eld_eval :detail ().
157+ variation_detail (FlagKey , User , DefaultValue ) when is_binary (FlagKey ), is_map (User ) ->
158+ variation_detail (FlagKey , User , DefaultValue , ? DEFAULT_INSTANCE_NAME ).
159+
160+ % % @doc Evaluate given flag key for given user and given client instance
161+ % %
162+ % % Evaluates the flag and returns the result detail containing the variation
163+ % % index, value, and reason why the specific result was chosen. The default
164+ % % value will be returned in case of any errors.
165+ % % @end
166+ -spec variation_detail (FlagKey :: binary (), User :: eld_user :user (), DefaultValue :: eld_eval :result_value (), Tag :: atom ()) ->
167+ eld_eval :detail ().
168+ variation_detail (FlagKey , User , DefaultValue , Tag ) when is_binary (FlagKey ), is_map (User ) ->
114169 % Get evaluation result detail
115170 {Detail , Events } = eld_eval :flag_key_for_user (Tag , FlagKey , User , DefaultValue ),
116171 % Send events
117- SendEventsFun = fun (Event ) -> eld_event_server :add_event (Tag , Event ) end ,
172+ SendEventsFun = fun (Event ) -> eld_event_server :add_event (Tag , Event , #{ include_reasons => true } ) end ,
118173 lists :foreach (SendEventsFun , Events ),
119174 % Return evaluation detail
120175 Detail .
@@ -126,15 +181,15 @@ evaluate(Tag, FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User)
126181% % @end
127182-spec all_flags_state (User :: eld_user :user ()) -> feature_flags_state ().
128183all_flags_state (User ) ->
129- all_flags_state (? DEFAULT_INSTANCE_NAME , User ).
184+ all_flags_state (User , ? DEFAULT_INSTANCE_NAME ).
130185
131186% % @doc Evaluate all flags for a given user and given client instance
132187% %
133188% % Evaluates all existing flags, but does not create any events as a side
134189% % effect of the evaluation. It returns a map of flag keys to evaluated values.
135190% % @end
136- -spec all_flags_state (Tag :: atom (), User :: eld_user : user ()) -> feature_flags_state ().
137- all_flags_state (Tag , User ) ->
191+ -spec all_flags_state (User :: eld_user : user (), Tag :: atom ()) -> feature_flags_state ().
192+ all_flags_state (User , Tag ) ->
138193 StorageBackend = eld_settings :get_value (Tag , storage_backend ),
139194 AllFlags = [FlagKey || {FlagKey , _ } <- StorageBackend :list (default , flags )],
140195 EvalFun = fun (FlagKey , Acc ) ->
@@ -149,30 +204,30 @@ all_flags_state(Tag, User) ->
149204% % @end
150205-spec identify (User :: eld_user :user ()) -> ok .
151206identify (User ) ->
152- identify (? DEFAULT_INSTANCE_NAME , User ).
207+ identify (User , ? DEFAULT_INSTANCE_NAME ).
153208
154209% % @doc Identify reports details about a user
155210% %
156211% % This is useful to report user to a specific client instance.
157212% % @end
158- -spec identify (Tag :: atom (), User :: eld_user : user ()) -> ok .
159- identify (Tag , User ) when is_atom (Tag ) ->
213+ -spec identify (User :: eld_user : user (), Tag :: atom ()) -> ok .
214+ identify (User , Tag ) when is_atom (Tag ) ->
160215 Event = eld_event :new_identify (User ),
161- eld_event_server :add_event (Tag , Event ).
216+ eld_event_server :add_event (Tag , Event , #{} ).
162217
163218% % @doc Track reports that a user has performed an event
164219% %
165220% % Custom data can be attached to the event.
166221% % @end
167222-spec track (Key :: binary (), User :: eld_user :user (), Data :: map ()) -> ok .
168223track (Key , User , Data ) when is_binary (Key ), is_map (Data ) ->
169- track (? DEFAULT_INSTANCE_NAME , Key , User , Data ).
224+ track (Key , User , Data , ? DEFAULT_INSTANCE_NAME ).
170225
171226% % @doc Track reports that a user has performed an event
172227% %
173228% % This is useful for specifying a specific client instance.
174229% % @end
175- -spec track (Tag :: atom (), Key :: binary (), User :: eld_user :user (), Data :: map ()) -> ok .
176- track (Tag , Key , User , Data ) when is_atom (Tag ), is_binary (Key ), is_map (Data ) ->
230+ -spec track (Key :: binary (), User :: eld_user :user (), Data :: map (), Tag :: atom ()) -> ok .
231+ track (Key , User , Data , Tag ) when is_atom (Tag ), is_binary (Key ), is_map (Data ) ->
177232 Event = eld_event :new_custom (Key , User , Data ),
178- eld_event_server :add_event (Tag , Event ).
233+ eld_event_server :add_event (Tag , Event , #{} ).
0 commit comments