Repository navigation
feat(celery): propagate context options to workers - #1207
Merged
Merged
Conversation
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>
5 of 6 tasks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eli-r-ph
marked this pull request as ready for review
November 8, 2026 03:20
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.
* 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>
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 Celery integration carried the distinct ID, session ID and tags to workers, but not context options. Options set with
set_context_optionbefore publishing a task were lost on the worker.Stacked on #1206.
X-POSTHOG-CONTEXT-OPTIONSheader, top level and nested, like the tags header.set_context_optionafter the tags and beforecelery task started. Missing, invalid or non-object JSON gives no options.propagate_context=Falsesends no options, like the other headers.propagate_contextdocstrings list context options. The migration guide notes the propagation, that a propagatedprocess_person_profile: Truecreates a person for each worker event without a distinct ID, and that eager mode publishes nothing.💚 How did you test it?
propagate_contextand invalid-JSON tests.Clientand the v1 payload. They cover all four options, an option against a legacy tag on the same key, legacy tags alone, context options against workersuper_options, a personlessprocess_person_profile: True, an override inside the task, missing, invalid, non-object and bytes headers, andpropagate_context=False.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 header name, placement and precedence were set by the maintainer. Options are propagated unfiltered, like tags.
🤖 Generated with Claude Code