Skip to content

docs(ai-observability): openai-agents identity goes per run, not on instrument() - #78493

Merged
trunk-io[bot] merged 3 commits into
masterfrom
marco/aio-openai-agents-per-run-docs
Aug 5, 2026
Merged

docs(ai-observability): openai-agents identity goes per run, not on instrument()#78493
trunk-io[bot] merged 3 commits into
masterfrom
marco/aio-openai-agents-per-run-docs

Conversation

@marco-g-pm

@marco-g-pm marco-g-pm commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Problem

The openai-agents installation docs pass distinct_id="user_123" and properties={"conversation_id": "abc123"} to instrument(). The tracing processor registers once per process, so those values are process-global — every user's runs in a server get stamped with the same identity and "conversation". Surfaced while testing wizard ai-observability on the wizard-workbench openai-agents test app: the wizard follows this page and produced events with no usable person attribution.

Change

No SDK changes needed — this uses the callable distinct_id resolver the released SDK already supports, wired once so every per-run value travels with the call:

instrument(
    client=posthog,
    # Resolves the user per run from RunConfig trace_metadata
    distinct_id=lambda trace: (trace.metadata or {}).get("posthog_distinct_id"),
)

result = Runner.run_sync(
    agent,
    prompt,
    run_config=RunConfig(
        group_id="conversation_abc",  # becomes $ai_session_id
        trace_metadata={"posthog_distinct_id": "user_123"},
    ),
)
  • instrument() example scoped to process-constant config, with an Identity scope callout: a static distinct_id string only when one process serves one user (CLI/worker).
  • Documents the group_id$ai_session_id mapping, which the page previously used without explaining.

🤖 Generated with Claude Code

…nstrument()

instrument() registers one process-global tracing processor, so the
distinct_id and per-conversation properties the example passed there
stamp every run in the process — wrong for any server. Show identity
and session per run via RunConfig (group_id -> $ai_session_id,
trace_metadata posthog_distinct_id / posthog_properties) and scope
instrument() to process-constant config.

Requires PostHog/posthog-python#833.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Aug 5, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

ℹ️ Docs preview — preview build triggered

Docs from this PR will be published at posthog.com.

Project Preview Updated (UTC)
posthog.com Open preview Aug 5, 2026, 6:04 PM

The preview should be ready in about 10 minutes. Open the preview at /handbook/engineering/.

@github-actions github-actions Bot added the docs Improvements or additions to documentation label Aug 5, 2026
@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
docs/onboarding/ai-observability/openai-agents.tsx:92-93
**Avoid em dashes in docs**

The new prose uses em dashes here and again on lines 103 and 120, introducing a punctuation pattern prohibited by the repository writing guide. Replace them with periods, commas, or parentheses.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "docs(ai-observability): openai-agents id..." | Re-trigger Greptile

Comment thread docs/onboarding/ai-observability/openai-agents.tsx Outdated
marco-g-pm and others added 2 commits August 5, 2026 13:56
…eeded

Per review: keep posthog-python as-is. The released SDK already resolves
a callable distinct_id per trace, so wire it once to read
posthog_distinct_id from each run's RunConfig trace_metadata. All
per-run values still travel with the call.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io
trunk-io Bot merged commit 6bbbc83 into master Aug 5, 2026
191 checks passed
@trunk-io
trunk-io Bot deleted the marco/aio-openai-agents-per-run-docs branch August 5, 2026 18:37
@deployment-status-posthog

deployment-status-posthog Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-08-05 19:06 UTC Run
prod-us ✅ Deployed 2026-08-05 19:22 UTC Run
prod-eu ✅ Deployed 2026-08-05 19:27 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants