-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Implement logging for Room, RoomLifecycleManager #84
Conversation
WalkthroughThe pull request introduces several modifications across various classes related to messaging, occupancy, presence, and room management in the chat application. Key changes include the renaming of logging properties for consistency, enhancements to error handling and logging mechanisms, and updates to method signatures to incorporate logging parameters. The overall structure of the interfaces remains intact, but the internal implementations have been refined to improve clarity and traceability during operations. Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
95a46cc
to
e8f7033
Compare
Code Coverage
|
1. Added private property roomsLogger for DefaultRooms class 2. Added basic logging for Rooms#get method 3. Updated fields roomGetDeferred and roomReleaseDeferred to roomGetDeferredMap and roomReleaseDeferredMap respectively 4. Refactored roomGetDeferred.invokeOnCompletion, to make sure operation is executed under sequential scope, moved it as a part of release
bb9a620
to
5c615aa
Compare
1. Renamed property roomLogger to logger 2. Added basic trace, debug and error loggings for the Room 3. Updated 'ensureAttached` method to accept featureLogger, added missing loggings for the same
9401a7c
to
2738fc7
Compare
2738fc7
to
da45e64
Compare
da45e64
to
4f09eaf
Compare
4f09eaf
to
e686835
Compare
e686835
to
f3b40a3
Compare
f3b40a3
to
d4cfc19
Compare
d4cfc19
to
00f995d
Compare
00f995d
to
91049c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (3)
chat-android/src/main/java/com/ably/chat/Typing.kt (2)
158-160
: Consider adding error handling for presence.getCoroutine()While the room attachment check is properly logged, the presence.getCoroutine() call could benefit from explicit error handling to provide better error context in logs.
override suspend fun get(): Set<String> { logger.trace("DefaultTyping.get()") room.ensureAttached(logger) - return channel.presence.getCoroutine().map { it.clientId }.toSet() + return try { + channel.presence.getCoroutine().map { it.clientId }.toSet() + } catch (e: Exception) { + logger.error("Failed to get typing presence members", e) + throw e + } }
183-185
: Consider adding error handling for presence.leaveClientCoroutine()While the room attachment check is properly logged, the presence.leaveClientCoroutine() call could benefit from explicit error handling to provide better error context in logs.
override suspend fun stop() { logger.trace("DefaultTyping.stop()") typingScope.launch { typingJob?.cancel() room.ensureAttached(logger) - channel.presence.leaveClientCoroutine(room.clientId) + try { + channel.presence.leaveClientCoroutine(room.clientId) + } catch (e: Exception) { + logger.error("Failed to leave typing presence", e, mapOf("clientId" to room.clientId)) + throw e + } }.join() }chat-android/src/main/java/com/ably/chat/Room.kt (1)
136-137
: Consider enhancing error messages with specific missing options.The error messages could be more specific about which options are missing from the RoomOptions.
Example improvement for presence:
-logger.error("Presence access failed, not enabled in provided RoomOptions: $options") +logger.error("Presence access failed, presence.enabled is false in provided RoomOptions: $options")Also applies to: 146-147, 156-157, 166-167
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (14)
chat-android/src/main/java/com/ably/chat/Messages.kt
(1 hunks)chat-android/src/main/java/com/ably/chat/Occupancy.kt
(1 hunks)chat-android/src/main/java/com/ably/chat/Presence.kt
(3 hunks)chat-android/src/main/java/com/ably/chat/Room.kt
(10 hunks)chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt
(16 hunks)chat-android/src/main/java/com/ably/chat/RoomOptions.kt
(1 hunks)chat-android/src/main/java/com/ably/chat/RoomReactions.kt
(3 hunks)chat-android/src/main/java/com/ably/chat/Rooms.kt
(3 hunks)chat-android/src/main/java/com/ably/chat/Typing.kt
(5 hunks)chat-android/src/test/java/com/ably/chat/TypingTest.kt
(1 hunks)chat-android/src/test/java/com/ably/chat/room/RoomEnsureAttachedTest.kt
(5 hunks)chat-android/src/test/java/com/ably/chat/room/RoomGetTest.kt
(2 hunks)chat-android/src/test/java/com/ably/chat/room/RoomReleaseTest.kt
(4 hunks)chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt
(1 hunks)
🧰 Additional context used
📓 Learnings (2)
chat-android/src/main/java/com/ably/chat/Occupancy.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#66
File: chat-android/src/main/java/com/ably/chat/Occupancy.kt:145-145
Timestamp: 2024-11-28T11:11:20.423Z
Learning: In `chat-android/src/main/java/com/ably/chat/Occupancy.kt`, within the `DefaultOccupancy` class, when methods use `room.chatApi`, which utilizes the REST API, there's no need to call `room.ensureAttached()` before performing the operation.
chat-android/src/main/java/com/ably/chat/Room.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#66
File: chat-android/src/main/java/com/ably/chat/Room.kt:0-0
Timestamp: 2024-11-28T11:09:34.042Z
Learning: In the `DefaultRoom` class, the `ensureAttached()` method checks `statusLifecycle.status` again inside `roomScope.launch` to handle possible state changes, ensuring robustness.
🔇 Additional comments (34)
chat-android/src/main/java/com/ably/chat/RoomReactions.kt (2)
109-109
: LGTM: Logger implementation looks good!
The logger is properly initialized and scoped with the "Reactions" context tag, following good logging practices. The inheritance from ContributesToRoomLifecycleImpl
ensures proper lifecycle management.
Also applies to: 121-121
140-141
: Please clarify the TODO comment about potential spec changes
The TODO comment indicates that the ensureAttached
check might be removed, but lacks context about:
- Which core spec change might trigger this
- The implications of removing this check
- The timeline or conditions for removal
Consider adding more detailed documentation about:
- The current purpose of this check
- Why it might become unnecessary
- What spec changes would trigger its removal
Let's check for related TODOs or spec discussions:
chat-android/src/main/java/com/ably/chat/Typing.kt (3)
97-97
: LGTM: Well-structured logging initialization
The logger setup follows best practices by:
- Using the room's logger as the base logger
- Adding appropriate context with the "Typing" tag for better log filtering
- Maintaining consistency with other components in the codebase
Also applies to: 106-106
173-175
: LGTM: Well-structured typing start implementation
The implementation properly handles:
- Logging during room attachment
- Timer reset logic
- Presence channel updates
Line range hint 97-106
: Verify logging configuration consistency
Let's verify that the logging configuration is consistent across related components.
✅ Verification successful
Logging configuration is consistently implemented across components
The verification shows consistent logging patterns across all major components:
- All components initialize their loggers using
room.logger.withContext
with appropriate component tags - The
ensureAttached
method consistently receives the logger parameter across all usages - Each component maintains its own scoped logger with a descriptive tag matching its functionality
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check logging configuration consistency across related files
# Check logger initialization patterns
echo "Checking logger initialization patterns..."
rg -A 2 "private val logger = \w+\.logger\.withContext" chat-android/src/main/java/com/ably/chat/
# Check ensureAttached logger parameter usage
echo "Checking ensureAttached logger parameter usage..."
rg "ensureAttached\(.*logger" chat-android/src/main/java/com/ably/chat/
Length of output: 2898
chat-android/src/test/java/com/ably/chat/room/RoomGetTest.kt (5)
126-127
: LGTM! Clear and accurate assertions.
The assertions correctly verify that no release operations are in progress by checking both the size and specific room entry in the RoomReleaseDeferredMap.
188-189
: LGTM! Proper verification of release operation state.
The assertions correctly verify that a release operation is in progress by checking both the map size and the presence of a deferred entry for the specific room.
192-194
: LGTM! Proper verification of concurrent get operation state.
The assertions correctly verify that a get operation is waiting by checking both the map size and the presence of a deferred entry for the specific room.
199-200
: LGTM! Proper verification of completed release operation.
The assertions correctly verify that the release operation has completed by checking that the map is empty and the specific room entry is removed.
203-205
: LGTM! Proper verification of completed get operation.
The assertions correctly verify that the get operation has completed by checking that the map is empty and the specific room entry is removed.
chat-android/src/test/java/com/ably/chat/room/RoomReleaseTest.kt (5)
117-118
: LGTM! Proper verification of initial state.
The assertions correctly verify that both maps are empty before attempting to release a non-existent room.
124-125
: LGTM! Proper verification of unchanged state after no-op.
The assertions correctly verify that both maps remain empty after attempting to release a non-existent room.
167-168
: LGTM! Proper verification of release operation state.
The assertions correctly verify that a release operation is in progress by checking both the map size and the presence of a deferred entry.
175-175
: LGTM! Proper verification of completed release operation.
The assertion correctly verifies that the release operation has completed by checking that the map is empty.
226-227
: LGTM! Comprehensive verification of concurrent operations.
The assertions thoroughly verify the state transitions during concurrent get and release operations:
- Initial release operation state
- Waiting get operations state
- Cancellation of pending get operations
- New get operation state
- Final cleanup of both maps
The test provides excellent coverage of the concurrent operation handling.
Also applies to: 238-239, 245-245, 251-252, 257-258, 261-263
chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt (1)
69-70
: LGTM! Property names are now more descriptive
The renaming of properties from RoomGetDeferred
/RoomReleaseDeferred
to RoomGetDeferredMap
/RoomReleaseDeferredMap
better reflects their nature as map collections, improving code clarity.
chat-android/src/main/java/com/ably/chat/Rooms.kt (4)
65-65
: LGTM! Proper logger initialization with context
Good practice to use a context-specific logger with the "Rooms" tag for better log filtering and identification.
Also applies to: 67-67
76-77
: LGTM! Consistent property naming
Property names now clearly indicate they are maps, matching the changes in test helpers.
80-80
: LGTM! Well-structured logging in get method
Good implementation of logging with:
- Entry logging at TRACE level
- Outcome logging at DEBUG level
- Meaningful context in log messages
Also applies to: 87-87, 93-93
99-111
: LGTM! Comprehensive logging for get operation cancellation
Good implementation of logging with appropriate error handling and cleanup.
chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt (1)
120-125
: Initialization of logger with appropriate context
The logger
is correctly initialized with context in RoomLifecycleManager
, enhancing log traceability.
chat-android/src/test/java/com/ably/chat/TypingTest.kt (1)
45-45
: Update mock to match new method signature
The ensureAttached
method now requires a Logger
parameter. The mock setup correctly reflects this change.
chat-android/src/main/java/com/ably/chat/RoomOptions.kt (1)
107-110
: Enhanced error logging in validateRoomOptions
Adding the logger
parameter to validateRoomOptions
enables detailed error logging for invalid room configurations, improving debuggability.
chat-android/src/main/java/com/ably/chat/Occupancy.kt (2)
76-76
: Consistent logger initialization in DefaultOccupancy
The logger
is properly initialized using room.logger
with the "Occupancy" tag, ensuring consistent logging within the class.
Also applies to: 84-84
Line range hint 88-93
: Appropriate usage of room.chatApi
without ensuring attachment
Following prior learnings, the get()
method correctly uses room.chatApi
without calling room.ensureAttached()
, as the REST API does not require the room to be attached.
chat-android/src/main/java/com/ably/chat/Presence.kt (2)
149-149
: LGTM! Enhanced logging context.
The logger initialization with the "Presence" tag improves traceability by providing context-aware logging.
154-154
: LGTM! Consistent error handling with logging.
The ensureAttached
calls now include the logger parameter, which aligns with the updated method signature in DefaultRoom
and enables better error tracking across presence operations.
Also applies to: 168-168, 173-173, 178-178
chat-android/src/test/java/com/ably/chat/room/RoomEnsureAttachedTest.kt (1)
47-47
: LGTM! Test cases updated for logger parameter.
The test cases have been properly updated to include the logger parameter in ensureAttached
calls, maintaining consistency with the method signature changes in DefaultRoom
.
Also applies to: 73-73, 101-101, 117-117, 153-153
chat-android/src/main/java/com/ably/chat/Room.kt (4)
120-120
: LGTM! Enhanced logging context.
The logger initialization with room context and metadata improves traceability by including the roomId.
183-185
: LGTM! Comprehensive initialization logging.
The initialization logging provides clear visibility into room setup and enabled features.
Also applies to: 214-216
227-227
: LGTM! Added trace logging for lifecycle methods.
The trace logging for attach, detach, and release methods improves debugging capabilities.
Also applies to: 232-232, 241-241
Line range hint 251-296
: LGTM! Enhanced error tracking in ensureAttached.
The ensureAttached
method changes provide:
- Improved error tracking with feature-specific logger
- Clear state transition logging
- Detailed error information when attachment fails
chat-android/src/main/java/com/ably/chat/Messages.kt (2)
223-223
: LGTM: Proper integration with room lifecycle logging
The inheritance from ContributesToRoomLifecycleImpl
with room.logger
parameter ensures consistent logging across the room lifecycle, aligning with the PR's logging implementation objectives.
229-229
: LGTM: Well-structured logger initialization with proper context
The logger is correctly initialized with the "Messages" tag and properly scoped from the room's logger.
Let's verify consistent logger usage across the codebase:
✅ Verification successful
LGTM: Logger initialization follows consistent pattern across the codebase
The verification confirms that the logger initialization in Messages.kt follows the same pattern used consistently throughout the codebase. All components (Typing, Rooms, Reactions, Messages, Presence, Occupancy, ChatClient) properly initialize their loggers using withContext(tag = "...")
with appropriate context tags.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for consistent logger initialization patterns across the codebase
# Check for logger initialization patterns
rg -A 2 "withContext\(tag\s*=\s*\".*\"\)" --type kotlin
# Check for potential direct logger usage without context
rg "\.logger\." --type kotlin
Length of output: 3247
ba6eeb8
to
b3b0a6c
Compare
Unit tests for logging will be addressed as a part of #92 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1. Added private property logger with thread specific dynamic context 2. Added trace, debug, error logging for private doRetry method 3. Added trace, debug, error logging for attach method 4. Added trace, debug, error logging for detach method 5. Added trace, debug, error logging for release method 6. Refactored Logger.kt default Android Logger TAG and formattedMessage a bit
b3b0a6c
to
037d607
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
chat-android/src/main/java/com/ably/chat/Logger.kt (2)
102-102
: Consider improving log format for better parsability.The current format
"$currentTime (${level.name.uppercase()}) ${finalContext.tag}:${message}$contextString"
could be enhanced for better machine parsing and readability.Consider using a more structured format with clear separators:
-val formattedMessage = "$currentTime (${level.name.uppercase()}) ${finalContext.tag}:${message}$contextString" +val formattedMessage = buildString { + append(currentTime) + append(" | ") + append(level.name.uppercase()) + append(" | ") + append(finalContext.tag) + append(" | ") + append(message) + if (completeContext.isNotEmpty()) { + append(" | context=") + append(completeContext) + } +}Benefits:
- Uses pipe (
|
) as a consistent separator- Avoids confusion with colons in timestamps
- Only includes context when non-empty
- Easier to parse programmatically using split operations
97-102
: Consider documenting the logging format specification.As these changes are part of a broader logging standardization effort across the application, it would be valuable to document the logging format specification (including the tag prefix and message structure) in a central location, such as a README or documentation file.
This documentation would help:
- Ensure consistency as the application grows
- Guide future contributors
- Assist in creating log parsing tools
- Make log analysis more efficient
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
chat-android/src/main/java/com/ably/chat/Logger.kt
(1 hunks)chat-android/src/main/java/com/ably/chat/Room.kt
(10 hunks)chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt
(16 hunks)chat-android/src/main/java/com/ably/chat/Utils.kt
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- chat-android/src/main/java/com/ably/chat/Utils.kt
🧰 Additional context used
📓 Learnings (2)
chat-android/src/main/java/com/ably/chat/Room.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#66
File: chat-android/src/main/java/com/ably/chat/Room.kt:0-0
Timestamp: 2024-11-28T11:09:34.042Z
Learning: In the `DefaultRoom` class, the `ensureAttached()` method checks `statusLifecycle.status` again inside `roomScope.launch` to handle possible state changes, ensuring robustness.
chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#84
File: chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt:261-263
Timestamp: 2024-12-12T09:17:50.095Z
Learning: In `RoomLifecycleManager.kt`, when setting `RoomStatus` to `Failed`, it's acceptable if `errorInfo` is `null`, and custom errors are not needed.
🔇 Additional comments (14)
chat-android/src/main/java/com/ably/chat/Logger.kt (1)
97-97
: LGTM! Good practice for log tag prefixing.
Adding the "ably-chat:" prefix to log tags is a good practice as it helps in filtering and identifying application-specific logs in the system log output.
chat-android/src/main/java/com/ably/chat/Room.kt (5)
Line range hint 120-125
: LGTM! Enhanced logging context with thread information.
The logger initialization has been improved by:
- Standardizing the logger property name
- Adding thread name to the logging context for better traceability
136-137
: LGTM! Improved error logging for presence access.
The error handling has been enhanced with detailed logging that includes the room options context, making it easier to diagnose presence-related issues.
146-147
: LGTM! Consistent error logging across feature access points.
Error handling has been standardized across reactions, typing, and occupancy features, providing detailed context through logging of room options.
Also applies to: 156-157, 166-167
172-172
: LGTM! Enhanced initialization logging.
Added appropriate logging for:
- Room initialization with options context
- Room options validation step
Also applies to: 183-185
214-216
: LGTM! Improved feature initialization logging.
Enhanced logging provides clear visibility into:
- RoomLifecycleManager initialization
- List of initialized features
chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt (8)
120-125
: LGTM! Consistent logger naming and enhanced thread context.
The changes align with the standardized logger naming convention and add valuable thread context for debugging concurrent operations.
192-207
: LGTM! Comprehensive logging for retry operations.
Added detailed logging that covers:
- Entry and exit points of the retry operation
- Channel wind-down process and failures
- Appropriate use of log levels (debug for normal flow, error for failures)
211-243
: LGTM! Detailed logging for attachment retry process.
Enhanced logging covers:
- Attachment attempts for all feature channels
- Failure scenarios with appropriate error context
- Status transitions during the retry process
249-267
: LGTM! Clear logging for channel reattachment process.
Added comprehensive logging for:
- Channel reattachment detection
- Waiting process for channel attachment
- Error handling during the waiting process
320-373
: LGTM! Comprehensive logging for room attachment process.
Added thorough logging that covers:
- Initial attachment state checks
- State transitions during attachment
- Error scenarios with appropriate context
- Successful attachment completion
Line range hint 386-430
: LGTM! Detailed logging for feature-level attachment process.
Enhanced logging covers:
- Individual feature attachment attempts
- Success/failure status for each feature
- Room state transitions based on attachment results
Line range hint 448-459
: LGTM! Clear logging for channel wind-down process.
Added appropriate logging for:
- Start of wind-down process
- Completion status of channel detachment
Line range hint 472-691
: LGTM! Consistent logging across all lifecycle operations.
The remaining changes maintain the same high quality of logging throughout:
- Clear entry/exit points for all operations
- Appropriate log levels (trace, debug, warn, error)
- Detailed context for state transitions and error scenarios
- Feature-specific logging for granular debugging
Fixed #82
Fixed #83
Fixed #43
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Refactor
Tests