Skip to content

[FSSDK-11450] experimentId + variationId to decision notification listener #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Restore dependencies
run: dotnet restore OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj
- name: Build & strongly name assemblies
run: dotnet build OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=D:\a\csharp-sdk\csharp-sdk\keypair.snk -c Release
run: dotnet build OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$(pwd)/keypair.snk -c Release

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

integration_tests:
name: Run Integration Tests
Expand Down
91 changes: 46 additions & 45 deletions OptimizelySDK.Tests/OptimizelyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ public void TestDecisionNotificationSentWhenSendFlagDecisionsFalseAndFeature()
{
"decisionEventDispatched", true
},
{
"experimentId", "7718750065"
},
{
"variationId", "7713030086"
}
}))), Times.Once);
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
Times.Once);
Expand Down Expand Up @@ -405,6 +411,12 @@ public void TestDecisionNotificationSentWhenSendFlagDecisionsTrueAndFeature()
{
"decisionEventDispatched", true
},
{
"experimentId", "7718750065"
},
{
"variationId", "7713030086"
}
}))), Times.Once);
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
Times.Once);
Expand Down Expand Up @@ -476,6 +488,12 @@ public void TestDecisionNotificationNotSentWhenSendFlagDecisionsFalseAndRollout(
{
"decisionEventDispatched", false
},
{
"experimentId", experiment.Id
},
{
"variationId", variation.Id
}
}))), Times.Once);
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
Times.Never);
Expand Down Expand Up @@ -547,6 +565,12 @@ public void TestDecisionNotificationSentWhenSendFlagDecisionsTrueAndRollout()
{
"decisionEventDispatched", true
},
{
"experimentId", experiment.Id
},
{
"variationId", variation.Id
}
}))), Times.Once);
EventDispatcherMock.Verify(dispatcher => dispatcher.DispatchEvent(It.IsAny<LogEvent>()),
Times.Once);
Expand Down Expand Up @@ -2361,8 +2385,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
}"" of feature flag ""{featureKey}""."));
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

[Test]
Expand Down Expand Up @@ -2406,8 +2429,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
}"" of feature flag ""{featureKey}""."));
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

[Test]
Expand Down Expand Up @@ -2439,8 +2461,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

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

[Test]
Expand Down Expand Up @@ -2484,8 +2505,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

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

[Test]
Expand Down Expand Up @@ -2515,8 +2535,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""true"" for variable ""{variableKey}"" of feature flag ""{
featureKey}""."));
$@"Got variable value ""true"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

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

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
}"" of feature flag ""{featureKey}""."));
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

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

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
}"" of feature flag ""{featureKey}""."));
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

[Test]
Expand Down Expand Up @@ -2654,8 +2671,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
}"" of feature flag ""{featureKey}""."));
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

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

[Test]
Expand Down Expand Up @@ -2728,8 +2743,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

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

[Test]
Expand Down Expand Up @@ -2758,8 +2772,7 @@ public void
Assert.AreEqual(expectedValue, variableValue);

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

#endregion Feature Toggle Tests
Expand Down Expand Up @@ -2822,8 +2835,7 @@ public void TestGetFeatureVariableValueForTypeGivenFeatureKeyOrVariableKeyNotFou
LoggerMock.Verify(l =>
l.Log(LogLevel.ERROR, $@"Feature key ""{featureKey}"" is not in datafile."));
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
$@"No feature variable was found for key ""{variableKey
}"" in feature flag ""double_single_variable_feature""."));
$@"No feature variable was found for key ""{variableKey}"" in feature flag ""double_single_variable_feature""."));
}

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

LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
$@"Variable is of type ""double"", but you requested it as type ""{variableTypeBool
}""."));
$@"Variable is of type ""double"", but you requested it as type ""{variableTypeBool}""."));
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
$@"Variable is of type ""boolean"", but you requested it as type ""{
variableTypeDouble}""."));
$@"Variable is of type ""boolean"", but you requested it as type ""{variableTypeDouble}""."));
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
$@"Variable is of type ""integer"", but you requested it as type ""{
variableTypeString}""."));
$@"Variable is of type ""integer"", but you requested it as type ""{variableTypeString}""."));
LoggerMock.Verify(l => l.Log(LogLevel.ERROR,
$@"Variable is of type ""string"", but you requested it as type ""{variableTypeInt
}""."));
$@"Variable is of type ""string"", but you requested it as type ""{variableTypeInt}""."));
}

[Test]
Expand Down Expand Up @@ -2913,8 +2921,7 @@ public void TestGetFeatureVariableValueForTypeGivenFeatureFlagIsNotEnabledForUse
Assert.AreEqual(expectedValue, variableValue);

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

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

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Variable ""{variableKey
}"" is not used in variation ""control"", returning default value ""{expectedValue
}""."));
$@"Variable ""{variableKey}"" is not used in variation ""control"", returning default value ""{expectedValue}""."));
}

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

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Got variable value ""{variableValue}"" for variable ""{variableKey
}"" of feature flag ""{featureKey}""."));
$@"Got variable value ""{variableValue}"" for variable ""{variableKey}"" of feature flag ""{featureKey}""."));
}

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

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

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

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

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

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

LoggerMock.Verify(l => l.Log(LogLevel.INFO,
$@"Feature flag ""{featureKey}"" is not enabled for user ""{TestUserId}""."));
Expand Down
6 changes: 6 additions & 0 deletions OptimizelySDK.Tests/OptimizelyUserContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,12 @@ public void TestDecisionNotification()
{
"decisionEventDispatched", true
},
{
"experimentId", "122235"
},
{
"variationId", "122236"
},
};

var userAttributes = new UserAttributes
Expand Down
11 changes: 9 additions & 2 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
try
{
#if USE_ODP
InitializeComponents(eventDispatcher, logger, errorHandler, userProfileService,

Check warning on line 144 in OptimizelySDK/Optimizely.cs

View workflow job for this annotation

GitHub Actions / Build Standard 2.0

'Optimizely.InitializeComponents(IEventDispatcher, ILogger, IErrorHandler, UserProfileService, NotificationCenter, EventProcessor, OptimizelyDecideOption[], IOdpManager)' is obsolete

Check warning on line 144 in OptimizelySDK/Optimizely.cs

View workflow job for this annotation

GitHub Actions / Build Standard 2.0

'Optimizely.InitializeComponents(IEventDispatcher, ILogger, IErrorHandler, UserProfileService, NotificationCenter, EventProcessor, OptimizelyDecideOption[], IOdpManager)' is obsolete
null, eventProcessor, defaultDecideOptions, odpManager);
#else
InitializeComponents(eventDispatcher, logger, errorHandler, userProfileService,
Expand Down Expand Up @@ -209,7 +209,7 @@
ProjectConfigManager = configManager;

#if USE_ODP
InitializeComponents(eventDispatcher, logger, errorHandler, userProfileService,

Check warning on line 212 in OptimizelySDK/Optimizely.cs

View workflow job for this annotation

GitHub Actions / Build Standard 2.0

'Optimizely.InitializeComponents(IEventDispatcher, ILogger, IErrorHandler, UserProfileService, NotificationCenter, EventProcessor, OptimizelyDecideOption[], IOdpManager)' is obsolete

Check warning on line 212 in OptimizelySDK/Optimizely.cs

View workflow job for this annotation

GitHub Actions / Build Standard 2.0

'Optimizely.InitializeComponents(IEventDispatcher, ILogger, IErrorHandler, UserProfileService, NotificationCenter, EventProcessor, OptimizelyDecideOption[], IOdpManager)' is obsolete
notificationCenter, eventProcessor, defaultDecideOptions, odpManager);

var projectConfig = ProjectConfigManager.CachedProjectConfig;
Expand Down Expand Up @@ -1000,16 +1000,21 @@
)
{
var userId = user.GetUserId();

string experimentId = null;
string variationId = null;
var flagEnabled = false;
if (flagDecision.Variation != null)
{
if (flagDecision.Variation.IsFeatureEnabled)
{
flagEnabled = true;
}
variationId = flagDecision.Variation.Id;
}
if (flagDecision.Experiment != null)
{
experimentId = flagDecision.Experiment.Id;
}

Logger.Log(LogLevel.INFO,
$"Feature \"{flagKey}\" is enabled for user \"{userId}\"? {flagEnabled}");

Expand Down Expand Up @@ -1062,6 +1067,8 @@
{ "ruleKey", ruleKey },
{ "reasons", reasonsToReport },
{ "decisionEventDispatched", decisionEventDispatched },
{ "experimentId", experimentId },
{ "variationId", variationId },
};

NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Decision,
Expand Down
Loading