Skip to content

feat: Inline contexts for all evaluation events #245

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 1 commit into from
Jan 16, 2024
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
1 change: 1 addition & 0 deletions contract-tests/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'migrations',
'event-sampling',
'context-comparison',
'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