Skip to content

perf: skip discarded trace payload construction - #2463

Open
rosetta-livekit-bot[bot] wants to merge 3 commits into
mainfrom
clergies-cleanse-hurtling
Open

perf: skip discarded trace payload construction#2463
rosetta-livekit-bot[bot] wants to merge 3 commits into
mainfrom
clergies-cleanse-hurtling

Conversation

@rosetta-livekit-bot

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Ports livekit/agents#7155.

Avoid constructing GenAI input/output payloads when spans are not recording or content capture is disabled. Preserve non-content request, response, usage, and legacy trace attributes, and avoid telemetry-only response accumulation when content will be discarded.

Source diff coverage
  • livekit-agents/livekit/agents/llm/llm.py: adapted to agents/src/llm/llm.ts. Snapshot span recording/content-capture state at llm_request start, skip eager request/output builders, and skip telemetry-only response accumulation. The target lacked Python's existing capture-state getter, so agents/src/telemetry/gen_ai.ts adds captureContentEnabled() and agents/etc/agents.api.md records the public API.
  • livekit-agents/livekit/agents/voice/generation.py: adapted to agents/src/voice/generation.ts. Guard legacy chat/tool serialization on span recording and uninstrumented GenAI content builders on recording plus capture enablement.
  • tests/test_llm_telemetry.py: adapted across agents/src/llm/llm.test.ts and agents/src/voice/generation_telemetry.test.ts to match target test organization. All source-added/modified cases are covered: cached-token/content attributes, capture toggles, disabled/nonrecording stream payload construction and accumulation, nonrecording llm_node serialization, and disabled-capture non-content attributes.
  • Not applicable: none.

Validation

  • pnpm test agents (2,514 passed, 5 skipped)
  • pnpm build
  • pnpm lint (passes with pre-existing repository warnings)
  • pnpm format:check
  • pnpm --filter @livekit/agents typecheck
  • pnpm --filter @livekit/agents api:check

cue-cli runtime validation was attempted after the full build, but the configured LiveKit environment rejected worker authentication with HTTP 401, so no framework-event run could be completed.

A minor changeset is included for the new public genAI.captureContentEnabled() API.


Ported from livekit/agents#7155

Original PR description

Tracing builds large chat and GenAI payloads before OpenTelemetry decides to discard them. Check span recording and content capture first, while retaining legacy chat context, recorded content, and non-content metrics.

A 1,000-message sampled-out llm_node drops from 4.1 ms to 84 µs locally.

Addresses AGT-3452

Initial prompt and agent context

Model: GPT-5.6

can you investigate linear AGT 3452?

sounds good, let's fix that with a draft PR first.

@rosetta-livekit-bot
rosetta-livekit-bot Bot requested a review from a team as a code owner September 9, 2026 10:58
@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 427337c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 38 packages
Name Type
@livekit/agents Minor
@livekit/agents-plugin-anam Minor
@livekit/agents-plugin-anthropic Minor
@livekit/agents-plugin-assemblyai Minor
@livekit/agents-plugin-azure Minor
@livekit/agents-plugin-baseten Minor
@livekit/agents-plugin-bey Minor
@livekit/agents-plugin-cartesia Minor
@livekit/agents-plugin-cerebras Minor
@livekit/agents-plugin-deepgram Minor
@livekit/agents-plugin-did Minor
@livekit/agents-plugin-elevenlabs Minor
@livekit/agents-plugin-fishaudio Minor
@livekit/agents-plugin-google Minor
@livekit/agents-plugin-hume Minor
@livekit/agents-plugin-inworld Minor
@livekit/agents-plugin-krisp Minor
@livekit/agents-plugin-lemonslice Minor
@livekit/agents-plugin-liveavatar Minor
@livekit/agents-plugin-livekit Minor
@livekit/agents-plugin-minimax Minor
@livekit/agents-plugin-mistral Minor
@livekit/agents-plugin-mistralai Minor
@livekit/agents-plugin-neuphonic Minor
@livekit/agents-plugin-openai Minor
@livekit/agents-plugin-perplexity Minor
@livekit/agents-plugin-phonic Minor
@livekit/agents-plugin-protoface Minor
@livekit/agents-plugin-resemble Minor
@livekit/agents-plugin-rime Minor
@livekit/agents-plugin-runway Minor
@livekit/agents-plugin-sarvam Minor
@livekit/agents-plugin-silero Minor
@livekit/agents-plugin-soniox Minor
@livekit/agents-plugin-tavus Minor
@livekit/agents-plugins-test Minor
@livekit/agents-plugin-trugen Minor
@livekit/agents-plugin-xai Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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.

0 participants