feat(ai): map openai-agents groupId to $ai_session_id - #4335
Merged
Conversation
The Agents SDK groupId links traces from one conversation, which is what PostHog calls a session. It was only written to $ai_group_id, which nothing in AI observability reads, so grouped runs never appeared as sessions. $ai_group_id is still emitted so existing queries keep working.
Contributor
|
Reviews (1): Last reviewed commit: "fix(ai): map openai-agents groupId to $a..." | Re-trigger Greptile |
Contributor
Contributor
|
Size Change: +568 B (0%) Total Size: 17.9 MB 📦 View Changed
ℹ️ View Unchanged
|
marandaneto
approved these changes
Jul 30, 2026
Radu-Raicea
approved these changes
Jul 30, 2026
Member
|
@marco-g-pm we should replicate this in the Python SDK |
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.
Problem
The OpenAI Agents SDK's
groupIdis documented as a "grouping identifier to link multiple traces from the same conversation or process" — that is exactly a PostHog session. We were writing it only to$ai_session_id's near-namesake$ai_group_id, which nothing in AI observability reads, so grouped runs never showed up as sessions.groupIdis the only per-conversation channel this integration exposes (RunConfig({ groupId })/withTrace({ groupId })), and it's already read per trace and threaded into every span event — it just landed under a name with no consumer.Changes
Emit
$ai_session_idalongside the existing$ai_group_idat both assignment sites inpackages/ai/src/openai-agents/processor.ts—_baseProperties(every span event) and the$ai_traceevent. Both properties are set, so anything already querying$ai_group_idkeeps working.Same fix as PostHog/posthog-python#819.
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Opus 5). The naming bug surfaced in the Python SDK while auditing which AI integrations can carry a session id;
openai-agentsis the only integration in either SDK that reused the framework's own native field instead of a per-call properties channel, which is where the name drifted. Checked the rest ofpackages/ai—groupIdexists only in the OpenAI Agents SDK, so nothing else is affected.Started as a straight rename to match the Python change, then switched to emitting both names so existing
$ai_group_idqueries don't break.Extended the existing
includes group_id in trace eventstest to cover span events too, and to assert both properties. Verified it fails without the source change and passes with it; the fullpackages/ai/tests/openai-agents.test.tssuite passes (61 tests). No manual end-to-end run against a live agent.