fix: Prefix SDK log messages#682
Merged
Merged
Conversation
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
posthog/test/logging_helpers.py:9
The logger name `"posthog"` is hardcoded here rather than using `POSTHOG_LOGGER_NAME` from `logging_utils.py`, which already defines this constant. If the logger name ever changes, this file would be missed, and the helper would silently capture the wrong logger's output.
```suggestion
from posthog.logging_utils import POSTHOG_LOGGER_NAME
logger = logging.getLogger(POSTHOG_LOGGER_NAME)
```
Reviews (1): Last reviewed commit: "fix: Prefix SDK log messages" | Re-trigger Greptile |
Contributor
posthog-python Compliance ReportDate: 2026-06-19 18:37:54 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
476a124 to
51e3c98
Compare
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
posthog/_logging.py:24-27
**Redundant initialization calls across three modules**
`_configure_posthog_logging()` is called at module level in `client.py`, `consumer.py`, and `request.py`. Since all three already `import` from `_logging`, simply invoking `_configure_posthog_logging()` once at the bottom of `_logging.py` itself would be sufficient — the function runs the first time the module is imported, and the idempotency guard handles any subsequent imports. The three callers could then drop both the import and the call, keeping the initialization in exactly one place.
Reviews (2): Last reviewed commit: "fix: Prefix SDK log messages" | Re-trigger Greptile |
ioannisj
approved these changes
Jun 19, 2026
# Conflicts: # posthog/test/test_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Fixes #149.
Applications that configure logging with a message-only formatter, such as
'%(message)s', could see SDK logs likequeueing:orconsumer exited.without any PostHog identifier. This makes SDK-originated logs difficult to distinguish from application logs.💚 How did you test it?
uv run --extra test pytest -q posthog/test/test_client.py posthog/test/test_consumer.py posthog/test/test_request.pyuv run --extra dev ruff format --check posthog/logging_utils.py posthog/client.py posthog/request.py posthog/consumer.py posthog/test/logging_helpers.py posthog/test/test_client.py posthog/test/test_consumer.py posthog/test/test_request.py posthog/test/test_exception_capture.pyuv run --extra dev ruff check posthog/logging_utils.py posthog/client.py posthog/request.py posthog/consumer.py posthog/test/logging_helpers.py posthog/test/test_client.py posthog/test/test_consumer.py posthog/test/test_request.py posthog/test/test_exception_capture.pyuv run --extra test pytest -q posthog/test/test_exception_capture.py📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
A Pi worker agent implemented the issue-specific fix in a dedicated worktree. The change uses a centralized PostHog logging filter so SDK records are rendered with a
[PostHog]prefix in message-only formatter setups while avoiding duplicate prefixes when a message is already prefixed.Focused tests cover debug, info, and error log output rendered via a
'%(message)s'formatter, plus an existing exception-capture assertion was updated for the prefixed debug output.