Skip to content

Commit 8b5429b

Browse files
committed
feat: Inline contexts for all evaluation events (#245)
1 parent c7b42a2 commit 8b5429b

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

contract-tests/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def status():
7171
'tags',
7272
'migrations',
7373
'event-sampling',
74-
'polling-gzip'
74+
'polling-gzip',
75+
'inline-context'
7576
]
7677
}
7778
return (json.dumps(body), 200, {'Content-type': 'application/json'})

ldclient/impl/events/event_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def make_output_events(self, events: List[Any], summary: EventSummary):
6565
def make_output_event(self, e: Any):
6666
if isinstance(e, EventInputEvaluation):
6767
out = self._base_eval_props(e, 'feature')
68-
out['contextKeys'] = self._context_keys(e.context)
68+
out['context'] = self._process_context(e.context)
6969
return out
7070
elif isinstance(e, DebugEvent):
7171
out = self._base_eval_props(e.original_input, 'debug')

testing/impl/events/test_event_processor.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ldclient.migrations.tracker import MigrationOpEvent
1616
from ldclient.impl.events.types import EventInput, EventInputCustom, EventInputEvaluation, EventInputIdentify
1717
from ldclient.impl.util import timedelta_millis
18+
from ldclient.impl.events.event_context_formatter import EventContextFormatter
1819

1920
from testing.builders import *
2021
from testing.proxy_test_util import do_proxy_tests
@@ -23,12 +24,6 @@
2324

2425
default_config = Config("fake_sdk_key")
2526
context = Context.builder('userkey').name('Red').build()
26-
filtered_context = context.to_dict() # TODO: implement attribute redaction
27-
filtered_context = {
28-
'kind': 'user',
29-
'key': 'userkey',
30-
'_meta': {'redactedAttributes': ['name']}
31-
}
3227
flag = FlagBuilder('flagkey').version(2).build()
3328
flag_with_0_sampling_ratio = FlagBuilder('flagkey').version(3).sampling_ratio(0).build()
3429
flag_excluded_from_summaries = FlagBuilder('flagkey').version(4).exclude_from_summaries(True).build()
@@ -233,12 +228,13 @@ def test_identify_event_is_queued():
233228

234229
def test_context_is_filtered_in_identify_event():
235230
with DefaultTestProcessor(all_attributes_private = True) as ep:
231+
formatter = EventContextFormatter(True, [])
236232
e = EventInputIdentify(timestamp, context)
237233
ep.send_event(e)
238234

239235
output = flush_and_get_events(ep)
240236
assert len(output) == 1
241-
check_identify_event(output[0], e, filtered_context)
237+
check_identify_event(output[0], e, formatter.format_context(context))
242238

243239
def test_individual_feature_event_is_queued_with_index_event():
244240
with DefaultTestProcessor() as ep:
@@ -275,13 +271,14 @@ def test_exclude_can_keep_feature_event_from_summary():
275271

276272
def test_context_is_filtered_in_index_event():
277273
with DefaultTestProcessor(all_attributes_private = True) as ep:
274+
formatter = EventContextFormatter(True, [])
278275
e = EventInputEvaluation(timestamp, context, flag.key, flag, 1, 'value', None, 'default', None, True)
279276
ep.send_event(e)
280277

281278
output = flush_and_get_events(ep)
282279
assert len(output) == 3
283-
check_index_event(output[0], e, filtered_context)
284-
check_feature_event(output[1], e)
280+
check_index_event(output[0], e, formatter.format_context(context))
281+
check_feature_event(output[1], e, formatter.format_context(context))
285282
check_summary_event(output[2])
286283

287284
def test_two_events_for_same_context_only_produce_one_index_event():
@@ -682,15 +679,15 @@ def check_index_event(data, source: EventInput, context_json: Optional[dict] = N
682679
assert data['creationDate'] == source.timestamp
683680
assert data['context'] == (source.context.to_dict() if context_json is None else context_json)
684681

685-
def check_feature_event(data, source: EventInputEvaluation):
682+
def check_feature_event(data, source: EventInputEvaluation, context_json: Optional[dict] = None):
686683
assert data['kind'] == 'feature'
687684
assert data['creationDate'] == source.timestamp
688685
assert data['key'] == source.key
689686
assert data.get('version') == None if source.flag is None else source.flag.version
690687
assert data.get('variation') == source.variation
691688
assert data.get('value') == source.value
692689
assert data.get('default') == source.default_value
693-
assert data['contextKeys'] == make_context_keys(source.context)
690+
assert data['context'] == (source.context.to_dict() if context_json is None else context_json)
694691
assert data.get('prereq_of') == None if source.prereq_of is None else source.prereq_of.key
695692

696693

0 commit comments

Comments
 (0)