4040use vwo \Utils \NetworkUtil ;
4141use vwo \Enums \EventEnum ;
4242use vwo \Services \SettingsService ;
43+ use vwo \Utils \DebuggerServiceUtil ;
44+ use vwo \Enums \DebuggerCategoryEnum ;
45+ use vwo \Services \LoggerService ;
46+ use vwo \Packages \Logger \Enums \LogLevelEnum ;
47+ use vwo \Constants \Constants ;
4348
4449class GetFlag
4550{
@@ -64,6 +69,7 @@ public function get(
6469
6570 $ hooksService = $ serviceContainer ->getHooksService ();
6671 $ logManager = $ serviceContainer ->getLogManager ();
72+ $ loggerService = $ serviceContainer ->getLoggerService ();
6773
6874 // Get feature object from feature key
6975 $ feature = FunctionUtil::getFeatureFromKey ($ serviceContainer ->getSettings (), $ featureKey );
@@ -75,6 +81,14 @@ public function get(
7581 'api ' => ApiEnum::GET_FLAG ,
7682 ];
7783
84+ // create debug event props
85+ $ debugEventProps = [
86+ 'an ' => ApiEnum::GET_FLAG ,
87+ 'uuid ' => $ context ? $ context ->getVwoUuid () : null ,
88+ 'fk ' => $ feature ? $ feature ->getKey () : null ,
89+ 'sId ' => $ context ? $ context ->getSessionId () : null ,
90+ ];
91+
7892 // Retrieve stored data
7993 $ storedData = (new StorageDecorator ())->getFeatureFromStorage (
8094 $ featureKey ,
@@ -134,10 +148,10 @@ public function get(
134148 }
135149
136150 if (!DataTypeUtil::isObject ($ feature )) {
137- $ logManager ->error (sprintf (
138- " Feature not found for the key: %s " ,
139- $ featureKey
140- ));
151+ $ loggerService ->error (' FEATURE_NOT_FOUND ' ,
152+ array_merge ([
153+ ' featureKey ' => $ featureKey,
154+ ], $ debugEventProps ));
141155
142156 return new GetFlagResultUtil (false , [], $ ruleStatus );
143157 }
@@ -172,7 +186,7 @@ public function get(
172186
173187 if (!$ isDebuggerUsed ) {
174188 if (($ serviceContainer ->getSettingsService ()->isGatewayServiceProvided || $ serviceContainer ->getSettingsService ()->isProxyUrlProvided ) && $ payload !== null ) {
175- ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context );
189+ ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context, $ featureKey );
176190 } else {
177191 if ($ payload !== null ) {
178192 $ batchPayload [] = $ payload ;
@@ -216,7 +230,7 @@ public function get(
216230 );
217231
218232 if (($ serviceContainer ->getSettingsService ()->isGatewayServiceProvided || $ serviceContainer ->getSettingsService ()->isProxyUrlProvided ) && $ payload !== null ) {
219- ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context );
233+ ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context, $ featureKey );
220234 } else {
221235 //push this payload to the batch payload
222236 if ($ payload !== null ) {
@@ -257,7 +271,7 @@ public function get(
257271 $ isEnabled = true ;
258272 $ payload = $ evaluateRuleResult ['payload ' ];
259273 if (($ serviceContainer ->getSettingsService ()->isGatewayServiceProvided || $ serviceContainer ->getSettingsService ()->isProxyUrlProvided ) && $ payload !== null ) {
260- ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context );
274+ ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context, $ featureKey );
261275 } else {
262276 if ($ payload !== null ) {
263277 $ batchPayload [] = $ payload ;
@@ -301,7 +315,7 @@ public function get(
301315 );
302316
303317 if (($ serviceContainer ->getSettingsService ()->isGatewayServiceProvided || $ serviceContainer ->getSettingsService ()->isProxyUrlProvided ) && $ payload !== null ) {
304- ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context );
318+ ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context, $ featureKey );
305319 } else {
306320 //push this payload to the batch payload
307321 if ($ payload !== null ) {
@@ -330,6 +344,22 @@ public function get(
330344 $ hooksService ->set ($ decision );
331345 $ hooksService ->execute ($ hooksService ->get ());
332346
347+ // send debug event, if debugger is enabled
348+ if ($ feature ->getIsDebuggerEnabled ()) {
349+
350+ $ debugEventProps ['cg ' ] = DebuggerCategoryEnum::DECISION ;
351+ // debugEventProps.msg_t = Constants.FLAG_DECISION;
352+ $ debugEventProps ['msg_t ' ] = Constants::FLAG_DECISION_GIVEN ;
353+
354+ $ debugEventProps ['lt ' ] = LogLevelEnum::INFO ;
355+
356+ // Update debug event props with decision keys
357+ $ this ->updateDebugEventPropsWithDecisionKeys ($ debugEventProps , $ decision );
358+
359+ // Send debug event
360+ DebuggerServiceUtil::sendDebugEventToVWO ($ debugEventProps );
361+ }
362+
333363 // Send data for Impact Campaign, if defined
334364 if ($ feature ->getImpactCampaign ()->getCampaignId ()) {
335365 $ status = $ isEnabled ? 'enabled ' : 'disabled ' ;
@@ -352,7 +382,7 @@ public function get(
352382 );
353383
354384 if (($ serviceContainer ->getSettingsService ()->isGatewayServiceProvided || $ serviceContainer ->getSettingsService ()->isProxyUrlProvided ) && $ payload !== null ) {
355- ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context );
385+ ImpressionUtil::SendImpressionForVariationShown ($ serviceContainer , $ payload , $ context, $ featureKey );
356386 } else {
357387 //push this payload to the batch payload
358388 if ($ payload !== null ) {
@@ -395,4 +425,30 @@ private function updateIntegrationsDecisionObject(CampaignModel $campaign, Varia
395425
396426 $ decision = array_merge ($ decision , $ passedRulesInformation );
397427 }
428+
429+ /**
430+ * Update debug event props with decision keys.
431+ *
432+ * @param array &$debugEventProps Debug event props (passed by reference)
433+ * @param array $decision Decision array
434+ * @return void
435+ */
436+ private function updateDebugEventPropsWithDecisionKeys (array &$ debugEventProps , array $ decision )
437+ {
438+ $ decisionKeys = DebuggerServiceUtil::extractDecisionKeys ($ decision );
439+ $ message = "Flag decision given for feature: {$ decision ['featureKey ' ]}. " ;
440+
441+ if (isset ($ decision ['rolloutKey ' ]) && isset ($ decision ['rolloutVariationId ' ])) {
442+ $ rolloutKeySuffix = substr ($ decision ['rolloutKey ' ], strlen ($ decision ['featureKey ' ] . '_ ' ));
443+ $ message .= " Got rollout: {$ rolloutKeySuffix } with variation: {$ decision ['rolloutVariationId ' ]}" ;
444+ }
445+
446+ if (isset ($ decision ['experimentKey ' ]) && isset ($ decision ['experimentVariationId ' ])) {
447+ $ experimentKeySuffix = substr ($ decision ['experimentKey ' ], strlen ($ decision ['featureKey ' ] . '_ ' ));
448+ $ message .= " and experiment: {$ experimentKeySuffix } with variation: {$ decision ['experimentVariationId ' ]}" ;
449+ }
450+
451+ $ debugEventProps ['msg ' ] = $ message ;
452+ $ debugEventProps = array_merge ($ debugEventProps , $ decisionKeys );
453+ }
398454}
0 commit comments