feat: identify MCP and AI analytics events by library - #917
Open
marandaneto wants to merge 3 commits into
Open
Conversation
Member
Author
|
This matches @posthog/ai and the MCP analytics |
Contributor
posthog-python Compliance ReportDate: 2026-09-03 12:09:38 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
Prompt To Fix All With AI### Issue 1
posthog/client.py:1083-1086
**Queued events get conflicting identity**
When `instrument()` relabels an active capture-v1 client with queued analytics events, those events retain their original `$lib` properties while the consumer sends them with the new MCP `PostHog-Sdk-Info` header, causing inconsistent library attribution.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat: identify MCP and AI analytics libr..." | Re-trigger Greptile |
1 task
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
MCP events currently report the generic
posthog-pythonlibrary, which makes them harder to distinguish from other Python SDK events. AI events also lack the$ai_liband$ai_lib_versionproperties emitted by@posthog/ai.This change gives both integrations consistent library metadata across the Python and Node SDKs.
💚 How did you test it?
uv run pytest -q- 2376 passed, 15 skipped, and 38 subtests passeduv run pytest -q posthog/test/test_capture_v1.py posthog/test/test_consumer.py posthog/test/test_capture_mode.py posthog/test/mcp/test_posthog_mcp.py posthog/test/mcp/test_no_crash.py posthog/test/test_ai_capture_lane.py- 236 passed after the CI fixuv run ruff format --check .uv run ruff check .uv run mypy --no-site-packages --config-file mypy.ini . | uv run mypy-baseline filteruv run make public_api_check📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with the Pi coding agent under human direction. The MCP integration uses a client-level identity to match
@posthog/mcp, including the capture v1 SDK header. This relabels every event sent by a client passed toinstrument(), so the documentation recommends a dedicated MCP analytics client. AI events keep the standard Python$libfields and add the separate$ai_libfields used by@posthog/ai. Existing$ai_providerand$ai_modelvalues remain unchanged.The CI follow-up kept the new SDK metadata internal to avoid changing the public API snapshot. It also updated the capture v1 compliance adapter to accept and forward the SDK identity header.