Skip to content

Commit 578186c

Browse files
Update Custom and MigrationOp events to write full context instead of context keys
Co-Authored-By: [email protected] <[email protected]>
1 parent 3597e39 commit 578186c

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

lib/sdk/server/contract-tests/service/src/main/java/sdktest/TestService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class TestService {
3535
"filtering",
3636
"migrations",
3737
"event-sampling",
38-
"inline-context",
38+
"inline-context-all",
3939
"anonymous-redaction",
4040
"evaluation-hooks",
4141
"client-prereq-events"

lib/shared/internal/src/main/java/com/launchdarkly/sdk/internal/events/EventOutputFormatter.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private boolean writeOutputEvent(Event event, JsonWriter jw) throws IOException
8989
jw.beginObject();
9090
writeKindAndCreationDate(jw, "custom", event.getCreationDate());
9191
jw.name("key").value(ce.getKey());
92-
writeContextKeys(ce.getContext(), jw);
92+
writeContext(ce.getContext(), jw, false);
9393
writeLDValue("data", ce.getData(), jw);
9494
if (ce.getMetricValue() != null) {
9595
jw.name("metricValue");
@@ -104,7 +104,7 @@ private boolean writeOutputEvent(Event event, JsonWriter jw) throws IOException
104104
} else if (event instanceof Event.MigrationOp) {
105105
jw.beginObject();
106106
writeKindAndCreationDate(jw, "migration_op", event.getCreationDate());
107-
writeContextKeys(event.getContext(), jw);
107+
writeContext(event.getContext(), jw, false);
108108

109109
Event.MigrationOp me = (Event.MigrationOp)event;
110110
jw.name("operation").value(me.getOperation());
@@ -296,17 +296,6 @@ private void writeContext(LDContext context, JsonWriter jw, boolean redactAnonym
296296
contextFormatter.write(context, jw, redactAnonymous);
297297
}
298298

299-
private void writeContextKeys(LDContext context, JsonWriter jw) throws IOException {
300-
jw.name("contextKeys").beginObject();
301-
for (int i = 0; i < context.getIndividualContextCount(); i++) {
302-
LDContext c = context.getIndividualContext(i);
303-
if (c != null) {
304-
jw.name(c.getKind().toString()).value(c.getKey());
305-
}
306-
}
307-
jw.endObject();
308-
}
309-
310299
private void writeLDValue(String key, LDValue value, JsonWriter jw) throws IOException {
311300
if (value == null || value.isNull()) {
312301
return;

lib/shared/internal/src/test/java/com/launchdarkly/sdk/internal/events/EventOutputTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ public void identifyEventIsSerialized() throws IOException {
265265
@Test
266266
public void customEventIsSerialized() throws IOException {
267267
LDContext context = LDContext.builder("userkey").name("me").build();
268-
LDValue contextKeysJson = LDValue.buildObject().put("user", context.getKey()).build();
268+
LDValue contextJson = LDValue.buildObject().put("kind", "user").put("key", "userkey").put("name", "me").build();
269269
EventOutputFormatter f = new EventOutputFormatter(defaultEventsConfig());
270270

271271
Event.Custom ceWithoutData = customEvent(context, "customkey").build();
272272
LDValue ceJson1 = parseValue("{" +
273273
"\"kind\":\"custom\"," +
274274
"\"creationDate\":100000," +
275275
"\"key\":\"customkey\"," +
276-
"\"contextKeys\":" + contextKeysJson +
276+
"\"context\":" + contextJson +
277277
"}");
278278
assertJsonEquals(ceJson1, getSingleOutputEvent(f, ceWithoutData));
279279

@@ -282,7 +282,7 @@ public void customEventIsSerialized() throws IOException {
282282
"\"kind\":\"custom\"," +
283283
"\"creationDate\":100000," +
284284
"\"key\":\"customkey\"," +
285-
"\"contextKeys\":" + contextKeysJson + "," +
285+
"\"context\":" + contextJson + "," +
286286
"\"data\":\"thing\"" +
287287
"}");
288288
assertJsonEquals(ceJson2, getSingleOutputEvent(f, ceWithData));
@@ -292,7 +292,7 @@ public void customEventIsSerialized() throws IOException {
292292
"\"kind\":\"custom\"," +
293293
"\"creationDate\":100000," +
294294
"\"key\":\"customkey\"," +
295-
"\"contextKeys\":" + contextKeysJson + "," +
295+
"\"context\":" + contextJson + "," +
296296
"\"metricValue\":2.5" +
297297
"}");
298298
assertJsonEquals(ceJson3, getSingleOutputEvent(f, ceWithMetric));
@@ -303,7 +303,7 @@ public void customEventIsSerialized() throws IOException {
303303
"\"kind\":\"custom\"," +
304304
"\"creationDate\":100000," +
305305
"\"key\":\"customkey\"," +
306-
"\"contextKeys\":" + contextKeysJson + "," +
306+
"\"context\":" + contextJson + "," +
307307
"\"data\":\"thing\"," +
308308
"\"metricValue\":2.5" +
309309
"}");
@@ -408,8 +408,10 @@ public void migrationOpEventIsSerialized() throws IOException {
408408
.put("reason", LDValue.buildObject()
409409
.put("kind", "FALLTHROUGH")
410410
.build()).build())
411-
.put("contextKeys", LDValue.buildObject()
412-
.put("user", "user-key")
411+
.put("context", LDValue.buildObject()
412+
.put("kind", "user")
413+
.put("key", "user-key")
414+
.put("name", "me")
413415
.build())
414416
.put("samplingRatio", 2)
415417
.put("measurements", LDValue.buildArray()
@@ -495,8 +497,10 @@ public void migrationOpEventSerializationCanExcludeOptionalItems() throws IOExce
495497
.put("reason", LDValue.buildObject()
496498
.put("kind", "FALLTHROUGH")
497499
.build()).build())
498-
.put("contextKeys", LDValue.buildObject()
499-
.put("user", "user-key")
500+
.put("context", LDValue.buildObject()
501+
.put("kind", "user")
502+
.put("key", "user-key")
503+
.put("name", "me")
500504
.build())
501505
.put("measurements", LDValue.buildArray()
502506
.add(LDValue.buildObject()

0 commit comments

Comments
 (0)