-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(replay): add feedback to LLM context #94315
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20a4019
feat(replay): add feedback to LLM context
michellewzhang 61c0886
:recycle: import
michellewzhang bb81894
:recycle: use feedback breadcrumb
michellewzhang 62cd6c7
:recycle: tweaks
michellewzhang 4c49505
:twisted_rightwards_arrows: merge master
michellewzhang 6ec0c56
:pencil2: types
michellewzhang 985f929
:art: pr comments
michellewzhang 8fcbb5a
:art: use default_project and make project_id required
michellewzhang 6527d33
:art: ref
michellewzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import uuid | ||
| import zlib | ||
| from datetime import datetime, timezone | ||
| from datetime import UTC, datetime, timezone | ||
| from unittest.mock import patch | ||
|
|
||
| import requests | ||
|
|
@@ -11,7 +11,7 @@ | |
| from sentry import nodestore | ||
| from sentry.eventstore.models import Event | ||
| from sentry.replays.endpoints.project_replay_summarize_breadcrumbs import ( | ||
| ErrorEvent, | ||
| GroupEvent, | ||
| as_log_message, | ||
| get_request_data, | ||
| ) | ||
|
|
@@ -56,6 +56,42 @@ def save_recording_segment( | |
| ) | ||
| FilestoreBlob().set(metadata, zlib.compress(data) if compressed else data) | ||
|
|
||
| def mock_create_feedback_occurrence(self, project_id: int, replay_id: str | None = None): | ||
| dt = datetime.now(UTC) | ||
|
|
||
| event = { | ||
| "project_id": project_id, | ||
| "event_id": "56b08cf7852c42cbb95e4a6998c66ad6", | ||
| "timestamp": dt.timestamp(), | ||
| "received": dt.isoformat(), | ||
| "first_seen": dt.isoformat(), | ||
| "user": { | ||
| "ip_address": "72.164.175.154", | ||
| "email": "[email protected]", | ||
| "id": 880461, | ||
| "isStaff": False, | ||
| "name": "Josh Ferge", | ||
| }, | ||
| "contexts": { | ||
| "feedback": { | ||
| "contact_email": "[email protected]", | ||
| "name": "Josh Ferge", | ||
| "message": "Great website!", | ||
| "replay_id": replay_id, | ||
| "url": "https://sentry.sentry.io/feedback/?statsPeriod=14d", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| self.store_event( | ||
| data={ | ||
| "event_id": event["event_id"], | ||
| "timestamp": event["timestamp"], | ||
| "contexts": event["contexts"], | ||
| }, | ||
| project_id=self.project.id, | ||
| ) | ||
michellewzhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @patch("sentry.replays.endpoints.project_replay_summarize_breadcrumbs.make_seer_request") | ||
| def test_get(self, make_seer_request): | ||
| return_value = json.dumps({"hello": "world"}).encode() | ||
|
|
@@ -215,7 +251,7 @@ def test_get_with_error(self, make_seer_request): | |
| assert response.content == return_value | ||
|
|
||
| @patch("sentry.replays.endpoints.project_replay_summarize_breadcrumbs.make_seer_request") | ||
| def test_get_with_error_context_disabled(self, make_seer_request): | ||
| def test_get_with_error_context_disabled_and_enabled(self, make_seer_request): | ||
| """Test handling of breadcrumbs with error context disabled""" | ||
| return_value = json.dumps({"error": "An error happened"}).encode() | ||
| make_seer_request.return_value = return_value | ||
|
|
@@ -261,6 +297,7 @@ def test_get_with_error_context_disabled(self, make_seer_request): | |
| ] | ||
| self.save_recording_segment(0, json.dumps(data).encode()) | ||
|
|
||
| # with error context disabled | ||
| with self.feature( | ||
| { | ||
| "organizations:session-replay": True, | ||
|
|
@@ -280,6 +317,85 @@ def test_get_with_error_context_disabled(self, make_seer_request): | |
| assert response.get("Content-Type") == "application/json" | ||
| assert response.content == return_value | ||
|
|
||
| # with error context enabled | ||
| with self.feature( | ||
| { | ||
| "organizations:session-replay": True, | ||
| "organizations:replay-ai-summaries": True, | ||
| "organizations:gen-ai-features": True, | ||
| } | ||
| ): | ||
| response = self.client.get(self.url, {"enable_error_context": "true"}) | ||
|
|
||
| call_args = json.loads(make_seer_request.call_args[0][0]) | ||
| assert "logs" in call_args | ||
| assert any("ZeroDivisionError" in log for log in call_args["logs"]) | ||
| assert any("division by zero" in log for log in call_args["logs"]) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.get("Content-Type") == "application/json" | ||
| assert response.content == return_value | ||
|
|
||
| @patch("sentry.replays.endpoints.project_replay_summarize_breadcrumbs.make_seer_request") | ||
| def test_get_with_feedback(self, make_seer_request): | ||
| """Test handling of breadcrumbs with user feedback""" | ||
| return_value = json.dumps({"feedback": "Feedback was submitted"}).encode() | ||
| make_seer_request.return_value = return_value | ||
|
|
||
| self.mock_create_feedback_occurrence(self.project.id, replay_id=self.replay_id) | ||
|
|
||
| now = datetime.now(timezone.utc) | ||
|
|
||
| self.store_replays( | ||
| mock_replay( | ||
| now, | ||
| self.project.id, | ||
| self.replay_id, | ||
| ) | ||
| ) | ||
|
|
||
| data = [ | ||
| { | ||
| "type": 5, | ||
| "timestamp": float(now.timestamp()), | ||
| "data": { | ||
| "tag": "breadcrumb", | ||
| "payload": {"category": "console", "message": "hello"}, | ||
| }, | ||
| }, | ||
| { | ||
| "type": 5, | ||
| "timestamp": float(now.timestamp()), | ||
| "data": { | ||
| "tag": "breadcrumb", | ||
| "payload": { | ||
| "category": "sentry.feedback", | ||
| "data": {"feedback_id": "56b08cf7852c42cbb95e4a6998c66ad6"}, | ||
| }, | ||
| }, | ||
| }, | ||
| ] | ||
| self.save_recording_segment(0, json.dumps(data).encode()) | ||
|
|
||
| with self.feature( | ||
| { | ||
| "organizations:session-replay": True, | ||
| "organizations:replay-ai-summaries": True, | ||
| "organizations:gen-ai-features": True, | ||
| } | ||
| ): | ||
| response = self.client.get(self.url) | ||
|
|
||
| make_seer_request.assert_called_once() | ||
| call_args = json.loads(make_seer_request.call_args[0][0]) | ||
| assert "logs" in call_args | ||
| assert any("Great website!" in log for log in call_args["logs"]) | ||
| assert any("User submitted feedback" in log for log in call_args["logs"]) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.get("Content-Type") == "application/json" | ||
| assert response.content == return_value | ||
|
|
||
|
|
||
| def test_get_request_data(): | ||
| def _faker(): | ||
|
|
@@ -307,14 +423,14 @@ def _faker(): | |
| ) | ||
|
|
||
| error_events = [ | ||
| ErrorEvent( | ||
| GroupEvent( | ||
| category="error", | ||
| id="123", | ||
| title="ZeroDivisionError", | ||
| timestamp=3.0, | ||
| message="division by zero", | ||
| ), | ||
| ErrorEvent( | ||
| GroupEvent( | ||
| category="error", | ||
| id="234", | ||
| title="BadError", | ||
|
|
||
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
Oops, something went wrong.
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.