Skip to content

Commit

Permalink
Fixed up logic
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Feb 22, 2024
1 parent a077032 commit 664fe1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion plugin-server/src/capabilities.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +19,7 @@ export function getPluginServerCapabilities(config: PluginsServerConfig): Plugin
processAsyncOnEventHandlers: true,
processAsyncWebhooksHandlers: true,
sessionRecordingBlobIngestion: true,
sessionRecordingV3Ingestion: isDevEnv(),
personOverrides: true,
appManagementSingleton: true,
preflightSchedules: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions posthog/session_recordings/realtime_snapshots.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down
13 changes: 11 additions & 2 deletions posthog/session_recordings/session_recording_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 664fe1c

Please sign in to comment.