Skip to content

Commit

Permalink
fix: flat sample key wil be easier to manage (#23444)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Jul 3, 2024
1 parent 3caeab0 commit 69dbda6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion posthog/api/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def sample_replay_data_to_object_storage(event: dict[str, Any], random_number: f
try:
sample_rate = settings.REPLAY_MESSAGE_TOO_LARGE_SAMPLE_RATE
if 0 < random_number < sample_rate <= 0.01:
object_key = f"token/{token}/session_id/{event.get('properties', {}).get('$session_id', 'unknown')}.json"
object_key = f"token-{token}-session_id-{event.get('properties', {}).get('$session_id', 'unknown')}.json"
object_storage.write(object_key, json.dumps(event), bucket=settings.REPLAY_MESSAGE_TOO_LARGE_SAMPLE_BUCKET)
except Exception as ex:
with sentry_sdk.push_scope() as scope:
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/test/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ def test_capture_replay_to_bucket_when_random_number_is_less_than_sample_rate(se
],
)
sample_replay_data_to_object_storage(event, random_number, "the-team-token")
contents = object_storage.read("token/the-team-token/session_id/abcdefgh.json", bucket=TEST_SAMPLES_BUCKET)
contents = object_storage.read("token-the-team-token-session_id-abcdefgh.json", bucket=TEST_SAMPLES_BUCKET)
assert contents == json.dumps(event)

@parameterized.expand(
Expand Down Expand Up @@ -2265,4 +2265,4 @@ def test_capture_replay_does_not_write_to_bucket(self, _name: str, sample_rate:
sample_replay_data_to_object_storage(event, random_number, "another-team-token")

with pytest.raises(ObjectStorageError):
object_storage.read("token/another-team-token/session_id/abcdefgh.json", bucket=TEST_SAMPLES_BUCKET)
object_storage.read("token-another-team-token-session_id-abcdefgh.json", bucket=TEST_SAMPLES_BUCKET)

0 comments on commit 69dbda6

Please sign in to comment.