Skip to content

Conversation

@bml1g12
Copy link
Contributor

@bml1g12 bml1g12 commented Oct 7, 2025

This PR extends the recent addition of TTFT metrics to Realtime API kindly provided by @longcw #3507 to allow LangFuse to natively parse this data, as currently it is not possible to Dashboard or filter on TTFT.

This PR makes two changes:

  • Expose TTFT to LangFuse via the ATTR_LANGFUSE_COMPLETION_START_TIME = "langfuse.observation.completion_start_time" namespace, similarly to how in the codebase we already do for regular non-realtime LLMs.
    • LangFuse themselves calculate TTFT from the span start timestamp and the first token timestamp provided through ATTR_LANGFUSE_COMPLETION_START_TIME. I have verified that as expected the Livekit reported TTFT matches the LangFuse reported TTFT here.
image

@bml1g12 bml1g12 marked this pull request as ready for review October 7, 2025 12:33
@bml1g12 bml1g12 changed the title feat(telemetry/utils): add ttft reporting feat(telemetry/utils): add ttft reporting to LangFuse Oct 7, 2025
# Langfuse only allows searching/filtering/graphing over fields if they are prefixes with this key OR
# which use a set of reserved keys like ATTR_GEN_AI and ATTR_LANGFUSE items above.
# so e.g. ATTR_LANGFUSE_SEARCHABLE_PREFIX + "foo" will allow `foo` to be a filterable attribute in langfuse.
ATTR_LANGFUSE_SEARCHABLE_PREFIX = "langfuse.trace.metadata."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used anywhere? if not it's better to not include it in the types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't think its useful reference for devs (i.e. to sign post you cannot assume simply adding an atrribute makes it useful for searching/graphing in langfuse)? This information was a little hard for me to find as a developer and surprising behaviour in LangFuse (that metadata attached to a trace is not searchable unless nested under very specific namespaces).

But OK I have removed it now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's langfuse should document this somewhere, we may not want to add too many platform-specific vars in the codebase.

@longcw longcw merged commit 29f190d into livekit:main Oct 10, 2025
9 checks passed
akshaym1shra pushed a commit to akshaym1shra/agents that referenced this pull request Oct 28, 2025
akshaym1shra pushed a commit to akshaym1shra/agents that referenced this pull request Oct 28, 2025
meetakshay99 added a commit to meetakshay99/agents that referenced this pull request Oct 30, 2025
* staging: (114 commits)
  Added min_confidence_threshold for deepgram flux.
  livekit-agents 1.2.15 (livekit#3658)
  fix livekit#3650 cartesia version backward compatibility (livekit#3651)
  Unprompted STT Reconnection at startup (livekit#3649)
  enable zero retention mode in elevenlabs (livekit#3647)
  fix: heartbeat (livekit#3648)
  feat: Integrate streaming endpoints for Sarvam APIs (livekit#3498)
  turn_detection: reduce max_endpointing_delay to 3s (livekit#3640)
  fix: exclude temperature parameter for gpt-5 and similar models (livekit#3573)
  add backwards compatibility for google's realtime model (livekit#3630)
  Align Google STT plugin with official documentation (livekit#3628)
  feat(speechmatics): add max_speakers parameter for speaker diarization (livekit#3524)
  fix(deepgram): send CloseStream message before closing TTS WebSocket (livekit#3608)
  chore: Remove duplicate docstring for `preemptive_generation` parameter in AgentSession (livekit#3624)
  Add RTZR(ReturnZero) STT Plugin for LiveKit Agents (livekit#3376)
  feat(telemetry/utils): add ttft reporting to LangFuse (livekit#3594)
  catch delete_room errors and disable delete_room_on_close by default (livekit#3600)
  lift google realtime api out of beta (livekit#3614)
  fix: lock pyav to <16 due to build issue (livekit#3593)
  Updating Cartesia Version (livekit#3570)
  ...
akshaym1shra pushed a commit to akshaym1shra/agents that referenced this pull request Nov 3, 2025
akshaym1shra pushed a commit to akshaym1shra/agents that referenced this pull request Nov 10, 2025
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.

2 participants