-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleverly query replays by logs (#22018)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e74488c
commit d6f60c8
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
74 changes: 74 additions & 0 deletions
74
posthog/hogql/database/schema/test/test_session_replay_events.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from posthog.hogql import ast | ||
from posthog.hogql.parser import parse_select | ||
from posthog.hogql.query import execute_hogql_query | ||
from posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summary | ||
from posthog.test.base import ( | ||
APIBaseTest, | ||
ClickhouseTestMixin, | ||
) | ||
|
||
|
||
class TestFilterSessionReplaysByConsoleLogs(ClickhouseTestMixin, APIBaseTest): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
produce_replay_summary( | ||
team_id=self.team.pk, | ||
distinct_id="d1", | ||
session_id="session_with_info_and_error_messages", | ||
log_messages={ | ||
"info": ["This is an info message"], | ||
"error": ["This is a generic message"], | ||
}, | ||
) | ||
|
||
produce_replay_summary( | ||
team_id=self.team.pk, | ||
distinct_id="d1", | ||
session_id="session_with_only_info_messages", | ||
log_messages={ | ||
"info": ["This is a generic message"], | ||
}, | ||
) | ||
|
||
produce_replay_summary( | ||
team_id=self.team.pk, distinct_id="d1", session_id="session_with_no_log_messages", log_messages=None | ||
) | ||
|
||
def test_select_by_console_log_text(self): | ||
response = execute_hogql_query( | ||
parse_select( | ||
"select distinct session_id from raw_session_replay_events where console_logs.message = {log_message} order by session_id asc", | ||
placeholders={"log_message": ast.Constant(value="This is a generic message")}, | ||
), | ||
self.team, | ||
) | ||
|
||
assert response.results == [("session_with_info_and_error_messages",), ("session_with_only_info_messages",)] | ||
|
||
def test_select_by_console_log_text_and_level(self): | ||
response = execute_hogql_query( | ||
parse_select( | ||
"select distinct session_id from raw_session_replay_events where console_logs.message = {log_message} and console_logs.level = {log_level} order by session_id asc", | ||
placeholders={ | ||
"log_message": ast.Constant(value="This is a generic message"), | ||
"log_level": ast.Constant(value="error"), | ||
}, | ||
), | ||
self.team, | ||
) | ||
|
||
assert response.results == [("session_with_info_and_error_messages",)] | ||
|
||
def test_select_log_text(self): | ||
response = execute_hogql_query( | ||
parse_select( | ||
"select distinct console_logs.message from raw_session_replay_events where console_logs.level = {log_level} order by session_id asc", | ||
placeholders={ | ||
"log_level": ast.Constant(value="info"), | ||
}, | ||
), | ||
self.team, | ||
) | ||
|
||
assert response.results == [("This is an info message",), ("This is a generic message",)] |
This file contains 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