Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/sentry/replays/endpoints/project_replay_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,39 @@ def post(self, request: Request, project: Project, replay_id: str) -> Response:
status=404,
)

# We expect the start and end times to be present, and error + respond 500 if they're not.
# Extract start and end times from the replay (pass None if missing or invalid).
replay = process_raw_response(snuba_response, fields=[])[0]
replay_start = datetime.fromisoformat(replay.get("started_at") or "")
replay_end = datetime.fromisoformat(replay.get("finished_at") or "")

def validate_iso_timestamp(timestamp: str | None) -> str | None:
"""Validate that timestamp is a valid ISO format string, return None if invalid."""
if not timestamp:
return None
try:
datetime.fromisoformat(timestamp)
return timestamp
except (ValueError, TypeError):
return None

replay_start = validate_iso_timestamp(replay.get("started_at"))
replay_end = validate_iso_timestamp(replay.get("finished_at"))

if not replay_start or not replay_end:
logger.warning(
"Replay start or end time missing or invalid.",
extra={
"started_at": replay.get("started_at"),
"finished_at": replay.get("finished_at"),
"replay_id": replay_id,
"organization_id": project.organization.id,
},
)

return self.make_seer_request(
SEER_START_TASK_ENDPOINT_PATH,
{
"replay_id": replay_id,
"replay_start": replay_start.isoformat(),
"replay_end": replay_end.isoformat(),
Comment on lines -206 to -207
Copy link
Member Author

Choose a reason for hiding this comment

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

confused why we were converting from iso and then to iso here, do we need this? .get() should default to None if it doesn't find anything

Copy link
Member

Choose a reason for hiding this comment

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

doing fromiso first to validate the format.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok added back validation

"replay_start": replay_start,
"replay_end": replay_end,
"num_segments": num_segments,
"organization_id": project.organization.id,
"project_id": project.id,
Expand Down
Loading