Skip to content

feat(fi-core): spans with a session carry gen_ai.conversation.id - #813

Open
nik13 wants to merge 2 commits into
devfrom
feat/fi-core-conversation-id
Open

nik13 wants to merge 2 commits into
devfrom
feat/fi-core-conversation-id

Conversation

@nik13

@nik13 nik13 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Spans started by the FI tracer in @traceai/fi-core that carry session.id also carry gen_ai.conversation.id with the same value, unless the span sets that attribute itself. Traces can then be grouped by conversation from TypeScript, as they can from Python (which sets both from a session).

Why?

Python's using_session sets session.id and gen_ai.conversation.id; TypeScript set only session.id, so conversation grouping did not work for TypeScript apps.

The value is taken from the span's final session.id, after context attributes and the span's own attributes are merged, so the two match on every span. Spans that are not created by the FI tracer (for example application spans exported through an integration) do not get the attribute, so it does not appear where session.id is treated differently. The conversation id gets the same export privacy treatment as session.id (grouping-key exemption and withheld marker). On spans that are not created by the FI tracer, a gen_ai.conversation.id equal to that span's session.id is exported exactly as its session.id is, so the two values cannot differ in exposure.

In the Codex and Cursor integrations, child spans carry the same gen_ai.conversation.id as their root (the thread id or agent id), so one trace carries one conversation id.

How was it tested?

  • New src/__tests__/conversationId.test.ts: a session sets both; a span overriding session.id gets the overriding value; an explicit gen_ai.conversation.id is kept; setAttributes overrides are followed; no session sets neither; both stay equal after the export privacy filter, including with PII redaction.

  • Codex and Cursor wrapper tests: with an app session, the root and every child carry the same conversation id.

  • Updated exact-attribute expectations in startSpanContext.test.ts, fitracerStartSpanContext.test.ts, round6-boundary.test.ts and the traceai_openai inline snapshot; traceai_genkit asserts application spans carry no gen_ai.conversation.id.

  • Before/after counts with no new failures: fi-core jest (both otel lines), fi-core node tests, semantic conventions, openai (jest, contracts, gateway), genkit, auto (including its e2e test), codex, cursor, claude-agent, vercel, elevenlabs and google-genai suites. fi-core typecheck: 0 errors.

  • Unit tests added / updated (vitest/jest)

  • Integration tests pass (or N/A — no gateway behavior changed)

  • npm run typecheck / npm run lint all pass

  • Public types, env vars, or SDK behavior changes are documented (fi-core CHANGELOG)

Checklist

  • Commit messages follow Conventional Commits
  • No TODOs or commented-out code left in
  • No real API keys or secrets in the diff
  • If prose was added or changed: checked against docs/VOCABULARY.md

Notes for reviewers

Targets dev. The added attribute takes one slot of the span attribute count limit when a session is set.

Spans started by the FI tracer whose start attributes hold a non-empty
session.id also get gen_ai.conversation.id with the same value, unless the
span sets that key itself. The export boundary treats gen_ai.conversation.id
as a grouping key, like session.id, on spans made by an FI tracer.
…sation id follows session.id at export

On spans not made by an FI tracer, a gen_ai.conversation.id equal to the
span's raw session.id is exported exactly as that session.id is, so the two
keys get the same exposure.

Codex item spans and Cursor child spans set gen_ai.conversation.id to the
thread id or agent id that their root span uses, so every span in a trace
carries one conversation id, also when the app sets session.id.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant