fix(langfuse): redact observation exports - #86
Conversation
📝 WalkthroughEnglish
中文中文
WalkthroughLangfuse exporter observation values now use cached redaction across agent, LLM, tool, and workflow transformations. Truncation and fallback paths also redact values, with tests covering common secrets and long secret-bearing inputs. ChangesObservation redaction
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
a47d369 to
83e8ed4
Compare
bcb8d34 to
f9ff772
Compare
* platform: add multi-tenant contracts * platform/gateway: add text loop * platform/toolpolicy: add governance bridge * platform/channeladapter: add adapter outbox skeleton * platform/gateway: enqueue outbound handoff * platform/storagerouter: add storage routing contracts * platform/gateway: add session lease * platform: add gray routing helpers * platform: add tenant budget helpers * platform: validate storage migration modes * platform: validate audit policies * platform: validate audit records * platform: add capacity estimator * platform/channeladapter: replay dead letters * platform: populate audit record ids * platform: validate audit sink writes * platform: add usage record contracts * platform: add usage sink contracts * platform: add config version contracts * platform: select config version by session gray bucket * platform: add config version lifecycle helpers * platform: add usage summary contracts * platform: add audit query contracts * platform: add config version diff contracts * platform: add config gray status summary * platform: add operational action audit contracts * platform: add config cache invalidation contracts * platform: add secret rotation status contracts * platform: add backend migration status contracts * platform: add storage router status summary * platform: add config operation summary contracts * platform/toolpolicy: add approval summary contract * fix(platform): enforce binding ACL and redact outbox errors * fix(platform): redact gateway audit error reasons * fix(toolpolicy): enforce auditable policy identity * platform: harden identity and idempotency contracts * platform: tighten routing identity contracts * fix(platform): reconcile hardened contracts with gateway * platform: add budget decision audit contracts * platform/gateway: add minimum loop acceptance test * platform/gateway: add outbound dispatch acceptance test * platform/gateway: correlate audit trace ids * platform/gateway: add trace skeleton spans * platform/gateway: enable runner session trace * platform/gateway: add message event trace contract * feat(platform): mark tool call trace spans Adds safe platform tool-call trace contract spans. Independent re-review reported P0/P1 clear; CodeRabbit only reported a trivial test-helper nitpick. * feat(platform): trace memory search spans Adds safe memory search trace spans on the current memory.Reader boundary. Independent review reported P0/P1 clear; local focused validation and build passed. * feat(platform): trace memory write spans Adds safe memory write trace spans for add/update/delete/clear. Independent review reported P0/P1 clear; local focused validation and build passed. * feat(platform): mark summary create trace spans Adds summary-create trace contract markers for Redis/PostgreSQL summary creation spans. Independent review reported P0/P1 clear; local focused validation and build passed. * fix(platform): address CI checks * fix(platform): address CodeRabbit review feedback * fix(platform): bound in-memory sink records --------- Co-authored-by: xnlemon <xianingawa@gmail.com>
f9ff772 to
cff3ba8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
telemetry/langfuse/exporter_test.go (1)
954-996: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLong-secret regression only covers the tool path.
The truncate-before-redact leak this test guards against also applies to
truncateObservationInputMessages/truncateObservationOutputChoices(invoke-agent) andtruncateObservationLLMInput(chat) — different helper functions than thetruncateObservationJSONLeafValuespath exercised here viatransformExecuteTool.transformWorkflowshares the same helper so it's implicitly covered, but invoke-agent/chat are not.中文
本测试防范的“先截断后脱敏导致泄露”问题同样存在于 `truncateObservationInputMessages`/`truncateObservationOutputChoices`(invoke-agent)以及 `truncateObservationLLMInput`(chat)中,这些是与本测试通过 `transformExecuteTool` 覆盖的 `truncateObservationJSONLeafValues` 不同的辅助函数。`transformWorkflow` 共用同一辅助函数,因此已被隐式覆盖,但 invoke-agent/chat 路径尚未被覆盖。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@telemetry/langfuse/exporter_test.go` around lines 954 - 996, Add regression coverage for long-secret redaction before truncation in the invoke-agent and chat paths, specifically exercising truncateObservationInputMessages, truncateObservationOutputChoices, and truncateObservationLLMInput. Assert that full secrets and representative prefixes/suffixes are absent after transformation while the redaction marker remains, reusing the existing test setup and helpers where applicable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@telemetry/langfuse/exporter.go`:
- Around line 162-166: Remove the redundant redaction performed when exporting
values already produced by otelObservationInput/otelObservationOutput and
buildLLMObservationInput/buildLLMObservationOutput. Update observationStringKV
or the affected exporter calls so these pre-truncated inputs and outputs are
converted to attributes without invoking the redactor a second time, while
preserving existing attribute construction.
---
Nitpick comments:
In `@telemetry/langfuse/exporter_test.go`:
- Around line 954-996: Add regression coverage for long-secret redaction before
truncation in the invoke-agent and chat paths, specifically exercising
truncateObservationInputMessages, truncateObservationOutputChoices, and
truncateObservationLLMInput. Assert that full secrets and representative
prefixes/suffixes are absent after transformation while the redaction marker
remains, reusing the existing test setup and helpers where applicable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f2ce6f65-908b-4d0d-bb38-1f816afffee3
📒 Files selected for processing (2)
telemetry/langfuse/exporter.gotelemetry/langfuse/exporter_test.go
| newAttributes = append(newAttributes, observationStringKV(observationInput, *input)) | ||
| } | ||
| if output := otelObservationOutput(outputMessagesOTel); output != nil { | ||
| newAttributes = append(newAttributes, stringKV(observationOutput, *output)) | ||
| newAttributes = append(newAttributes, observationStringKV(observationOutput, *output)) | ||
| } |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check whether otelObservationInput/otelObservationOutput/buildLLMObservationInput/buildLLMObservationOutput
# internally call the self-redacting truncate* helpers.
rg -n -A 15 'func otelObservationInput|func otelObservationOutput|func buildLLMObservationInput|func buildLLMObservationOutput' telemetry/langfuse/exporter.goRepository: XnLemon/trpc-agent-go
Length of output: 1887
🏁 Script executed:
#!/bin/bash
# Inspect observationStringKV and the nearby transform helpers to see
# whether redaction happens again at the wrapper level.
rg -n -A 20 -B 5 'func observationStringKV|func transformExecuteTool|func transformWorkflow|truncateObservationInputMessages|truncateObservationOutputChoices|truncateObservationLLMInput|truncateObservationLLMResponse|truncateObservationJSONLeafValues' telemetry/langfuse/exporter.goRepository: XnLemon/trpc-agent-go
Length of output: 11768
Avoid double redaction on the export hot path.
otelObservationInput/otelObservationOutput and buildLLMObservationInput/buildLLMObservationOutput already pass through the truncateObservation* helpers, and observationStringKV redacts again. That repeats the same redactor work for every exported observation.
中文
`otelObservationInput`/`otelObservationOutput` 以及 `buildLLMObservationInput`/`buildLLMObservationOutput` 已经经过 `truncateObservation*` 处理,而 `observationStringKV` 会再次脱敏。这样会让每个导出的 observation 重复执行同一套 redactor 工作。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@telemetry/langfuse/exporter.go` around lines 162 - 166, Remove the redundant
redaction performed when exporting values already produced by
otelObservationInput/otelObservationOutput and
buildLLMObservationInput/buildLLMObservationOutput. Update observationStringKV
or the affected exporter calls so these pre-truncated inputs and outputs are
converted to attributes without invoking the redactor a second time, while
preserving existing attribute construction.
Objective
Close the Phase2 redaction gap where Langfuse observation input/output attributes could carry sensitive trace payloads.
Completed changes
Validation
Risks / limitations
Follow-up