From 7d9894a982977ba9f06fe9e9735a3aecd40ed370 Mon Sep 17 00:00:00 2001 From: drkjc Date: Wed, 11 Nov 2026 17:12:58 -0500 Subject: [PATCH 1/3] fix: leave eventTime unset until event() sends it --- CHANGELOG.md | 1 + .../com/spreedly/composer/api/ApiEvent.java | 1 - .../composer/api/ComposerServices.java | 9 ++-- .../composer/ComposerIntegrationTest.java | 45 +++++++++++++++++++ .../com/spreedly/composer/api/ApiTest.java | 3 +- 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f32004..3ac56ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ First release as `com.spreedly:composer-sdk-server`. If you're upgrading from `c - `CheckpointResponseOptions.timeout` is an `Integer` and `sync` is a `Boolean`. A new `CheckpointRequest` has `options` `null`. - `checkpoint()` throws `ComposerMissingParameterException` (an `IllegalArgumentException`) before returning the future when the request, `checkpointName`, `event`, or both `sessionId` and `sourceToken` are missing. Blank strings count as missing. This happens even when the SDK is disabled. - `event.ip` is optional on checkpoints. +- When `eventTime` is `null`, `event()` sends the current time. It doesn't set `eventTime` on your `ApiEvent`. - `event()` doesn't throw for invalid input or failed requests. It logs the problem and returns a response with `success` `false`. - `sync` defaults to `false` and is sent as given. With `sync` `true`, the first request waits for the workflow to finish, so set `setRequestTimeoutMs` longer than your slowest workflow. - `timeout` is now only how long the SDK polls, and defaults to 10 minutes. It's no longer sent to the API. diff --git a/src/main/java/com/spreedly/composer/api/ApiEvent.java b/src/main/java/com/spreedly/composer/api/ApiEvent.java index 70b0687..aa9fd3f 100644 --- a/src/main/java/com/spreedly/composer/api/ApiEvent.java +++ b/src/main/java/com/spreedly/composer/api/ApiEvent.java @@ -37,7 +37,6 @@ public ApiEvent() { public ApiEvent(String type, Map data) { this.type = type; this.data = data; - this.eventTime = System.currentTimeMillis(); } /** diff --git a/src/main/java/com/spreedly/composer/api/ComposerServices.java b/src/main/java/com/spreedly/composer/api/ComposerServices.java index f7bfa8d..1b6a5ed 100644 --- a/src/main/java/com/spreedly/composer/api/ComposerServices.java +++ b/src/main/java/com/spreedly/composer/api/ComposerServices.java @@ -340,13 +340,14 @@ public NotificationResponse call() { OkHttpClient client = buildClient(requestTimeoutMs); try { - // Ensure event has timestamp - if (request.event != null && request.event.eventTime == null) { - request.event.eventTime = System.currentTimeMillis(); + // Default the timestamp on a copy, so a reused event gets a fresh time on each call + ApiEvent event = request.event; + if (event != null && event.eventTime == null) { + event = new ApiEvent(event.type, event.data, System.currentTimeMillis()); } // Prepare request body - String jsonBody = gson.toJson(request.event); + String jsonBody = gson.toJson(event); RequestBody body = RequestBody.create(jsonBody, JSON); // Build request diff --git a/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java b/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java index 26da965..9caee0d 100644 --- a/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java +++ b/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java @@ -1238,6 +1238,51 @@ public void testEvent_withNullTimestamp() throws Exception { assertThat(recordedRequest.getBody().readUtf8()).contains("eventTime"); } + @Test + public void testEvent_reusedEventGetsFreshDefaultTime() throws Exception { + NotificationResponse mockResponse = new NotificationResponse(true, new ComposerApiError[]{}); + mockServer.enqueue(new MockResponse() + .setBody(gson.toJson(mockResponse)) + .addHeader("Content-Type", "application/json")); + mockServer.enqueue(new MockResponse() + .setBody(gson.toJson(mockResponse)) + .addHeader("Content-Type", "application/json")); + + ApiEvent event = new ApiEvent("TEST_EVENT", new HashMap<>()); + NotificationRequest request = new NotificationRequest(); + request.event = event; + request.sessionId = "sess-123"; + + composer.event(request).get(5, TimeUnit.SECONDS); + Thread.sleep(5); + composer.event(request).get(5, TimeUnit.SECONDS); + + long firstTime = gson.fromJson(mockServer.takeRequest().getBody().readUtf8(), com.google.gson.JsonObject.class) + .get("eventTime").getAsLong(); + long secondTime = gson.fromJson(mockServer.takeRequest().getBody().readUtf8(), com.google.gson.JsonObject.class) + .get("eventTime").getAsLong(); + assertThat(secondTime).isGreaterThan(firstTime); + assertThat(event.eventTime).isNull(); + } + + @Test + public void testEvent_keepsCallerEventTime() throws Exception { + NotificationResponse mockResponse = new NotificationResponse(true, new ComposerApiError[]{}); + mockServer.enqueue(new MockResponse() + .setBody(gson.toJson(mockResponse)) + .addHeader("Content-Type", "application/json")); + + NotificationRequest request = new NotificationRequest(); + request.event = new ApiEvent("TEST_EVENT", new HashMap<>(), 1700000000000L); + request.sessionId = "sess-123"; + + composer.event(request).get(5, TimeUnit.SECONDS); + + long sentTime = gson.fromJson(mockServer.takeRequest().getBody().readUtf8(), com.google.gson.JsonObject.class) + .get("eventTime").getAsLong(); + assertThat(sentTime).isEqualTo(1700000000000L); + } + @Test public void testEvent_nullEvent() throws Exception { Composer errorLoggingComposer = Composer.builder() diff --git a/src/test/java/com/spreedly/composer/api/ApiTest.java b/src/test/java/com/spreedly/composer/api/ApiTest.java index 9aa7ac0..f5b844f 100644 --- a/src/test/java/com/spreedly/composer/api/ApiTest.java +++ b/src/test/java/com/spreedly/composer/api/ApiTest.java @@ -73,8 +73,7 @@ public void testApiEvent_constructorWithTypeAndData() { assertThat(event.type).isEqualTo("TEST_EVENT"); assertThat(event.data).isEqualTo(data); - assertThat(event.eventTime).isNotNull(); - assertThat(event.eventTime).isGreaterThan(0L); + assertThat(event.eventTime).isNull(); } @Test From e8a6bc07dedb48fae20651a5af1d459e203c154c Mon Sep 17 00:00:00 2001 From: drkjc Date: Thu, 12 Nov 2026 11:45:13 -0500 Subject: [PATCH 2/3] fix: send only type, data and eventTime from event() --- CHANGELOG.md | 1 + .../composer/api/ComposerServices.java | 9 ++++--- .../composer/ComposerIntegrationTest.java | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ac56ca..38b377f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ First release as `com.spreedly:composer-sdk-server`. If you're upgrading from `c - `checkpoint()` throws `ComposerMissingParameterException` (an `IllegalArgumentException`) before returning the future when the request, `checkpointName`, `event`, or both `sessionId` and `sourceToken` are missing. Blank strings count as missing. This happens even when the SDK is disabled. - `event.ip` is optional on checkpoints. - When `eventTime` is `null`, `event()` sends the current time. It doesn't set `eventTime` on your `ApiEvent`. +- `event()` sends only `type`, `data` and `eventTime`. Fields you add in an `ApiEvent` subclass aren't sent; put custom values in `data`. - `event()` doesn't throw for invalid input or failed requests. It logs the problem and returns a response with `success` `false`. - `sync` defaults to `false` and is sent as given. With `sync` `true`, the first request waits for the workflow to finish, so set `setRequestTimeoutMs` longer than your slowest workflow. - `timeout` is now only how long the SDK polls, and defaults to 10 minutes. It's no longer sent to the API. diff --git a/src/main/java/com/spreedly/composer/api/ComposerServices.java b/src/main/java/com/spreedly/composer/api/ComposerServices.java index 1b6a5ed..31c3185 100644 --- a/src/main/java/com/spreedly/composer/api/ComposerServices.java +++ b/src/main/java/com/spreedly/composer/api/ComposerServices.java @@ -340,10 +340,13 @@ public NotificationResponse call() { OkHttpClient client = buildClient(requestTimeoutMs); try { - // Default the timestamp on a copy, so a reused event gets a fresh time on each call + // Send a copy with only the fields the track endpoint takes. Gson would otherwise + // serialize a subclass's extra fields, and defaulting the time on the copy gives a + // reused event a fresh time on each call. ApiEvent event = request.event; - if (event != null && event.eventTime == null) { - event = new ApiEvent(event.type, event.data, System.currentTimeMillis()); + if (event != null) { + Long eventTime = event.eventTime != null ? event.eventTime : System.currentTimeMillis(); + event = new ApiEvent(event.type, event.data, eventTime); } // Prepare request body diff --git a/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java b/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java index 9caee0d..4b91e04 100644 --- a/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java +++ b/src/test/java/com/spreedly/composer/ComposerIntegrationTest.java @@ -1283,6 +1283,33 @@ public void testEvent_keepsCallerEventTime() throws Exception { assertThat(sentTime).isEqualTo(1700000000000L); } + static class EventWithExtraField extends ApiEvent { + public String region = "us-east"; + + EventWithExtraField(Long eventTime) { + super("TEST_EVENT", new HashMap<>(), eventTime); + } + } + + @Test + public void testEvent_sendsOnlyTrackFields() throws Exception { + NotificationResponse mockResponse = new NotificationResponse(true, new ComposerApiError[]{}); + for (Long eventTime : new Long[]{1700000000000L, null}) { + mockServer.enqueue(new MockResponse() + .setBody(gson.toJson(mockResponse)) + .addHeader("Content-Type", "application/json")); + + NotificationRequest request = new NotificationRequest(); + request.event = new EventWithExtraField(eventTime); + request.sessionId = "sess-123"; + + composer.event(request).get(5, TimeUnit.SECONDS); + + com.google.gson.JsonObject body = gson.fromJson(mockServer.takeRequest().getBody().readUtf8(), com.google.gson.JsonObject.class); + assertThat(body.keySet()).containsExactlyInAnyOrder("type", "data", "eventTime"); + } + } + @Test public void testEvent_nullEvent() throws Exception { Composer errorLoggingComposer = Composer.builder() From c98241213ed9d86b3ad78d36e8d8034813b2552a Mon Sep 17 00:00:00 2001 From: drkjc Date: Fri, 13 Nov 2026 14:30:52 -0500 Subject: [PATCH 3/3] docs: note that eventTime is a Long --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b377f..3195aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ First release as `com.spreedly:composer-sdk-server`. If you're upgrading from `c - `CheckpointResponseOptions.timeout` is an `Integer` and `sync` is a `Boolean`. A new `CheckpointRequest` has `options` `null`. - `checkpoint()` throws `ComposerMissingParameterException` (an `IllegalArgumentException`) before returning the future when the request, `checkpointName`, `event`, or both `sessionId` and `sourceToken` are missing. Blank strings count as missing. This happens even when the SDK is disabled. - `event.ip` is optional on checkpoints. +- `ApiEvent.eventTime` is a `Long` (milliseconds since the Unix epoch) instead of a `Date`. - When `eventTime` is `null`, `event()` sends the current time. It doesn't set `eventTime` on your `ApiEvent`. - `event()` sends only `type`, `data` and `eventTime`. Fields you add in an `ApiEvent` subclass aren't sent; put custom values in `data`. - `event()` doesn't throw for invalid input or failed requests. It logs the problem and returns a response with `success` `false`.