Skip to content

Commit

Permalink
feat: Inline contexts for all evaluation events (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Mar 8, 2024
1 parent a343458 commit 0275892
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions contract-tests/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'event-sampling',
'context-comparison',
'polling-gzip',
'inline-context',
],
}.to_json
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def make_output_events(events, summary)
out[:variation] = event.variation unless event.variation.nil?
out[:version] = event.version unless event.version.nil?
out[:prereqOf] = event.prereq_of unless event.prereq_of.nil?
out[:contextKeys] = event.context.keys
out[:context] = @context_filter.filter(event.context)
out[:reason] = event.reason unless event.reason.nil?
out

Expand Down
20 changes: 11 additions & 9 deletions spec/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(default_config, context)),
eq(feature_event(flag, context, 1, 'value')),
eq(feature_event(default_config, flag, context, 1, 'value')),
include(:kind => "summary")
)
end
Expand Down Expand Up @@ -69,7 +69,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(default_config, context)),
eq(feature_event(flag, context, 1, 'value'))
eq(feature_event(default_config, flag, context, 1, 'value'))
)
end
end
Expand All @@ -83,7 +83,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(config, context)),
eq(feature_event(flag, context, 1, 'value')),
eq(feature_event(config, flag, context, 1, 'value')),
include(:kind => "summary")
)
end
Expand All @@ -98,7 +98,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(config, context)),
eq(feature_event(flag, context, 1, 'value')),
eq(feature_event(config, flag, context, 1, 'value')),
include(:kind => "summary")
)
end
Expand Down Expand Up @@ -142,7 +142,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(default_config, context)),
eq(feature_event(flag, context, 1, 'value')),
eq(feature_event(default_config, flag, context, 1, 'value')),
eq(debug_event(default_config, flag, context, 1, 'value')),
include(:kind => "summary")
)
Expand Down Expand Up @@ -207,8 +207,8 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(default_config, context)),
eq(feature_event(flag1, context, 1, 'value', starting_timestamp)),
eq(feature_event(flag2, context, 1, 'value', starting_timestamp + 1)),
eq(feature_event(default_config, flag1, context, 1, 'value', starting_timestamp)),
eq(feature_event(default_config, flag2, context, 1, 'value', starting_timestamp + 1)),
include(:kind => "summary")
)
end
Expand Down Expand Up @@ -624,18 +624,20 @@ def identify_event(config, context, timestamp = starting_timestamp)
end

#
# @param config [Config]
# @param flag [Hash]
# @param context [LDContext]
# @param variation [Integer]
# @param value [any]
# @param timestamp [Integer]
# @return [Hash]
#
def feature_event(flag, context, variation, value, timestamp = starting_timestamp)
def feature_event(config, flag, context, variation, value, timestamp = starting_timestamp)
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
out = {
kind: 'feature',
creationDate: timestamp,
contextKeys: context.keys,
context: context_filter.filter(context),
key: flag[:key],
variation: variation,
version: flag[:version],
Expand Down

0 comments on commit 0275892

Please sign in to comment.