Repository navigation
feat: ios sdk (swift package) for the events collector - #18
Open
yuvrajjsingh0 wants to merge 3 commits into
Open
yuvrajjsingh0 wants to merge 3 commits into
yuvrajjsingh0 wants to merge 3 commits into
Conversation
Adds clients/ios, the Swift counterpart of clients/android and clients/typescript: a Swift package for iOS 13+ with an Objective-C wrapper. Apps call SudoQuery.initialize/track/setUser/flush; events are persisted to disk, batched and posted to /v1/events/batch. - Event.swift holds every wire type; `typealias CanonicalEvent = EventV1` is the one line that picks the event type the SDK sends. The bytes match the Android golden files apart from `"source":"ios"`. - The network, batching and file layers are ported from hyper-sdk-ios (HPJPLogPusher, HPJPLogsManager, Airborne's AJPNetworkClient and AJPFileUtil), with its bugs fixed: a transport error is no longer turned into an empty URLResponse(), any 2xx counts as sent, 400/413/422 drop the batch, other failures back off exponentially instead of deleting the batch, a batch is visible to the uploader only once fully written, and the queue has size and age limits. - GCD and locks only, so iOS 13-14 apps need no Swift Concurrency runtime. Going to the background flushes inside a background task, and an identity that can't be read before the first unlock is never overwritten. - CI runs the tests on macOS and on an iOS simulator and builds the sample, whose Objective-C file compile-checks the generated header. SwiftPM publishing isn't set up yet; apps add clients/ios as a local package.
The config option, the Objective-C initializer and property, the blank-id error code (still code 2) and the sample's build setting now say workspaceId, the name the dashboard's switcher copies the id as. The collector still reads x-project-id and each event's project_id, so the SDK keeps sending the id under those names and the wire format is unchanged; the golden files didn't change.
The header is now x-workspace-id, and the event field workspace_id takes project_id's place, right after org_id. The org id still goes out as x-org-id and org_id. The collector still requires x-project-id and project_id and answers 400 without them, which the SDK treats as final and drops the batch, so the collector has to accept the new names before this ships.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
clients/ios, the Swift counterpart ofclients/android(#17) andclients/typescript: a Swift package for iOS 13+ with an Objective-C wrapper. It is a standalone SwiftPM package, outside the Cargo workspace.What's in it
initialize,track,setUser/removeUser/user, super properties,flushandreset(). Every method is thread-safe and never throws or traps in the host app. Objective-C apps useSQSudoQuery/SQSudoQueryConfig, and an invalid config comes back as anNSError. The project id isworkspaceId, as the dashboard's switcher calls it, and it goes out asx-workspace-idandworkspace_id.clients/ios/Sources/SudoQuery/Event.swiftholds every wire type.EventV1matchesCollectorEventfield for field and in the same key order, nulls included, except that it hasworkspace_idwhere the collector hasproject_id. Its bytes match the Android golden files apart from"workspace_id":"ios-demo1"(Android:"project_id":"android-demo1") and"source":"ios".typealias CanonicalEvent = EventV1is the one line that picks the event type.HPJPLogPusher,HPJPLogsManager, Airborne'sAJPNetworkClientandAJPFileUtil): one NDJSON file per batch, committed by atomic rename and replayed on launch, and one sharedURLSession. Bugs fixed along the way:URLResponse(), whichHPJPLogPusherthen read as an HTTP response (a likely crash when offline).Retry-After), instead of deleting it or retrying back to back.DispatchSourcetimers instead ofNSTimers that pause while the user scrolls.completeUntilFirstUserAuthentication, instead of the backed-upLibrary/.clients/ios/Sample, SwiftUI with the Android sample's buttons. ItsObjCSmokeTest.mcalls every Objective-C method, so building the sample checks the generated header.ios-client.ymlruns the tests on macOS and on an iOS simulator, checks the SDK has no trapping calls (try!,as!,fatalError,precondition) and no Swift Concurrency symbols, and builds the sample. There is no release workflow yet.Verification
x-workspace-id/workspace_id: the opt-inLiveCollectorTestspassed from macOS and from the simulator. Events reached Kafka withsource: "ios", the user id, the time zone and the server-side IP.headerscrash on non-string values;Before publishing
x-workspace-idandworkspace_id, but the collector still requiresx-project-idandproject_id. It answers 400 without them, and the SDK drops a batch that gets a 400, so the collector has to accept the new names before this ships.Package.swiftonly at a repository root, and thev*tags here belong to npm. Publishing needs either a mirror repo fed bygit subtree split --prefix=clients/ios, or a root manifest with tags that don't collide. Until then, apps addclients/iosas a local package.