-
Notifications
You must be signed in to change notification settings - Fork 20
[FSSDK-9533] Log error & reject on track event with null, empty or whitespace event key #362
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
Changes from all commits
7a2fd20
aa6e213
7a6cbb3
0251e5a
0a265c9
dcbedf4
1ab6c55
0b6f70a
9bf7230
2597098
a2b8d54
aad09e1
609973e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
using OptimizelySDK.OptlyConfig; | ||
using OptimizelySDK.OptimizelyDecisions; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
#if USE_ODP | ||
using OptimizelySDK.Odp; | ||
|
@@ -87,7 +88,7 @@ public static String SDK_VERSION | |
{ | ||
get | ||
{ | ||
// Example output: "2.1.0" . Should be kept in synch with NuGet package version. | ||
// Example output: "2.1.0". Should be kept in sync with NuGet package version. | ||
#if NET35 || NET40 | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
#else | ||
|
@@ -338,54 +339,60 @@ private bool ValidateInputs(string datafile, bool skipJsonValidation) | |
/// <summary> | ||
/// Sends conversion event to Optimizely. | ||
/// </summary> | ||
/// <param name="eventKey">Event key representing the event which needs to be recorded</param> | ||
/// <param name="eventKey">Event key representing the event (must not be null, empty, or whitespace)</param> | ||
/// <param name="userId">ID for user</param> | ||
/// <param name="userAttributes">Attributes of the user</param> | ||
/// <param name="eventTags">eventTags array Hash representing metadata associated with the event.</param> | ||
public void Track(string eventKey, string userId, UserAttributes userAttributes = null, | ||
EventTags eventTags = null | ||
) | ||
{ | ||
var config = ProjectConfigManager?.GetConfig(); | ||
|
||
if (config == null) | ||
Comment on lines
-349
to
-351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we remove this config ready check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going to call |
||
if (eventKey == null || Regex.IsMatch(eventKey, @"^\s*$")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an earlier eventKey check since it's cheaper before digging into the ProjectConfig to see if the eventKey is present in the datafile since it's required per the docs. |
||
{ | ||
Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'Track'."); | ||
Logger.Log(LogLevel.ERROR, | ||
"Event key cannot be null, empty, or whitespace string. Failing 'Track'."); | ||
return; | ||
} | ||
|
||
var inputValues = new Dictionary<string, string> | ||
{ { USER_ID, userId }, { EVENT_KEY, eventKey } }; | ||
{ | ||
{ USER_ID, userId }, | ||
{ EVENT_KEY, eventKey }, | ||
}; | ||
|
||
if (!ValidateStringInputs(inputValues)) | ||
{ | ||
return; | ||
} | ||
|
||
var eevent = config.GetEvent(eventKey); | ||
|
||
if (eevent.Key == null) | ||
Comment on lines
-365
to
-367
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these 2 lines will filter out null or empty eventKey cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I see what you're talking about: The eventKey must be in the datafile before it can be tracked anyway, regardless of whether it's not null, empty, or whitespace. |
||
var config = ProjectConfigManager?.GetConfig(); | ||
if (config == null) | ||
{ | ||
Logger.Log(LogLevel.INFO, | ||
string.Format("Not tracking user {0} for event {1}.", userId, eventKey)); | ||
Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'Track'."); | ||
return; | ||
} | ||
|
||
if (eventTags != null) | ||
var eventToTrack = config.GetEvent(eventKey); | ||
if (eventToTrack.Key == null) | ||
{ | ||
eventTags = eventTags.FilterNullValues(Logger); | ||
Logger.Log(LogLevel.INFO, $"Not tracking user {userId} for event {eventKey}."); | ||
return; | ||
} | ||
|
||
eventTags = eventTags?.FilterNullValues(Logger); | ||
|
||
var userEvent = UserEventFactory.CreateConversionEvent(config, eventKey, userId, | ||
userAttributes, eventTags); | ||
|
||
EventProcessor.Process(userEvent); | ||
Logger.Log(LogLevel.INFO, | ||
string.Format("Tracking event {0} for user {1}.", eventKey, userId)); | ||
|
||
Logger.Log(LogLevel.INFO, $"Tracking event {eventKey} for user {userId}."); | ||
|
||
if (NotificationCenter.GetNotificationCount(NotificationCenter.NotificationType.Track) > | ||
0) | ||
{ | ||
var conversionEvent = EventFactory.CreateLogEvent(userEvent, Logger); | ||
|
||
NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Track, | ||
eventKey, userId, | ||
userAttributes, eventTags, conversionEvent); | ||
|
@@ -1347,7 +1354,8 @@ List<OdpSegmentOption> segmentOptions | |
|
||
if (config == null) | ||
{ | ||
Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'FetchQualifiedSegments'."); | ||
Logger.Log(LogLevel.ERROR, | ||
"Datafile has invalid format. Failing 'FetchQualifiedSegments'."); | ||
return null; | ||
} | ||
|
||
|
@@ -1378,7 +1386,8 @@ internal void IdentifyUser(string userId) | |
/// <param name="identifiers">Dictionary for identifiers. The caller must provide at least one key-value pair.</param> | ||
/// <param name="type">Type of event (defaults to `fullstack`)</param> | ||
/// <param name="data">Optional event data in a key-value pair format</param> | ||
public void SendOdpEvent(string action, Dictionary<string, string> identifiers, string type = Constants.ODP_EVENT_TYPE, | ||
public void SendOdpEvent(string action, Dictionary<string, string> identifiers, string type | ||
= Constants.ODP_EVENT_TYPE, | ||
Dictionary<string, object> data = null | ||
) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should read: "Event key representing the event in the datafile which must not be null, empty, or whitespace"