Skip to content

Commit

Permalink
feat: run posthog in production only (#670)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Abrich <[email protected]>
  • Loading branch information
KIRA009 and abrichr authored May 14, 2024
1 parent 11a4ad3 commit bed12ec
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
12 changes: 3 additions & 9 deletions openadapt/app/dashboard/api/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_recordings() -> dict[str, list[Recording]]:
@staticmethod
async def start_recording() -> dict[str, str]:
"""Start a recording session."""
await crud.acquire_db_lock(begin_transaction=False)
await crud.acquire_db_lock()
quick_record()
return {"message": "Recording started"}

Expand Down Expand Up @@ -79,17 +79,11 @@ async def get_recording_detail(websocket: WebSocket, recording_id: int) -> None:
image = display_event(action_event)
width, height = image.size
image = image2utf8(image)
diff = image2utf8(display_event(action_event, diff=True))
mask = image2utf8(action_event.screenshot.diff_mask)
except Exception as e:
logger.exception("Failed to display event: {}", e)
except Exception:
logger.info("Failed to display event")
image = None
diff = None
mask = None
width, height = 0, 0
event_dict["screenshot"] = image
event_dict["diff"] = diff
event_dict["mask"] = mask
event_dict["dimensions"] = {"width": width, "height": height}
if event_dict["key"]:
event_dict["key"] = str(event_dict["key"])
Expand Down
13 changes: 9 additions & 4 deletions openadapt/app/dashboard/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import posthog from 'posthog-js'
import { PostHogProvider } from 'posthog-js/react'

if (typeof window !== 'undefined') {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PUBLIC_KEY as string, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
})
if (process.env.NEXT_PUBLIC_MODE !== "development") {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PUBLIC_KEY as string, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
})
}
}


export function CSPostHogProvider({ children }: { children: React.ReactNode }) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
if (process.env.NEXT_PUBLIC_MODE === "development") {
return <>{children}</>;
}
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
}
3 changes: 3 additions & 0 deletions openadapt/app/dashboard/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def run_client() -> subprocess.Popen:
"DASHBOARD_SERVER_PORT": str(config.DASHBOARD_SERVER_PORT),
"NEXT_PUBLIC_POSTHOG_HOST": POSTHOG_HOST,
"NEXT_PUBLIC_POSTHOG_PUBLIC_KEY": POSTHOG_PUBLIC_KEY,
"NEXT_PUBLIC_MODE": (
"production" if is_running_from_executable() else "development"
),
},
)

Expand Down
7 changes: 2 additions & 5 deletions openadapt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import git
import sentry_sdk

from openadapt.build_utils import (
get_root_dir_path,
is_running_from_executable,
)
from openadapt.build_utils import get_root_dir_path, is_running_from_executable

ROOT_DIR_PATH = get_root_dir_path()
CONFIG_DEFAULTS_FILE_PATH = (ROOT_DIR_PATH / "config.defaults.json").absolute()
Expand Down Expand Up @@ -403,7 +400,7 @@ def print_config() -> None:
if is_running_from_executable():
is_reporting_branch = True
else:
active_branch_name = git.Repo(ROOT_DIR_PATH).active_branch.name
active_branch_name = git.Repo(ROOT_DIR_PATH.parent).active_branch.name
logger.info(f"{active_branch_name=}")
is_reporting_branch = (
active_branch_name == config.ERROR_REPORTING_BRANCH
Expand Down

0 comments on commit bed12ec

Please sign in to comment.