diff --git a/plugin-server/src/capabilities.ts b/plugin-server/src/capabilities.ts index b7285d1b1ebee..e2543d66adbb5 100644 --- a/plugin-server/src/capabilities.ts +++ b/plugin-server/src/capabilities.ts @@ -1,5 +1,5 @@ import { PluginServerCapabilities, PluginServerMode, PluginsServerConfig, stringToPluginServerMode } from './types' -import { isTestEnv } from './utils/env-utils' +import { isDevEnv, isTestEnv } from './utils/env-utils' export function getPluginServerCapabilities(config: PluginsServerConfig): PluginServerCapabilities { const mode: PluginServerMode | null = config.PLUGIN_SERVER_MODE @@ -19,6 +19,7 @@ export function getPluginServerCapabilities(config: PluginsServerConfig): Plugin processAsyncOnEventHandlers: true, processAsyncWebhooksHandlers: true, sessionRecordingBlobIngestion: true, + sessionRecordingV3Ingestion: isDevEnv(), personOverrides: true, appManagementSingleton: true, preflightSchedules: true, diff --git a/plugin-server/src/main/ingestion-queues/session-recording/session-recordings-consumer-v3.ts b/plugin-server/src/main/ingestion-queues/session-recording/session-recordings-consumer-v3.ts index 4567851d0d9bc..93e5cc3581516 100644 --- a/plugin-server/src/main/ingestion-queues/session-recording/session-recordings-consumer-v3.ts +++ b/plugin-server/src/main/ingestion-queues/session-recording/session-recordings-consumer-v3.ts @@ -414,7 +414,8 @@ export class SessionRecordingIngesterV3 { } private setupHttpRoutes() { - expressApp.get('/api/projects/:projectId/session_recordings/:sessionId', async (req, res) => { + // Mimic the app sever's endpoint + expressApp.get('/api/projects/:projectId/session_recordings/:sessionId/snapshots', async (req, res) => { // TODO: Sanitize the projectId and sessionId as we are checking the filesystem // validate that projectId is a number and sessionId is UUID like diff --git a/posthog/session_recordings/realtime_snapshots.py b/posthog/session_recordings/realtime_snapshots.py index d6890c63517e1..6c29ed59758d3 100644 --- a/posthog/session_recordings/realtime_snapshots.py +++ b/posthog/session_recordings/realtime_snapshots.py @@ -1,12 +1,14 @@ import json from time import sleep from typing import Dict, List, Optional +import requests import structlog from prometheus_client import Counter from posthog import settings from posthog.redis import get_client +from posthog.settings import RECORDINGS_INGESTER_URL from sentry_sdk import capture_exception logger = structlog.get_logger(__name__) diff --git a/posthog/session_recordings/session_recording_api.py b/posthog/session_recordings/session_recording_api.py index f34424ee46ee4..191f8ae1df87a 100644 --- a/posthog/session_recordings/session_recording_api.py +++ b/posthog/session_recordings/session_recording_api.py @@ -381,8 +381,17 @@ def snapshots(self, request: request.Request, **kwargs): response_data["sources"] = sources elif source == "realtime": - # TODO: Swap to using the new API if supported - snapshots = get_realtime_snapshots(team_id=self.team.pk, session_id=str(recording.session_id)) or [] + if request.GET.get("version", None) == "3" and settings.RECORDINGS_INGESTER_URL: + url = f"{settings.RECORDINGS_INGESTER_URL}/api/projects/{self.team.pk}/session_recordings/{str(recording.session_id)}/snapshots" + with requests.get(url=url, stream=True) as r: + if r.status_code == 404: + return Response({"snapshots": []}) + + response = HttpResponse(content=r.raw, content_type="application/json") + response["Content-Disposition"] = "inline" + return response + else: + snapshots = get_realtime_snapshots(team_id=self.team.pk, session_id=str(recording.session_id)) or [] event_properties["source"] = "realtime" event_properties["snapshots_length"] = len(snapshots)