Skip to content

Commit 5119679

Browse files
authored
Fix Session Event printout for sampling, log_environment (#10790)
1 parent 729eb40 commit 5119679

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

FirebaseSessions/Sources/Development/NanoPB+CustomStringConvertible.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ extension firebase_appquality_sessions_OsName: CustomStringConvertible {
8686
}
8787
}
8888

89+
extension firebase_appquality_sessions_LogEnvironment: CustomStringConvertible {
90+
public var description: String {
91+
switch self {
92+
case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_PROD:
93+
return "PROD"
94+
case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_STAGING:
95+
return "STAGING"
96+
case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_AUTOPUSH:
97+
return "AUTOPUSH"
98+
case firebase_appquality_sessions_LogEnvironment_LOG_ENVIRONMENT_UNKNOWN:
99+
return "UNKNOWN"
100+
default:
101+
return "Unrecognized LogEnvironment. Please update the firebase_appquality_sessions_LogEnvironment CustomStringConvertible extension"
102+
}
103+
}
104+
}
105+
89106
extension UnsafeMutablePointer<pb_bytes_array_t>: CustomStringConvertible {
90107
public var description: String {
91108
let decoded = FIRSESDecodeString(self)

FirebaseSessions/Sources/FirebaseSessions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ private enum GoogleDataTransportConfig {
181181
self.settings.updateSettings()
182182

183183
self.addSubscriberFields(event: event)
184+
event.setSamplingRate(samplingRate: self.settings.samplingRate)
184185

185186
guard sessionInfo.shouldDispatchEvents else {
186187
loggedEventCallback(.failure(.SessionSamplingError))

FirebaseSessions/Tests/Unit/FirebaseSessionsTests+DataCollection.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,26 @@ final class FirebaseSessionsTestsBase_DataCollection: FirebaseSessionsTestsBase
158158
}
159159
)
160160
}
161+
162+
func test_defaultSamplingRate_isSetInProto() {
163+
runSessionsSDK(
164+
subscriberSDKs: [
165+
mockCrashlyticsSubscriber,
166+
167+
], preSessionsInit: { _ in
168+
// Nothing
169+
}, postSessionsInit: {
170+
sessions.register(subscriber: self.mockCrashlyticsSubscriber)
171+
// Nothing
172+
173+
}, postLogEvent: { result, subscriberSDKs in
174+
// Make sure we set the sampling rate in the proto
175+
XCTAssertEqual(
176+
self.mockCoordinator.loggedEvent?.proto.session_data.data_collection_status
177+
.session_sampling_rate,
178+
1.0
179+
)
180+
}
181+
)
182+
}
161183
}

0 commit comments

Comments
 (0)