Skip to content

feat: android sdk (kotlin) for the events collector - #17

Open
yuvrajjsingh0 wants to merge 1 commit into
sudoquery-monorepo-implfrom
feat/android-sdk
Open

yuvrajjsingh0 wants to merge 1 commit into
sudoquery-monorepo-implfrom
feat/android-sdk

Conversation

@yuvrajjsingh0

Copy link
Copy Markdown
Contributor

Adds clients/android, the Kotlin counterpart of clients/typescript, published as io.juspay:sudoquery-android. It is a standalone Gradle build, outside the Cargo workspace.

SudoQuery.init(this, SudoQueryConfig.Builder(orgId, projectId, "https://…/v1/events/batch").build())
SudoQuery.track("button_click", mapOf("button_id" to "submit"))

What's in it

  • API mirroring the TS client: init, track (Map or JSONObject), setUser / removeUser / getUser, super properties and flush, plus reset() for logout. Every method is static for Java, thread-safe, and never throws into the host app.
  • One-line event type swap: sudoquery/src/main/kotlin/io/juspay/sudoquery/Event.kt holds every wire type. EventV1 matches CollectorEvent field for field and in the same key order, nulls included. typealias CanonicalEvent = EventV1 is the one line that picks the event class. Batching, storage and upload only handle serialized events, so switching envelopes is that line plus the new class.
  • Ported from hyper-sdk-android's experimental log pipeline: one NDJSON file per batch, committed by atomic rename, a directory scan on startup, plus age and size limits. Bugs fixed along the way:
    • Any 2xx counts as sent.
    • 400/413/422 drop the batch instead of blocking the queue forever.
    • Other failures back off exponentially (5 s up to 5 min, honours Retry-After).
    • The size cap no longer wipes the whole queue.
    • Files are ordered by sequence number, so a clock change can't reorder them.
    • Storage is in noBackupFilesDir, not cacheDir.
    • Network IO never blocks event writes.
  • Sessions and identity: anon_id, the user id and the session persist across restarts. A session ends after 30 min without events. Delivery is at least once, and a resend is byte-identical with the same event ids.
  • Consumer compatibility: minSdk 21, compileSdk 34+, Kotlin 2.0+. The only runtime dependencies are coroutines, kotlinx.serialization and lifecycle-process.
  • Sample app: clients/android/sample, a minified release build used for end-to-end checks.
  • CI:
    • android-client.yml runs tests, lint, the minified sample build and publishToMavenLocal on changes to clients/android.
    • release-android.yml publishes to Maven Central on android-v* tags. release.yml only matches v*, so npm releases are unaffected.

Verification

  • Unit tests: 64 JVM and Robolectric tests, covering the golden wire format, the type swap, the queue, upload policy and backoff, identity, and the facade.
  • Local collector: the golden batch gets HTTP 200, and the opt-in LiveCollectorTest sends through the full pipeline.
  • Emulator, minified release build: events reached Kafka and the OpenSearch data stream with correct anon_id, user and session handling across setUser and reset.
  • Collector stopped, then app force-stopped: queued events were recovered and delivered on relaunch, with their original timestamps.
  • Non-slug project id: the collector's 400 is logged and the batch dropped.

Before the first release

  • Maven Central: verify the io.juspay namespace (DNS TXT on juspay.io), then add the secrets MAVEN_CENTRAL_USERNAME, MAVEN_CENTRAL_PASSWORD, SIGNING_KEY and SIGNING_KEY_PASSWORD.
  • License: the POM says ISC, matching clients/typescript/package.json, but the repo has no LICENSE file. Please confirm.

AGP is pinned to 9.1.1 so Android Studio Panda 3 can open the project.

🤖 Generated with Claude Code

Adds clients/android, the Kotlin counterpart of clients/typescript, published
as io.juspay:sudoquery-android. Apps call SudoQuery.init/track/setUser/flush;
events are persisted to disk, batched and posted to /v1/events/batch.

- Event.kt holds every wire type; `typealias CanonicalEvent = EventV1` is the
  one line that picks the event class the SDK sends.
- Batching, on-disk queue and upload are ported from hyper-sdk-android's
  experimental log pipeline, with its bugs fixed: any 2xx counts as sent,
  400/413/422 are dropped instead of blocking the queue, other failures back
  off exponentially, and the size cap no longer wipes the whole queue.
- CI runs tests, lint and the minified sample on changes to clients/android;
  tags android-v* publish to Maven Central.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant