-
Notifications
You must be signed in to change notification settings - Fork 24
feat(client): support forwarding sdk logs to clients #627
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
Draft
addisonbeck
wants to merge
8
commits into
main
Choose a base branch
from
PM-27800-expose-sdk-tracing-flight-recorder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+488
−15
Conversation
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
- Create log_callback.rs module with UNIFFI callback trait definition - Add Send + Sync bounds for thread-safe callback invocation - Re-export LogCallback from lib.rs for UNIFFI binding generation - Include test validating trait implementation with Arc Part of PM-27800: Expose SDK Tracing to Flight Recorder
…g integration - Add CallbackLayer struct implementing tracing_subscriber::Layer - Implement MessageVisitor with record_debug for message extraction - Add target filtering to prevent infinite callback recursion - Include error logging to platform loggers for mobile debugging - Add basic compilation tests for layer and visitor - Remove weak test_message_visitor_extracts_message test CallbackLayer bridges SDK tracing to UNIFFI callback interface. MessageVisitor extracts formatted messages from trace events using only record_debug (sufficient per trait default implementations). Target filtering prevents recursion when logging callback errors.
…nal logging Refactor init_logger to accept optional callback parameter and compose CallbackLayer with existing tracing infrastructure from PM-26930. Changes: - Add callback parameter: fn init_logger(Option<Arc<dyn LogCallback>>) - Extract base registry construction to avoid platform duplication - Use Option layer pattern for type-safe conditional layer addition - Temporarily pass None at call site (updated in next TODO) Layer composition order: 1. Base registry (fmtlayer + filter) 2. CallbackLayer (optional - when callback provided) 3. Platform layers (oslog/android_logger/none) Each layer observes events independently. When callback is None, Option<CallbackLayer> becomes a no-op layer with no overhead.
…e logging - Add optional log_callback parameter to Client::new() constructor - Pass callback to init_logger() for integration with CallbackLayer - Update LogCallback trait to use uniffi::export(with_foreign) pattern - Add comprehensive test suite with mock implementations - Verify backward compatibility with None callback - All tests pass: callback receives logs and SDK works without callback This enables mobile clients to register callbacks for forwarding SDK logs to Flight Recorder observability systems following PM-27800 spec.
- Add CallbackError variant to BitwardenError enum - Implement From<UnexpectedUniFFICallbackError> conversion - Add test validating SDK stability when callbacks fail Enables proper error handling when mobile callbacks throw exceptions. Mobile exceptions are converted to BitwardenError::CallbackError at the FFI boundary, logged to platform loggers, and SDK continues normal operation without crashes. Test coverage: - test_callback_error_does_not_crash_sdk validates resilience Resolves PM-27800 error handling requirements.
…ency Remove test_client_with_callback_receives_logs which fails due to Once::call_once() in init_logger. The logger initializes once per process, causing test interference when multiple tests register different callbacks. The remaining tests provide sufficient coverage: - test_callback_error_does_not_crash_sdk validates error handling - test_client_without_callback_still_works validates backward compat - Callback invocation is implicitly validated by log output Future callback integration tests should use integration test directory (tests/) where each test runs in a separate process.
…alidation Replace test_client_without_callback_still_works with test_callback_receives_logs to validate core callback functionality. Rationale: - Backward compatibility (None callback) tests trivial Option handling - Happy path (successful callback) tests core feature implementation - Validates callback receives correct level, target, and message data - Removes test_callback_error_does_not_crash_sdk to avoid Once constraint Error handling remains validated through CallbackError implementation and From<UnexpectedUniFFICallbackError> conversion. Integration tests will provide comprehensive error and edge case coverage. Test passes consistently, proves primary use case works.
…callback - Created 5 integration tests in tests/ directory for callback validation - Each test runs as separate process, avoiding Once initialization constraint - TC-001: Happy path validation (callback receives logs with correct data) - TC-002: Multiple log levels (INFO, WARN, ERROR) forwarded correctly - TC-004: Thread safety validation (concurrent callback invocations) - TC-005: Error handling (callback failures don't crash SDK) - TC-007: MessageVisitor validates message field extraction Made error module public to enable integration tests to access BitwardenError type for test implementations. All tests pass and validate core callback functionality comprehensively.
Contributor
|
Great job! No new security vulnerabilities introduced in this pull request |
Contributor
🔍 SDK Breaking Change Detection ResultsSDK Version:
Breaking change detection completed. View SDK workflow |
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.

🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-27800
📔 Objective
🚨 Breaking Changes
⏰ Reminders before review
team
🦮 Reviewer guidelines
:+1:) or similar for great changes:memo:) or ℹ️ (:information_source:) for notes or general info:question:) for questions:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmedissue and could potentially benefit from discussion
:art:) for suggestions / improvements:x:) or:warning:) for more significant problems or concerns needing attention:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt:pick:) for minor or nitpick changes