chore: improve code quality and production readiness#31
Merged
Conversation
sohankshirsagar
approved these changes
Jan 14, 2026
There was a problem hiding this comment.
1 issue found across 9 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="drift/core/batch_processor.py">
<violation number="1" location="drift/core/batch_processor.py:138">
P2: `_export_loop` always sleeps even when the queue already meets the export threshold, so condition notifications delivered while the thread wasn’t waiting are lost and batches aren’t exported immediately.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| # Wait for either: batch size reached, scheduled delay, or shutdown | ||
| with self._condition: | ||
| # Wait until batch is ready or timeout | ||
| self._condition.wait(timeout=self._config.scheduled_delay_seconds) |
There was a problem hiding this comment.
P2: _export_loop always sleeps even when the queue already meets the export threshold, so condition notifications delivered while the thread wasn’t waiting are lost and batches aren’t exported immediately.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At drift/core/batch_processor.py, line 138:
<comment>`_export_loop` always sleeps even when the queue already meets the export threshold, so condition notifications delivered while the thread wasn’t waiting are lost and batches aren’t exported immediately.</comment>
<file context>
@@ -121,16 +125,17 @@ def add_span(self, span: CleanSpanData) -> bool:
+ # Wait for either: batch size reached, scheduled delay, or shutdown
+ with self._condition:
+ # Wait until batch is ready or timeout
+ self._condition.wait(timeout=self._config.scheduled_delay_seconds)
if self._shutdown_event.is_set():
</file context>
Suggested change
| self._condition.wait(timeout=self._config.scheduled_delay_seconds) | |
| if ( | |
| not self._shutdown_event.is_set() | |
| and len(self._queue) < self._config.max_export_batch_size | |
| ): | |
| self._condition.wait(timeout=self._config.scheduled_delay_seconds) |
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
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.
Summary
Addresses several code quality issues to improve production readiness, consistency, and maintainability.
Changes
Version Management
importlib.metadatafor single source of truth version (reads frompyproject.toml)__version__indrift/__init__.pyto useSDK_VERSIONBug Fixes
request_mock_sync()pyproject.toml(pointed to Node SDK)Code Quality
print()withlogger.warning()in sampling validationexcept Exception: passblocksOSErrorinstead of bareExceptionfor socket cleanup[CONNECT_SYNC],[INIT_COMPLETE],[CLEANUP])TypeVardeclaration to top of file inregistry.pyPerformance
threading.ConditiontoBatchSpanProcessorfor efficient thread coordinationValidation
sampling_ratein config file parsingTesting