Skip to content

Add posthog integration for error logging#303

Merged
kdh29 merged 6 commits intomainfrom
posthog
Dec 17, 2025
Merged

Add posthog integration for error logging#303
kdh29 merged 6 commits intomainfrom
posthog

Conversation

@kcarnold
Copy link
Contributor

@kcarnold kcarnold commented Nov 11, 2025

Closes: #157

@kcarnold kcarnold requested a review from kdh29 November 11, 2025 19:25
Copy link
Contributor

@kdh29 kdh29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds cool, ill try it out!

@kcarnold
Copy link
Contributor Author

@kdh29 can you push what you've got so far?

@kdh29 kdh29 requested a review from Alina086 November 25, 2025 05:47
@Alina086 Alina086 mentioned this pull request Nov 25, 2025
@kdh29 kdh29 self-assigned this Nov 25, 2025
Copy link
Contributor Author

@kcarnold kcarnold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The container build might not work, we may need to do something like kcarnold/live-notes@e0df2c4

raise ValueError(f"Invalid generation type: {payload.gtype}")
result = await nlp.get_suggestion(payload.gtype, payload.doc_context)
# Pass username for PostHog LLM analytics tracking
result = await nlp.get_suggestion(payload.gtype, payload.doc_context, username=payload.username)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Posthog have contexts for things like this?

posthog_client = None
if POSTHOG_API_KEY:
from posthog import Posthog
posthog_client = Posthog(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant with the code in nlp.py.

const envVars = {};
const prefix = 'VITE_PUBLIC_';

for (const [key, value] of Object.entries(process.env)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs at build time, but .env gets injected at runtime, so this probably won't work (see my previous comment).

Copy link
Contributor Author

@kcarnold kcarnold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs cleanup, see comments inline.

btw, the build failure is an out-of-sync /frontend/package-lock.json. Jenkins says:


#21 [frontend build 4/6] RUN npm ci
#21 0.398 npm error code EUSAGE
#21 0.400 npm error
#21 0.400 npm error The `npm ci` command can only install with an existing package-lock.json or
#21 0.400 npm error npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
#21 0.400 npm error later to generate a package-lock.json file, then try again.
#21 0.400 npm error
#21 0.400 npm error Clean install a project
#21 0.400 npm error
#21 0.400 npm error Usage:
#21 0.400 npm error npm ci
#21 0.400 npm error
#21 0.400 npm error Options:
#21 0.400 npm error [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
#21 0.400 npm error [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
#21 0.400 npm error [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
#21 0.400 npm error [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
#21 0.400 npm error [--no-bin-links] [--no-fund] [--dry-run]
#21 0.400 npm error [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
#21 0.400 npm error [--workspaces] [--include-workspace-root] [--install-links]
#21 0.400 npm error
#21 0.400 npm error aliases: clean-install, ic, install-clean, isntall-clean
#21 0.400 npm error
#21 0.400 npm error Run "npm help ci" for more info
#21 0.400 npm error A complete log of this run can be found in: /root/.npm/_logs/2025-12-10T03_25_48_909Z-debug-0.log
#21 ERROR: process "/bin/sh -c npm ci" did not complete successfully: exit code: 1

Fix it by checking your node / npm version (should match what's in the Dockerfile), then revert package-lock to what was on main, then npm install to regen.

package.json Outdated
@@ -0,0 +1,7 @@
{
"dependencies": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package.json is in the wrong place (should be /frontend.

And I actually don't think we need any of these packages; these are for nodejs backends I think.

…-lock.json, remove misplaced package.json, update webpack env handling
@kdh29 kdh29 merged commit 9eb7e2f into main Dec 17, 2025
7 checks passed
@kdh29 kdh29 deleted the posthog branch December 17, 2025 02:21
@kcarnold kcarnold restored the posthog branch December 17, 2025 15:40
@kcarnold
Copy link
Contributor Author

Unfortunately this is causing crashes on prod because the API key was not configured. There's also a missing variable posthog_client in the code, so this wouldn't work even if that was defined. So I'm reverting using git revert -m 1 HEAD.

Errors were:

backend-1   | [2025-12-17 15:08:20 +0000] [10] [ERROR] Exception in worker process
backend-1   | Traceback (most recent call last):
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
backend-1   |     worker.init_process()
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/uvicorn/workers.py", line 75, in init_process
backend-1   |     super().init_process()
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 135, in init_process
backend-1   |     self.load_wsgi()
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 147, in load_wsgi
backend-1   |     self.wsgi = self.app.wsgi()
backend-1   |                 ^^^^^^^^^^^^^^^
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/app/base.py", line 66, in wsgi
backend-1   |     self.callable = self.load()
backend-1   |                     ^^^^^^^^^^^
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 57, in load
backend-1   |     return self.load_wsgiapp()
backend-1   |            ^^^^^^^^^^^^^^^^^^^
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 47, in load_wsgiapp
backend-1   |     return util.import_app(self.app_uri)
backend-1   | Warning: POSTHOG_API_KEY not set. LLM analytics will be disabled.
backend-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/gunicorn/util.py", line 370, in import_app
backend-1   |     mod = importlib.import_module(module)
backend-1   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
backend-1   |   File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
backend-1   |     return _bootstrap._gcd_import(name[level:], package, level)
backend-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
backend-1   |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
backend-1   |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
backend-1   |   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
backend-1   |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
backend-1   |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
backend-1   |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
backend-1   |   File "/app/backend/server.py", line 12, in <module>
backend-1   |     import nlp
backend-1   |   File "/app/backend/nlp.py", line 44, in <module>
backend-1   |     openai_client = AsyncOpenAI(
backend-1   |                     ^^^^^^^^^^^^
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/posthog/ai/openai/openai_async.py", line 50, in __init__
backend-1   |     self._ph_client = posthog_client or setup()
backend-1   |                                         ^^^^^^^
backend-1   |   File "/app/.venv/lib/python3.11/site-packages/posthog/__init__.py", line 769, in setup
backend-1   |     raise ValueError("API key is required")
backend-1   | ValueError: API key is required

kcarnold added a commit that referenced this pull request Dec 17, 2025
This reverts commit 9eb7e2f, reversing
changes made to cf36ad1.
@kdh29 kdh29 mentioned this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failure notifications

2 participants