Skip to content

feat: refactor instrumentations to use span/mode utils + add sampling#18

Merged
sohankshirsagar merged 7 commits intomainfrom
sohan/refactor-instrumentations
Jan 8, 2026
Merged

feat: refactor instrumentations to use span/mode utils + add sampling#18
sohankshirsagar merged 7 commits intomainfrom
sohan/refactor-instrumentations

Conversation

@sohankshirsagar
Copy link
Contributor

@sohankshirsagar sohankshirsagar commented Jan 8, 2026

  • need to add e2e tests for requests and httpx before refactoring those

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sohankshirsagar sohankshirsagar changed the title feat: refactor instrumentations to use span utils + mode utils feat: refactor instrumentations to use span/mode utils + fix sampling Jan 8, 2026
@sohankshirsagar sohankshirsagar changed the title feat: refactor instrumentations to use span/mode utils + fix sampling feat: refactor instrumentations to use span/mode utils + add sampling Jan 8, 2026
@sohankshirsagar sohankshirsagar merged commit 9a275be into main Jan 8, 2026
5 checks passed
@sohankshirsagar sohankshirsagar deleted the sohan/refactor-instrumentations branch January 8, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant