Skip to content

Commit 8c38b23

Browse files
MichaelGHSegclaude
andcommitted
Align e2e-cli types with sdk-e2e-tests definitions
Add missing field extraction: timestamp, category, context, integrations. Wire timestamp, messageId, context, and integrations through to the Java SDK MessageBuilder for full fidelity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3d4dd86 commit 8c38b23

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

e2e-cli/src/main/kotlin/cli/Main.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import com.google.gson.reflect.TypeToken
55
import com.segment.analytics.Analytics
66
import com.segment.analytics.Callback
77
import com.segment.analytics.messages.*
8+
import java.text.SimpleDateFormat
9+
import java.util.Date
10+
import java.util.Locale
11+
import java.util.TimeZone
812
import java.util.concurrent.CountDownLatch
913
import java.util.concurrent.TimeUnit
1014
import java.util.concurrent.atomic.AtomicBoolean
@@ -107,14 +111,20 @@ fun sendEvent(analytics: Analytics, event: Map<String, Any>) {
107111
val userId = event["userId"] as? String ?: ""
108112
val anonymousId = event["anonymousId"] as? String
109113
val messageId = event["messageId"] as? String
114+
val timestamp = event["timestamp"] as? String
110115
@Suppress("UNCHECKED_CAST")
111116
val traits = event["traits"] as? Map<String, Any> ?: emptyMap()
112117
@Suppress("UNCHECKED_CAST")
113118
val properties = event["properties"] as? Map<String, Any> ?: emptyMap()
114119
val eventName = event["event"] as? String
115120
val name = event["name"] as? String
121+
val category = event["category"] as? String
116122
val groupId = event["groupId"] as? String
117123
val previousId = event["previousId"] as? String
124+
@Suppress("UNCHECKED_CAST")
125+
val context = event["context"] as? Map<String, Any>
126+
@Suppress("UNCHECKED_CAST")
127+
val integrations = event["integrations"] as? Map<String, Any>
118128

119129
val messageBuilder: MessageBuilder<*, *> = when (type) {
120130
"identify" -> {
@@ -154,6 +164,37 @@ fun sendEvent(analytics: Analytics, event: Map<String, Any>) {
154164
if (anonymousId != null) {
155165
messageBuilder.anonymousId(anonymousId)
156166
}
167+
if (messageId != null) {
168+
messageBuilder.messageId(messageId)
169+
}
170+
if (timestamp != null) {
171+
messageBuilder.timestamp(parseTimestamp(timestamp))
172+
}
173+
if (context != null) {
174+
messageBuilder.context(context)
175+
}
176+
if (integrations != null) {
177+
for ((key, value) in integrations) {
178+
when (value) {
179+
is Boolean -> messageBuilder.enableIntegration(key, value)
180+
is Map<*, *> -> @Suppress("UNCHECKED_CAST")
181+
messageBuilder.integrationOptions(key, value as Map<String, Any>)
182+
}
183+
}
184+
}
157185

158186
analytics.enqueue(messageBuilder)
159187
}
188+
189+
private fun parseTimestamp(iso: String): Date {
190+
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)
191+
format.timeZone = TimeZone.getTimeZone("UTC")
192+
return try {
193+
format.parse(iso)!!
194+
} catch (_: Exception) {
195+
// Fallback: try without millis
196+
val fallback = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US)
197+
fallback.timeZone = TimeZone.getTimeZone("UTC")
198+
fallback.parse(iso)!!
199+
}
200+
}

0 commit comments

Comments
 (0)