Skip to content

Commit 31fb5a3

Browse files
authored
feat: Inline contexts for all evaluation events (#245)
1 parent 42ccae5 commit 31fb5a3

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

contract-tests/service.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'migrations',
3737
'event-sampling',
3838
'context-comparison',
39+
'inline-context',
3940
],
4041
}.to_json
4142
end

lib/ldclient-rb/events.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def make_output_events(events, summary)
485485
out[:variation] = event.variation unless event.variation.nil?
486486
out[:version] = event.version unless event.version.nil?
487487
out[:prereqOf] = event.prereq_of unless event.prereq_of.nil?
488-
out[:contextKeys] = event.context.keys
488+
out[:context] = @context_filter.filter(event.context)
489489
out[:reason] = event.reason unless event.reason.nil?
490490
out
491491

spec/events_spec.rb

+11-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module LaunchDarkly
4141
output = flush_and_get_events(ep, sender)
4242
expect(output).to contain_exactly(
4343
eq(index_event(default_config, context)),
44-
eq(feature_event(flag, context, 1, 'value')),
44+
eq(feature_event(default_config, flag, context, 1, 'value')),
4545
include(:kind => "summary")
4646
)
4747
end
@@ -69,7 +69,7 @@ module LaunchDarkly
6969
output = flush_and_get_events(ep, sender)
7070
expect(output).to contain_exactly(
7171
eq(index_event(default_config, context)),
72-
eq(feature_event(flag, context, 1, 'value'))
72+
eq(feature_event(default_config, flag, context, 1, 'value'))
7373
)
7474
end
7575
end
@@ -83,7 +83,7 @@ module LaunchDarkly
8383
output = flush_and_get_events(ep, sender)
8484
expect(output).to contain_exactly(
8585
eq(index_event(config, context)),
86-
eq(feature_event(flag, context, 1, 'value')),
86+
eq(feature_event(config, flag, context, 1, 'value')),
8787
include(:kind => "summary")
8888
)
8989
end
@@ -98,7 +98,7 @@ module LaunchDarkly
9898
output = flush_and_get_events(ep, sender)
9999
expect(output).to contain_exactly(
100100
eq(index_event(config, context)),
101-
eq(feature_event(flag, context, 1, 'value')),
101+
eq(feature_event(config, flag, context, 1, 'value')),
102102
include(:kind => "summary")
103103
)
104104
end
@@ -142,7 +142,7 @@ module LaunchDarkly
142142
output = flush_and_get_events(ep, sender)
143143
expect(output).to contain_exactly(
144144
eq(index_event(default_config, context)),
145-
eq(feature_event(flag, context, 1, 'value')),
145+
eq(feature_event(default_config, flag, context, 1, 'value')),
146146
eq(debug_event(default_config, flag, context, 1, 'value')),
147147
include(:kind => "summary")
148148
)
@@ -207,8 +207,8 @@ module LaunchDarkly
207207
output = flush_and_get_events(ep, sender)
208208
expect(output).to contain_exactly(
209209
eq(index_event(default_config, context)),
210-
eq(feature_event(flag1, context, 1, 'value', starting_timestamp)),
211-
eq(feature_event(flag2, context, 1, 'value', starting_timestamp + 1)),
210+
eq(feature_event(default_config, flag1, context, 1, 'value', starting_timestamp)),
211+
eq(feature_event(default_config, flag2, context, 1, 'value', starting_timestamp + 1)),
212212
include(:kind => "summary")
213213
)
214214
end
@@ -624,18 +624,20 @@ def identify_event(config, context, timestamp = starting_timestamp)
624624
end
625625

626626
#
627+
# @param config [Config]
627628
# @param flag [Hash]
628629
# @param context [LDContext]
629630
# @param variation [Integer]
630631
# @param value [any]
631632
# @param timestamp [Integer]
632633
# @return [Hash]
633634
#
634-
def feature_event(flag, context, variation, value, timestamp = starting_timestamp)
635+
def feature_event(config, flag, context, variation, value, timestamp = starting_timestamp)
636+
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
635637
out = {
636638
kind: 'feature',
637639
creationDate: timestamp,
638-
contextKeys: context.keys,
640+
context: context_filter.filter(context),
639641
key: flag[:key],
640642
variation: variation,
641643
version: flag[:version],

0 commit comments

Comments
 (0)