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
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