Skip to content

Commit 092880c

Browse files
authored
Rebase (#10660)
1 parent 1bd9913 commit 092880c

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

FirebaseSessions/README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ Follow the [Main Firebase Readme](https://github.com/firebase/firebase-ios-sdk#d
66
## Development
77
### Generating the Project and Test Project
88

9-
- `generate_project.sh` uses [cocoapods-generate](https://github.com/square/cocoapods-generate) to create an Xcode Workspace that has the SDK installed for all the SDK's supported platforms. This is useful for test-based development.
9+
- Test-based Development:
10+
- **Option 1:** `generate_project.sh` uses [cocoapods-generate](https://github.com/square/cocoapods-generate) to create an Xcode Workspace that has the SDK installed for all the SDK's supported platforms. This is useful for test-based development.
11+
- **Option 2:** `open Package.swift` in the root of the firebase-ios-sdk repo. You can run tests using the `FirebaseSessionsUnit` Scheme
1012
- `generate_testapp.sh` generates and opens a test app with the Sessions SDK included. This is useful for developing the Sessions SDK against a real app.
1113

12-
### Switching dev environments - Autopush/Staging/Prod
14+
### Debugging Options
1315

16+
#### Switching Dev Environments - Autopush/Staging/Prod
1417
SDK is configured to send events to different environments. To enforce different environments for sending events, we use an environment variable to configure the specific environment. Since environment variables are enforced in the context of the App, use the TestApp to send events to different environments after using the following configuration steps.
1518

1619
- Enter "Edit scheme" - On the title bar menu "Product" > "Scheme" > "Edit Scheme"
@@ -23,13 +26,18 @@ SDK is configured to send events to different environments. To enforce different
2326

2427
NOTE: Default is PROD. Not configuring any flags would mean the events are sent to PROD environment.
2528

26-
### Debugging
27-
28-
### Command Line Arguments
29+
#### Debugging Events
2930
You can access command line parameters by following: Press `CMD-Shift-,` => Run => Arguments.
3031

3132
- `-FIRSessionsDebugEvents` will print Session Start events to the console for debugging purposes.
3233

34+
#### Overriding Settings
35+
You can override the Settings values fetched from the server using the app's Info.plist. The full list of override plist keys can be found in `LocalOverrideSettings.swift`.
36+
37+
- **FirebaseSessionsEnabled**: Bool representing whether to make any network calls
38+
- **FirebaseSessionsTimeout**: Float number of seconds representing the time that an app must be backgrounded before generating a new session
39+
- **FirebaseSessionsSampingRate**: Float between 0 and 1 representing how often events are sent. 0 is drop everything, 1 is send everything.
40+
3341
### Updating the Proto
3442
#### Prerequesites
3543
To update the Sessions Proto, Protobuf is required. To install run:
@@ -42,3 +50,11 @@ brew install protobuf
4250
1. Follow the directions in `sessions.proto` for updating it
4351
1. Run the following to regenerate the nanopb source files: `./FirebaseSessions/ProtoSupport/generate_protos.sh`
4452
1. Update the SDK to use the new proto fields
53+
54+
55+
### Logging
56+
The Sessions SDK uses the following strategy when determining log level:
57+
- **Info** should be used rarely. Because the Sessions SDK is a dependency of other products, customers will not expect regular logs from the SDK. Therefore, info events are not recommended except under circumstances where the code path is blocked by another debug parameter (eg. `-FIRSessionsDebugEvents` will log under info because we don't want to require it be paired with `-FIRDebugEnabled`)
58+
- **Debug** Is recommended to be used generously in the Sessions SDK for the purposes of debugging customer issues.
59+
- **Warning** Is used when the Sessions SDK runs into a recoverable issue that still results in events being sent. For example, a problem converting between values that results in an incorrect value being reported.
60+
- **Error** Is used when the Sessions SDK runs into an unrecoverable issue that prevents functionality from working. If we would want customers to reach out to us when a issue happens, then error logs should be used to convey the issue.

FirebaseSessions/Sources/Development/DevEventConsoleLogger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DevEventConsoleLogger: EventGDTLoggerProtocol {
3333

3434
func prettyPrint(proto: firebase_appquality_sessions_SessionEvent) {
3535
let logOutput = """
36-
Logging Session Event due to \"\(commandLineArgument)\" command line argument
36+
Printing Session Event due to \"\(commandLineArgument)\" command line argument
3737
Session Event:
3838
event_type: \(proto.event_type)
3939
session_data

FirebaseSessions/Sources/FirebaseSessions.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ private enum GoogleDataTransportConfig {
141141
self.subscriberPromises[subscriberName] = Promise<Void>.pending()
142142
}
143143

144-
Logger.logDebug("Expecting subscriptions from: \(SessionsDependencies.dependencies)")
144+
Logger
145+
.logDebug(
146+
"Version \(FirebaseVersion()). Expecting subscriptions from: \(SessionsDependencies.dependencies)"
147+
)
145148

146149
self.initiator.beginListening {
147150
// Generating a Session ID early is important as Subscriber

FirebaseSessions/Sources/SessionCoordinator.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@ class SessionCoordinator: SessionCoordinatorProtocol {
3333
self.fireLogger = fireLogger
3434
}
3535

36-
// Begins the process of logging a SessionStartEvent to FireLog, while taking into account Data Collection, Sampling, and fetching Settings
36+
/// Begins the process of logging a SessionStartEvent to FireLog after
37+
/// it has been approved for sending
3738
func attemptLoggingSessionStart(event: SessionStartEvent,
3839
callback: @escaping (Result<Void, FirebaseSessionsError>)
3940
-> Void) {
4041
/// Order of execution
41-
/// 1. Check if the session can be sent. If yes, move to 2. Else, drop the event.
42-
/// 2. Fetch the installations Id. If successful, move to 3. Else, drop sending the event.
43-
/// 3. Log the event. If successful, all is good. Else, log the message with error.
42+
/// 1. Fetch the installations Id. If successful, move to 3. Else, drop sending the event.
43+
/// 2. Log the event. If successful, all is good. Else, log the message with error.
4444
installations.installationID { result in
4545
switch result {
4646
case let .success(fiid):
4747
event.setInstallationID(installationId: fiid)
4848
self.fireLogger.logEvent(event: event) { logResult in
4949
switch logResult {
5050
case .success():
51+
Logger.logDebug("Successfully logged Session Start event to GoogleDataTransport")
5152
callback(.success(()))
5253
case let .failure(error):
5354
callback(.failure(FirebaseSessionsError.DataTransportError(error)))

FirebaseSessions/Sources/SessionStartEvent.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ class SessionStartEvent: NSObject, GDTCOREventDataObject {
126126
var error: NSError?
127127
let data = FIRSESEncodeProto(&fields.0, &proto, &error)
128128
if error != nil {
129-
Logger.logError(error.debugDescription)
129+
Logger
130+
.logError("Session Event failed to encode as proto with error: \(error.debugDescription)")
130131
}
131132
guard let data = data else {
132-
Logger.logError("Session event generated nil transportBytes. Returning empty data.")
133+
Logger.logError("Session Event generated nil transportBytes. Returning empty data.")
133134
return Data()
134135
}
135136
return data
@@ -193,7 +194,7 @@ class SessionStartEvent: NSObject, GDTCOREventDataObject {
193194
if !pb_decode(&istream, &fields.0, &proto) {
194195
let errorMessage = FIRSESPBGetError(istream)
195196
if errorMessage.count > 0 {
196-
Logger.logInfo("Failed to decode transportBytes: \(errorMessage)")
197+
Logger.logError("Session Event failed to decode transportBytes: \(errorMessage)")
197198
}
198199
}
199200
return proto

0 commit comments

Comments
 (0)