From 6faef7e7c618b4221b14444127b1a707779800bd Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 3 Oct 2024 21:22:09 +0800 Subject: [PATCH] fix: Added a bunch of logs to see whats up (#25365) --- plugin-server/src/utils/db/celery.ts | 1 + posthog/tasks/plugin_server.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/plugin-server/src/utils/db/celery.ts b/plugin-server/src/utils/db/celery.ts index daec50f09b3..9494f72a1db 100644 --- a/plugin-server/src/utils/db/celery.ts +++ b/plugin-server/src/utils/db/celery.ts @@ -43,6 +43,7 @@ export class Celery { const body = [args, kwargs, { callbacks: null, errbacks: null, chain: null, chord: null }] /** A base64-encoded JSON representation of the body tuple. */ const bodySerialized = Buffer.from(JSON.stringify(body)).toString('base64') + await this.redisLPush(CELERY_DEFAULT_QUEUE, { body: bodySerialized, 'content-encoding': 'utf-8', diff --git a/posthog/tasks/plugin_server.py b/posthog/tasks/plugin_server.py index 11a6e0dd903..e7aa29a1156 100644 --- a/posthog/tasks/plugin_server.py +++ b/posthog/tasks/plugin_server.py @@ -2,11 +2,14 @@ from typing import Optional from celery import shared_task from django.conf import settings import posthoganalytics +from structlog import get_logger from posthog.event_usage import report_team_action from posthog.tasks.email import send_hog_function_disabled, send_fatal_plugin_error from posthog.tasks.utils import CeleryQueue +logger = get_logger(__name__) + # IMPORTANT - Do not modify this without also modifying plugin-server/../celery.ts # Same goes for this file path and the task names queue = CeleryQueue.DEFAULT.value @@ -28,9 +31,12 @@ def fatal_plugin_error( def hog_function_state_transition(hog_function_id: str, state: int) -> None: from posthog.models.hog_functions.hog_function import HogFunction + logger.info("hog_function_state_transition", hog_function_id=hog_function_id, state=state) + hog_function = HogFunction.objects.get(id=hog_function_id) if not hog_function: + logger.warning("hog_function_state_transition: hog_function not found", hog_function_id=hog_function_id) return report_team_action( @@ -44,7 +50,11 @@ def hog_function_state_transition(hog_function_id: str, state: int) -> None: ) # TRICKY: It seems like without this call the events don't get flushed, possibly due to celery worker threads exiting... + logger.info("hog_function_state_transition: Flushing posthoganalytics") posthoganalytics.flush() if state >= 2: # 2 and 3 are disabled + logger.info("hog_function_state_transition: sending hog_function_disabled email") send_hog_function_disabled.delay(hog_function_id) + + logger.info("hog_function_state_transition: done")