Repository navigation
feat(ai): take capture options in the AI integrations - #1208
Merged
eli-r-ph merged 4 commits intoNov 9, 2026
Merged
Conversation
Every AI wrapper method that takes posthog_properties also takes posthog_options, and the Gemini clients take it as a per-client default. LangChain's CallbackHandler and PostHogMiddleware, and the OpenAI Agents and Claude Agent SDK instrument() and processors, take options=. LangChain also reads posthog_options from run metadata. The wrappers never pass posthog_options to the provider. The options are sent as the event's own options, below the personless process_person_profile: False. A value that is not a dict is logged and ignored, and no options argument is passed when none are set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eli-r-ph
force-pushed
the
eli/v1-ai-posthog-options
branch
from
November 8, 2026 02:38
67e5ff7 to
0a65bf3
Compare
eli-r-ph
marked this pull request as ready for review
November 8, 2026 03:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marandaneto
approved these changes
Nov 9, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
eli-r-ph
added a commit
that referenced
this pull request
Nov 9, 2026
* feat(celery): propagate context options to workers Publish context options in an X-POSTHOG-CONTEXT-OPTIONS task header, next to the tags header, and set them as context options on the worker before the task started event. propagate_context=False sends none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(celery): point eager tasks to explicit PostHog headers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(ai): take capture options in the AI integrations (#1208) * feat(ai): take capture options in the AI integrations Every AI wrapper method that takes posthog_properties also takes posthog_options, and the Gemini clients take it as a per-client default. LangChain's CallbackHandler and PostHogMiddleware, and the OpenAI Agents and Claude Agent SDK instrument() and processors, take options=. LangChain also reads posthog_options from run metadata. The wrappers never pass posthog_options to the provider. The options are sent as the event's own options, below the personless process_person_profile: False. A value that is not a dict is logged and ignored, and no options argument is passed when none are set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): send LangChain exception events with the run's options Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(migration): simplify the 8.0 checklist and MCP hook note Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): pass exception options as a typed keyword Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
eli-r-ph
added a commit
that referenced
this pull request
Nov 9, 2026
* feat(mcp): add event_options to MCP capture calls and instrument The PostHogMCP capture_* methods and McpAnalytics.capture take a keyword-only event_options argument, and MCPAnalyticsOptions gains an event_options callback, called for the same events as event_properties. Per-call options win over the callback's key by key, and an event without an identity still always sends process_person_profile: False. A non-dict value is logged and ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(mcp): document MCP event_options Covers the per-call argument and the callback, why context options set inside a tool handler miss $mcp_tool_call, copying options in MCP before_send, and the options vs event_options split on PostHogMCP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(celery): propagate context options to workers (#1207) * feat(celery): propagate context options to workers Publish context options in an X-POSTHOG-CONTEXT-OPTIONS task header, next to the tags header, and set them as context options on the worker before the task started event. propagate_context=False sends none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(celery): point eager tasks to explicit PostHog headers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(ai): take capture options in the AI integrations (#1208) * feat(ai): take capture options in the AI integrations Every AI wrapper method that takes posthog_properties also takes posthog_options, and the Gemini clients take it as a per-client default. LangChain's CallbackHandler and PostHogMiddleware, and the OpenAI Agents and Claude Agent SDK instrument() and processors, take options=. LangChain also reads posthog_options from run metadata. The wrappers never pass posthog_options to the provider. The options are sent as the event's own options, below the personless process_person_profile: False. A value that is not a dict is logged and ignored, and no options argument is passed when none are set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): send LangChain exception events with the run's options Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(migration): simplify the 8.0 checklist and MCP hook note Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ai): pass exception options as a typed keyword Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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
The AI integrations had no way to set capture options per call or per integration. The only routes were
set_context_optionaround the call,super_optionsorbefore_send. This addsposthog_options, named so it does not clash with the Claude Agent SDK's ownoptions.Stacked on #1207.
posthog_propertiestakesposthog_options: OpenAI and Anthropic (chat, responses, parse, embeddings, streaming, sync and async), Gemini (generate, stream, embed), and the Claude Agent SDKquery()andPostHogClaudeSDKClient.posthog_optionsas a default for every call. A call's options win key by key, likeposthog_properties.CallbackHandlerandPostHogMiddleware, andinstrument()and the processors for OpenAI Agents and the Claude Agent SDK, takeoptions=. LangChain also reads aposthog_optionsrun-metadata key._capture_ai_eventsends the options as the event's own, so they beat context options andsuper_options. The personlessprocess_person_profile: Falseis applied last and always wins.optionsargument is passed when none are set.posthog_optionsto the provider.optionsargument" with the new arguments and an example. Docstrings on every new parameter.💚 How did you test it?
options;posthog_options;Falsebeats a userTrue, and an identified event keeps the user's values;optionskwarg when unset;instrument(), and the Claude Agent SDKquery(), processor andinstrument().PostHogClaudeSDKClientand the middleware.Clienttest shows per-call options beatset_context_optionandsuper_options.test_client.pypass. The full suite has three fork tests that also fail on macOS without this change.📝 Checklist
If releasing new changes
sampo addto generate a changeset file (minor changeset written by hand)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code, Claude Opus 5.5. The argument names, merge order and plumbing were set by the maintainer. The LangChain and Claude Agent SDK precedence copies their properties, where the integration-level value wins. LangChain's
$exceptionevents, sent withcapture_exception, do not get the options. That keeps this change inside the AI event path.🤖 Generated with Claude Code