Skip to content

Commit bed12ec

Browse files
KIRA009abrichr
andauthored
feat: run posthog in production only (#670)
Co-authored-by: Richard Abrich <[email protected]>
1 parent 11a4ad3 commit bed12ec

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

openadapt/app/dashboard/api/recordings.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_recordings() -> dict[str, list[Recording]]:
3636
@staticmethod
3737
async def start_recording() -> dict[str, str]:
3838
"""Start a recording session."""
39-
await crud.acquire_db_lock(begin_transaction=False)
39+
await crud.acquire_db_lock()
4040
quick_record()
4141
return {"message": "Recording started"}
4242

@@ -79,17 +79,11 @@ async def get_recording_detail(websocket: WebSocket, recording_id: int) -> None:
7979
image = display_event(action_event)
8080
width, height = image.size
8181
image = image2utf8(image)
82-
diff = image2utf8(display_event(action_event, diff=True))
83-
mask = image2utf8(action_event.screenshot.diff_mask)
84-
except Exception as e:
85-
logger.exception("Failed to display event: {}", e)
82+
except Exception:
83+
logger.info("Failed to display event")
8684
image = None
87-
diff = None
88-
mask = None
8985
width, height = 0, 0
9086
event_dict["screenshot"] = image
91-
event_dict["diff"] = diff
92-
event_dict["mask"] = mask
9387
event_dict["dimensions"] = {"width": width, "height": height}
9488
if event_dict["key"]:
9589
event_dict["key"] = str(event_dict["key"])

openadapt/app/dashboard/app/providers.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import posthog from 'posthog-js'
33
import { PostHogProvider } from 'posthog-js/react'
44

55
if (typeof window !== 'undefined') {
6-
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PUBLIC_KEY as string, {
7-
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
8-
})
6+
if (process.env.NEXT_PUBLIC_MODE !== "development") {
7+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PUBLIC_KEY as string, {
8+
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
9+
})
10+
}
911
}
1012

1113

1214
export function CSPostHogProvider({ children }: { children: React.ReactNode }) {
13-
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
15+
if (process.env.NEXT_PUBLIC_MODE === "development") {
16+
return <>{children}</>;
17+
}
18+
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
1419
}

openadapt/app/dashboard/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def run_client() -> subprocess.Popen:
4141
"DASHBOARD_SERVER_PORT": str(config.DASHBOARD_SERVER_PORT),
4242
"NEXT_PUBLIC_POSTHOG_HOST": POSTHOG_HOST,
4343
"NEXT_PUBLIC_POSTHOG_PUBLIC_KEY": POSTHOG_PUBLIC_KEY,
44+
"NEXT_PUBLIC_MODE": (
45+
"production" if is_running_from_executable() else "development"
46+
),
4447
},
4548
)
4649

openadapt/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
import git
1717
import sentry_sdk
1818

19-
from openadapt.build_utils import (
20-
get_root_dir_path,
21-
is_running_from_executable,
22-
)
19+
from openadapt.build_utils import get_root_dir_path, is_running_from_executable
2320

2421
ROOT_DIR_PATH = get_root_dir_path()
2522
CONFIG_DEFAULTS_FILE_PATH = (ROOT_DIR_PATH / "config.defaults.json").absolute()
@@ -403,7 +400,7 @@ def print_config() -> None:
403400
if is_running_from_executable():
404401
is_reporting_branch = True
405402
else:
406-
active_branch_name = git.Repo(ROOT_DIR_PATH).active_branch.name
403+
active_branch_name = git.Repo(ROOT_DIR_PATH.parent).active_branch.name
407404
logger.info(f"{active_branch_name=}")
408405
is_reporting_branch = (
409406
active_branch_name == config.ERROR_REPORTING_BRANCH

0 commit comments

Comments
 (0)