Skip to content

fix(traces): include observation IO in legacy trace JSON download - #15451

Open
Souravrajvi0 wants to merge 3 commits into
langfuse:mainfrom
Souravrajvi0:feat/legacy-trace-download-io-9735
Open

fix(traces): include observation IO in legacy trace JSON download#15451
Souravrajvi0 wants to merge 3 commits into
langfuse:mainfrom
Souravrajvi0:feat/legacy-trace-download-io-9735

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Jul 26, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #15337

Legacy trace JSON downloads serialized observations from traces.byIdWithObservationsAndScores, which intentionally loads observations with includeIO: false and strips input/output for the lightweight trace detail view. The download button reused that payload client-side, so exported observations had input: null, output: null, and empty metadata even though the observation detail panel showed the full data.

Root cause

  • byIdWithObservationsAndScores queries ClickHouse with includeIO: false
  • The router then explicitly clears input and output on each observation before returning
  • Legacy download (!v4Beta) called downloadLegacyTraceAsJson({ trace, observations }) with that in-memory payload
  • V4 download already uses /api/traces/[traceId]/download, which loads full observation IO server-side

Proposed changes

  • web/src/server/api/routers/traces.ts: add optional includeObservationIO input; when true, query observations with includeIO: true and stringify IO for export
  • web/src/components/trace/components/_layout/TracePanelNavigationHeader.tsx: legacy download now fetches trace data with includeObservationIO: true before serializing JSON
  • web/src/features/traces/server/mapTraceDetailObservations.ts: extract observation mapping helper used by the trace router
  • web/src/__tests__/server/mapTraceDetailObservations.servertest.ts: ClickHouse integration coverage for the export path
  • web/src/features/traces/server/mapTraceDetailObservations.unit.test.ts: unit coverage for stripped vs exported observation IO

Impacted packages

  • web

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (tooling, dependencies, CI, workflows, repo upkeep, or other maintenance work)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (restructures existing code without changing behavior, e.g. simplify logic, split modules, reduce duplication)
  • This change requires a documentation update

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I have read the contributing guide
  • My code follows the style guidelines of this project (pnpm run format)
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked if my PR needs changes to the documentation
  • I have checked that my changes generate no new warnings (npm run lint)
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that new and existing unit tests pass locally with my changes

Testing

Verified on the local VM against running Docker infra (postgres, clickhouse, redis, minio):

cd /root/langfuse
source ~/.nvm/nvm.sh && nvm use 24
docker compose -f docker-compose.dev.yml up -d --wait

pnpm --filter web exec vitest run \
  src/features/traces/server/mapTraceDetailObservations.unit.test.ts \
  src/__tests__/server/mapTraceDetailObservations.servertest.ts

Results:

  • mapTraceDetailObservations.unit.test.ts: 2 passed
  • mapTraceDetailObservations.servertest.ts: 1 passed (writes to ClickHouse, verifies exported input, output, and metadata)

Manual verification still recommended in the UI:

  1. Open a trace with legacy mode enabled (v4 beta off)
  2. Click Download trace as JSON
  3. Confirm exported observations include the same input, output, and metadata shown in the observation detail panel

Legacy trace downloads serialized lightweight observations from the trace
detail query, which omitted input, output, and metadata. Fetch full
observation IO on download via includeObservationIO and add unit coverage.

Fixes langfuse#15337

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 26, 2026
@CLAassistant

CLAassistant commented Jul 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

bug-fix-mar-26 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: legacy trace JSON download omits observation input, output, and metadata

2 participants