feat: refactor instrumentations to use span/mode utils + add sampling#18
Merged
sohankshirsagar merged 7 commits intomainfrom Jan 8, 2026
Merged
feat: refactor instrumentations to use span/mode utils + add sampling#18sohankshirsagar merged 7 commits intomainfrom
sohankshirsagar merged 7 commits intomainfrom
Conversation
There was a problem hiding this comment.
6 issues 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/instrumentation/psycopg/instrumentation.py">
<violation number="1" location="drift/instrumentation/psycopg/instrumentation.py:378">
P2: Span is not ended when `RuntimeError` is raised. This causes a resource leak. Consider wrapping in try/finally to ensure `span_info.span.end()` is always called.</violation>
</file>
<file name="drift/core/mode_utils.py">
<violation number="1" location="drift/core/mode_utils.py:57">
P2: Inconsistent error handling: `is_background_request` makes the same SDK calls that are protected by try-except in `handle_record_mode`. Consider adding error handling and returning `False` on failure (safe default).</violation>
<violation number="2" location="drift/core/mode_utils.py:57">
P2: Inconsistent error handling: `handle_record_mode` wraps these same SDK calls in try-except, but `handle_replay_mode` does not. If `TuskDrift.get_instance()` or subsequent calls can fail, this function should also handle exceptions gracefully to avoid crashing the instrumented application.</violation>
</file>
<file name="drift/instrumentation/psycopg2/instrumentation.py">
<violation number="1" location="drift/instrumentation/psycopg2/instrumentation.py:471">
P2: Span is not ended before raising RuntimeError, causing a span leak. Add `span_info.span.end()` before the raise statement to ensure the span is properly closed.</violation>
</file>
<file name="drift/instrumentation/redis/instrumentation.py">
<violation number="1" location="drift/instrumentation/redis/instrumentation.py:199">
P1: Span is never ended in `_replay_execute_command`. The `SpanUtils.with_span()` context manager only handles context attach/detach but does not end the span. Add `span_info.span.end()` in a finally block to ensure the span is properly closed.</violation>
<violation number="2" location="drift/instrumentation/redis/instrumentation.py:199">
P1: Span is never ended in `_replay_pipeline_execute`. The `SpanUtils.with_span()` context manager only handles context attach/detach but does not end the span. Add `span_info.span.end()` in a finally block to ensure the span is properly closed.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
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.
Uh oh!
There was an error while loading. Please reload this page.