Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix pr reviews

Blue Mousea0e11520f0c6
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.ts
index 620dd5f98..7c2b55dac 100644
--- a/backend/apps/cloud/src/analytics/analytics.service.ts
+++ b/backend/apps/cloud/src/analytics/analytics.service.ts
@@ -156,12 +156,20 @@ local activeReplayKey = KEYS[1]
local proposedReplayId = ARGV[1]
local chunkIndexRange = tonumber(ARGV[2])
local ttl = tonumber(ARGV[3])
+local maxDurationMs = tonumber(ARGV[4])
+local time = redis.call("TIME")
+local currentTimeMs = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000)
local replayId = redis.call("HGET", activeReplayKey, "replayId")
+local replayStartTs = tonumber(redis.call("HGET", activeReplayKey, "replayStartTs") or "")
local nextChunkIndex = tonumber(redis.call("HGET", activeReplayKey, "nextChunkIndex") or "0")
-if replayId == false or replayId == nil or replayId == "" then
+if
+ replayId == false or replayId == nil or replayId == "" or
+ replayStartTs == nil or replayStartTs + maxDurationMs <= currentTimeMs
+then
replayId = proposedReplayId
+ replayStartTs = currentTimeMs
nextChunkIndex = 0
end
@@ -171,6 +179,8 @@ redis.call(
activeReplayKey,
"replayId",
replayId,
+ "replayStartTs",
+ tostring(replayStartTs),
"nextChunkIndex",
allocatedChunkIndex + chunkIndexRange
)
@@ -1983,6 +1993,7 @@ export class AnalyticsService {
replayId,
SESSION_REPLAY_CHUNK_INDEX_RANGE,
this.getActiveReplayTtlSeconds(),
+ MAX_SESSION_REPLAY_DURATION_MS,
)
const [resolvedReplayId, nextChunkIndex] = Array.isArray(result)
? result
diff --git a/backend/apps/cloud/src/analytics/session-replay-export.service.ts b/backend/apps/cloud/src/analytics/session-replay-export.service.ts
index a6d87886e..6d980ab7a 100644
--- a/backend/apps/cloud/src/analytics/session-replay-export.service.ts
+++ b/backend/apps/cloud/src/analytics/session-replay-export.service.ts
@@ -155,7 +155,8 @@ export class SessionReplayExportService {
this.validateReplayMetadata(replay.eventCount, replay.replayDuration)
- const exportReplayId = replayId || 'session'
+ const resolvedReplayId = replay.replayId || replayId
+ const exportReplayId = resolvedReplayId || 'session'
const exportId = hash(
`${EXPORT_RENDERER_VERSION}:${pid}:${psid}:${exportReplayId}:${replay.eventCount}:${replay.replayDuration}`,
)
@@ -182,7 +183,7 @@ export class SessionReplayExportService {
exportId,
pid,
psid,
- replayId,
+ replayId: resolvedReplayId,
status: 'queued',
progress: 0,
filename: this.getFilename(psid),
@@ -201,7 +202,7 @@ export class SessionReplayExportService {
exportId,
pid,
psid,
- replayId,
+ replayId: resolvedReplayId,
},
{
jobId: exportId,