Skip to content

feat: default session id #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class UnleashClientBase {
self.metrics = Metrics(appName: appName, metricsInterval: Double(metricsInterval), clock: { return Date() }, disableMetrics: disableMetrics, poster: urlSessionPoster, url: url, clientKey: clientKey, customHeaders: customHeaders, connectionId: connectionId)
}

self.context = Context(appName: appName, environment: environment)
self.context = Context(appName: appName, environment: environment, sessionId: String(Int.random(in: 0..<1_000_000_000)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ is calculateContext overriding the sessionId with the providedContext session id (if present)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

if let providedContext = context {
self.context = self.calculateContext(context: providedContext)
}
Expand Down Expand Up @@ -192,12 +192,14 @@ public class UnleashClientBase {
properties?.forEach { (key, value) in
newProperties[key] = value
}

let sessionId = context["sessionId"] ?? self.context.sessionId;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gastonfournier here's the override if present


let newContext = Context(
appName: self.context.appName,
environment: self.context.environment,
userId: context["userId"],
sessionId: context["sessionId"],
sessionId: sessionId,
remoteAddress: context["remoteAddress"],
properties: newProperties
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/UnleashProxyClientSwift/Version/Version.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public struct LibraryInfo {
public static let version = "2.1.0" // Update this string with each new release
public static let version = "2.2.0" // Update this string with each new release
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UnleashIntegrationTests: XCTestCase {
clientKey: "SDKIntegration:development.f0474f4a37e60794ee8fb00a4c112de58befde962af6d5055b383ea3",
refreshInterval: 15,
appName: "testIntegration",
context: ["clientId": "disabled"]
context: ["clientId": "disabled", "sessionId": "1234"]
)
}

Expand All @@ -23,7 +23,7 @@ class UnleashIntegrationTests: XCTestCase {
func testUserJourneyHappyPath() {
let expectation = self.expectation(description: "Waiting for client updates")

XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration"])
XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration", "sessionId": "1234"])

unleashClient.subscribe(name: "ready", callback: {
XCTAssertFalse(self.unleashClient.isEnabled(name: self.featureName), "Feature should be disabled")
Expand Down Expand Up @@ -59,7 +59,7 @@ class UnleashIntegrationTests: XCTestCase {
func testUserJourneyHappyPathWithUnleashEvent() {
let expectation = self.expectation(description: "Waiting for client updates")

XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration"])
XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration", "sessionId": "1234"])

unleashClient.subscribe(.ready) {
XCTAssertFalse(self.unleashClient.isEnabled(name: self.featureName), "Feature should be disabled")
Expand Down