Skip to content

Commit e5c6cc4

Browse files
committed
feat: Always inline contexts for feature events (#119)
1 parent b391fb0 commit e5c6cc4

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/ldclient_event_process_server.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ maybe_set_reason(_Event, OutputEvent) ->
228228
OutputEvent.
229229

230230
-spec format_event_set_context(binary(), ldclient_context:context(), map(), ldclient_config:private_attributes()) -> map().
231-
format_event_set_context(<<"feature">>, Context, OutputEvent, _) ->
232-
OutputEvent#{<<"contextKeys">> => ldclient_context:get_keys_and_kinds(Context)};
231+
format_event_set_context(<<"feature">>, Context, OutputEvent, GlobalPrivateAttributes) ->
232+
OutputEvent#{
233+
<<"context">> => ldclient_context_filter:format_context_for_event(GlobalPrivateAttributes, Context)
234+
};
233235
format_event_set_context(<<"debug">>, Context, OutputEvent, GlobalPrivateAttributes) ->
234236
OutputEvent#{
235237
<<"context">> => ldclient_context_filter:format_context_for_event(GlobalPrivateAttributes, Context)

test-service/src/ts_service_request_handler.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ get_service_detail(Req, State) ->
7373
<<"all-flags-with-reasons">>,
7474
<<"tags">>,
7575
<<"server-side-polling">>,
76-
<<"user-type">>
76+
<<"user-type">>,
77+
<<"inline-context">>
7778
],
7879
<<"clientVersion">> => ldclient_config:get_version()
7980
}),

test/ldclient_events_SUITE.erl

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,13 @@ add_flag_eval_events_flush_with_track(_) ->
342342
<<"variation">> := 5,
343343
<<"version">> := 5,
344344
<<"creationDate">> := _,
345-
<<"contextKeys">> := #{<<"user">> := <<"12345-track">>}
345+
<<"context">> :=
346+
#{
347+
<<"firstName">> := <<"Tester">>,
348+
<<"key">> := <<"12345-track">>,
349+
<<"kind">> := <<"user">>,
350+
<<"lastName">> := <<"Testerson">>
351+
}
346352
}
347353
] = ActualEvents.
348354

@@ -397,7 +403,13 @@ add_flag_eval_events_flush_with_track_no_reasons(_) ->
397403
<<"variation">> := 5,
398404
<<"version">> := 5,
399405
<<"creationDate">> := _,
400-
<<"contextKeys">> := #{<<"user">> := <<"12345-track-no-reasons">>}
406+
<<"context">> :=
407+
#{
408+
<<"firstName">> := <<"Tester">>,
409+
<<"key">> := <<"12345-track-no-reasons">>,
410+
<<"kind">> := <<"user">>,
411+
<<"lastName">> := <<"Testerson">>
412+
}
401413
}
402414
] = ActualEvents.
403415

@@ -453,7 +465,13 @@ add_flag_eval_events_flush_with_track_experimentation_rule(_) ->
453465
<<"variation">> := 5,
454466
<<"version">> := 5,
455467
<<"creationDate">> := _,
456-
<<"contextKeys">> := #{<<"user">> := <<"12345-track-experimentation-rule">>}
468+
<<"context">> :=
469+
#{
470+
<<"firstName">> := <<"Tester">>,
471+
<<"key">> := <<"12345-track-experimentation-rule">>,
472+
<<"kind">> := <<"user">>,
473+
<<"lastName">> := <<"Testerson">>
474+
}
457475
}
458476
] = ActualEvents.
459477

@@ -509,7 +527,13 @@ add_flag_eval_events_flush_with_track_experimentation_fallthrough(_) ->
509527
<<"variation">> := 5,
510528
<<"version">> := 5,
511529
<<"creationDate">> := _,
512-
<<"contextKeys">> := #{<<"user">> := <<"12345-track-experimentation-fallthrough">>}
530+
<<"context">> :=
531+
#{
532+
<<"firstName">> := <<"Tester">>,
533+
<<"key">> := <<"12345-track-experimentation-fallthrough">>,
534+
<<"kind">> := <<"user">>,
535+
<<"lastName">> := <<"Testerson">>
536+
}
513537
}
514538
] = ActualEvents.
515539

@@ -917,7 +941,7 @@ add_flag_eval_events_flush_in_experiment_fallthrough(_) ->
917941
<<"key">> := <<"abc">>,
918942
<<"default">> := <<"default-value">>,
919943
<<"reason">> := #{<<"kind">> := <<"FALLTHROUGH">>, <<"inExperiment">> := true},
920-
<<"contextKeys">> := #{<<"user">> := <<"experiment-fallthrough">>},
944+
<<"context">> := #{<<"key">> := <<"experiment-fallthrough">>, <<"kind">> := <<"user">>},
921945
<<"value">> := <<"a">>,
922946
<<"variation">> := 0,
923947
<<"version">> := 5,
@@ -967,7 +991,7 @@ add_flag_eval_events_flush_in_experiment_rule_match(_) ->
967991
<<"key">> := <<"abc">>,
968992
<<"default">> := <<"default-value">>,
969993
<<"reason">> := #{<<"kind">> := <<"RULE_MATCH">>, <<"ruleIndex">> := 0, <<"ruleId">> := <<"id">>, <<"inExperiment">> := true},
970-
<<"contextKeys">> := #{<<"user">> := <<"experiment-rule">>},
994+
<<"context">> := #{<<"key">> := <<"experiment-rule">>, <<"kind">> := <<"user">>},
971995
<<"value">> := <<"a">>,
972996
<<"variation">> := 0,
973997
<<"version">> := 5,

0 commit comments

Comments
 (0)