Skip to content

Commit c9d06cd

Browse files
[FSSDK-11450] experimentId + variationId to decision notification listener (#381)
1 parent 282b7cf commit c9d06cd

File tree

4 files changed

+63
-49
lines changed

4 files changed

+63
-49
lines changed

.github/workflows/csharp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: Restore dependencies
7676
run: dotnet restore OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj
7777
- name: Build & strongly name assemblies
78-
run: dotnet build OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=D:\a\csharp-sdk\csharp-sdk\keypair.snk -c Release
78+
run: dotnet build OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$(pwd)/keypair.snk -c Release
7979

8080
netStandard20:
8181
name: Build Standard 2.0
@@ -98,7 +98,7 @@ jobs:
9898
- name: Restore dependencies
9999
run: dotnet restore OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj
100100
- name: Build & strongly name assemblies
101-
run: dotnet build OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=D:\a\csharp-sdk\csharp-sdk\keypair.snk -c Release
101+
run: dotnet build OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$(pwd)/keypair.snk -c Release
102102

103103
integration_tests:
104104
name: Run Integration Tests

OptimizelySDK.Tests/OptimizelyTest.cs

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ public void TestDecisionNotificationSentWhenSendFlagDecisionsFalseAndFeature()
339339
{
340340
"decisionEventDispatched", true
341341
},
342+
{
343+
"experimentId", "7718750065"
344+
},
345+
{
346+
"variationId", "7713030086"
347+
}
342348
}))), Times.Once);
343349
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
344350
Times.Once);
@@ -405,6 +411,12 @@ public void TestDecisionNotificationSentWhenSendFlagDecisionsTrueAndFeature()
405411
{
406412
"decisionEventDispatched", true
407413
},
414+
{
415+
"experimentId", "7718750065"
416+
},
417+
{
418+
"variationId", "7713030086"
419+
}
408420
}))), Times.Once);
409421
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
410422
Times.Once);
@@ -476,6 +488,12 @@ public void TestDecisionNotificationNotSentWhenSendFlagDecisionsFalseAndRollout(
476488
{
477489
"decisionEventDispatched", false
478490
},
491+
{
492+
"experimentId", experiment.Id
493+
},
494+
{
495+
"variationId", variation.Id
496+
}
479497
}))), Times.Once);
480498
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
481499
Times.Never);
@@ -547,6 +565,12 @@ public void TestDecisionNotificationSentWhenSendFlagDecisionsTrueAndRollout()
547565
{
548566
"decisionEventDispatched", true
549567
},
568+
{
569+
"experimentId", experiment.Id
570+
},
571+
{
572+
"variationId", variation.Id
573+
}
550574
}))), Times.Once);
551575
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
552576
Times.Once);
@@ -2361,8 +2385,7 @@ public void
23612385
Assert.AreEqual(expectedValue, variableValue);
23622386

23632387
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2364-
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
2365-
}"" of feature flag ""{featureKey}""."));
2388+
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
23662389
}
23672390

23682391
[Test]
@@ -2406,8 +2429,7 @@ public void
24062429
Assert.AreEqual(expectedValue, variableValue);
24072430

24082431
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2409-
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
2410-
}"" of feature flag ""{featureKey}""."));
2432+
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
24112433
}
24122434

24132435
[Test]
@@ -2439,8 +2461,7 @@ public void
24392461
Assert.AreEqual(expectedValue, variableValue);
24402462

24412463
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2442-
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId
2443-
}. Returning the default variable value ""{variableValue}""."));
2464+
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId}. Returning the default variable value ""{variableValue}""."));
24442465
}
24452466

24462467
[Test]
@@ -2484,8 +2505,7 @@ public void
24842505
Assert.AreEqual(expectedValue, variableValue);
24852506

24862507
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2487-
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId
2488-
}. Returning the default variable value ""{variableValue}""."));
2508+
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId}. Returning the default variable value ""{variableValue}""."));
24892509
}
24902510

24912511
[Test]
@@ -2515,8 +2535,7 @@ public void
25152535
Assert.AreEqual(expectedValue, variableValue);
25162536

25172537
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2518-
$@"Got variable value ""true"" for variable ""{variableKey}"" of feature flag ""{
2519-
featureKey}""."));
2538+
$@"Got variable value ""true"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
25202539
}
25212540

25222541
[Test]
@@ -2562,8 +2581,7 @@ public void
25622581
Assert.AreEqual(expectedStringValue, variableValue.GetValue<string>("string_var"));
25632582

25642583
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2565-
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
2566-
}"" of feature flag ""{featureKey}""."));
2584+
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
25672585
}
25682586

25692587
[Test]
@@ -2609,8 +2627,7 @@ public void
26092627
Assert.AreEqual(expectedStringValue, variableValue.GetValue<string>("string_var"));
26102628

26112629
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2612-
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
2613-
}"" of feature flag ""{featureKey}""."));
2630+
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
26142631
}
26152632

26162633
[Test]
@@ -2654,8 +2671,7 @@ public void
26542671
Assert.AreEqual(expectedValue, variableValue);
26552672

26562673
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2657-
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
2658-
}"" of feature flag ""{featureKey}""."));
2674+
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
26592675
}
26602676

26612677
[Test]
@@ -2684,8 +2700,7 @@ public void
26842700
variableKey, TestUserId, null);
26852701
Assert.AreEqual(expectedValue, variableValue);
26862702
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2687-
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId
2688-
}. Returning the default variable value ""true""."));
2703+
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId}. Returning the default variable value ""true""."));
26892704
}
26902705

26912706
[Test]
@@ -2728,8 +2743,7 @@ public void
27282743
Assert.AreEqual(expectedValue, variableValue);
27292744

27302745
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2731-
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId
2732-
}. Returning the default variable value ""{variableValue}""."));
2746+
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId}. Returning the default variable value ""{variableValue}""."));
27332747
}
27342748

27352749
[Test]
@@ -2758,8 +2772,7 @@ public void
27582772
Assert.AreEqual(expectedValue, variableValue);
27592773

27602774
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2761-
$@"User ""{TestUserId}"" is not in any variation for feature flag ""{featureKey
2762-
}"", returning default value ""{variableValue}""."));
2775+
$@"User ""{TestUserId}"" is not in any variation for feature flag ""{featureKey}"", returning default value ""{variableValue}""."));
27632776
}
27642777

27652778
#endregion Feature Toggle Tests
@@ -2822,8 +2835,7 @@ public void TestGetFeatureVariableValueForTypeGivenFeatureKeyOrVariableKeyNotFou
28222835
LoggerMock.Verify(l =>
28232836
l.Log(LogLevel.ERROR, $@"Feature key ""{featureKey}"" is not in datafile."));
28242837
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
2825-
$@"No feature variable was found for key ""{variableKey
2826-
}"" in feature flag ""double_single_variable_feature""."));
2838+
$@"No feature variable was found for key ""{variableKey}"" in feature flag ""double_single_variable_feature""."));
28272839
}
28282840

28292841
// Should return null and log error message when variable type is invalid.
@@ -2851,17 +2863,13 @@ public void TestGetFeatureVariableValueForTypeGivenInvalidVariableType()
28512863
"string_single_variable_feature", "json_var", TestUserId, null, variableTypeInt));
28522864

28532865
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
2854-
$@"Variable is of type ""double"", but you requested it as type ""{variableTypeBool
2855-
}""."));
2866+
$@"Variable is of type ""double"", but you requested it as type ""{variableTypeBool}""."));
28562867
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
2857-
$@"Variable is of type ""boolean"", but you requested it as type ""{
2858-
variableTypeDouble}""."));
2868+
$@"Variable is of type ""boolean"", but you requested it as type ""{variableTypeDouble}""."));
28592869
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
2860-
$@"Variable is of type ""integer"", but you requested it as type ""{
2861-
variableTypeString}""."));
2870+
$@"Variable is of type ""integer"", but you requested it as type ""{variableTypeString}""."));
28622871
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
2863-
$@"Variable is of type ""string"", but you requested it as type ""{variableTypeInt
2864-
}""."));
2872+
$@"Variable is of type ""string"", but you requested it as type ""{variableTypeInt}""."));
28652873
}
28662874

28672875
[Test]
@@ -2913,8 +2921,7 @@ public void TestGetFeatureVariableValueForTypeGivenFeatureFlagIsNotEnabledForUse
29132921
Assert.AreEqual(expectedValue, variableValue);
29142922

29152923
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2916-
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId
2917-
}. Returning the default variable value ""{variableValue}""."));
2924+
$@"Feature ""{featureKey}"" is not enabled for user {TestUserId}. Returning the default variable value ""{variableValue}""."));
29182925
}
29192926

29202927
// Should return default value and log message when feature is enabled for the user
@@ -2954,9 +2961,7 @@ public void
29542961
Assert.AreEqual(expectedValue, variableValue);
29552962

29562963
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2957-
$@"Variable ""{variableKey
2958-
}"" is not used in variation ""control"", returning default value ""{expectedValue
2959-
}""."));
2964+
$@"Variable ""{variableKey}"" is not used in variation ""control"", returning default value ""{expectedValue}""."));
29602965
}
29612966

29622967
// Should return variable value from variation and log message when feature is enabled for the user
@@ -2994,8 +2999,7 @@ public void
29942999
Assert.AreEqual(expectedValue, variableValue);
29953000

29963001
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
2997-
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
2998-
}"" of feature flag ""{featureKey}""."));
3002+
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
29993003
}
30003004

30013005
// Verify that GetFeatureVariableValueForType returns correct variable value for rollout rule.
@@ -3149,8 +3153,7 @@ public void TestIsFeatureEnabledGivenFeatureFlagIsEnabledAndUserIsNotBeingExperi
31493153

31503154
// SendImpressionEvent() does not get called.
31513155
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
3152-
$@"The user ""{TestUserId}"" is not being experimented on feature ""{featureKey
3153-
}""."), Times.Once);
3156+
$@"The user ""{TestUserId}"" is not being experimented on feature ""{featureKey}""."), Times.Once);
31543157

31553158
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
31563159
$@"Feature flag ""{featureKey}"" is enabled for user ""{TestUserId}""."));
@@ -3183,8 +3186,7 @@ public void TestIsFeatureEnabledGivenFeatureFlagIsEnabledAndUserIsBeingExperimen
31833186

31843187
// SendImpressionEvent() gets called.
31853188
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
3186-
$@"The user ""{TestUserId}"" is not being experimented on feature ""{featureKey
3187-
}""."), Times.Never);
3189+
$@"The user ""{TestUserId}"" is not being experimented on feature ""{featureKey}""."), Times.Never);
31883190

31893191
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
31903192
$@"Feature flag ""{featureKey}"" is enabled for user ""{TestUserId}""."));
@@ -3218,8 +3220,7 @@ public void TestIsFeatureEnabledGivenFeatureFlagIsNotEnabledAndUserIsBeingExperi
32183220

32193221
// SendImpressionEvent() gets called.
32203222
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
3221-
$@"The user ""{TestUserId}"" is not being experimented on feature ""{featureKey
3222-
}""."), Times.Never);
3223+
$@"The user ""{TestUserId}"" is not being experimented on feature ""{featureKey}""."), Times.Never);
32233224

32243225
LoggerMock.Verify(l => l.Log(LogLevel.INFO,
32253226
$@"Feature flag ""{featureKey}"" is not enabled for user ""{TestUserId}""."));

OptimizelySDK.Tests/OptimizelyUserContextTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,12 @@ public void TestDecisionNotification()
10811081
{
10821082
"decisionEventDispatched", true
10831083
},
1084+
{
1085+
"experimentId", "122235"
1086+
},
1087+
{
1088+
"variationId", "122236"
1089+
},
10841090
};
10851091

10861092
var userAttributes = new UserAttributes

OptimizelySDK/Optimizely.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,21 @@ ProjectConfig projectConfig
10001000
)
10011001
{
10021002
var userId = user.GetUserId();
1003-
1003+
string experimentId = null;
1004+
string variationId = null;
10041005
var flagEnabled = false;
10051006
if (flagDecision.Variation != null)
10061007
{
10071008
if (flagDecision.Variation.IsFeatureEnabled)
10081009
{
10091010
flagEnabled = true;
10101011
}
1012+
variationId = flagDecision.Variation.Id;
1013+
}
1014+
if (flagDecision.Experiment != null)
1015+
{
1016+
experimentId = flagDecision.Experiment.Id;
10111017
}
1012-
10131018
Logger.Log(LogLevel.INFO,
10141019
$"Feature \"{flagKey}\" is enabled for user \"{userId}\"? {flagEnabled}");
10151020

@@ -1062,6 +1067,8 @@ ProjectConfig projectConfig
10621067
{ "ruleKey", ruleKey },
10631068
{ "reasons", reasonsToReport },
10641069
{ "decisionEventDispatched", decisionEventDispatched },
1070+
{ "experimentId", experimentId },
1071+
{ "variationId", variationId },
10651072
};
10661073

10671074
NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Decision,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy