fix(langchain): keep objects out of association properties - #4467
fix(langchain): keep objects out of association properties#4467IdoGol24 wants to merge 2 commits into
Conversation
Metadata values reached span attributes through str(): any non-primitive was stringified, so an object's repr became the attribute value. A model, client or config object renders its constructor state, which routinely includes an API key, and association properties are copied onto every descendant span, so one such value spread across the whole trace. This path is also not gated by TRACELOOP_TRACE_CONTENT, so turning content capture off did not suppress it. Forward plain data only. Primitives are unchanged, lists keep their primitive elements, and a mapping is kept as JSON when every value in it is serializable (json.dumps with no default, so a mapping holding an object raises and the key is dropped). Anything else sanitizes to None and the key is dropped rather than recorded as a stringified object. Documented usage is unaffected: string and numeric labels such as user_id and session_id are primitives and still populate association properties.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughLangChain metadata sanitization now preserves plain values, serializes plain mappings, drops arbitrary objects, and omits dropped values from span attributes and association properties. Tests cover unit cases and end-to-end span export. ChangesLangChain metadata sanitization
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change sanitizes LangChain metadata before span export, retaining supported primitive data while omitting unsupported object values. No concrete merge-blocking risk is currently identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Metadata values reached span attributes through str(): any non-primitive was stringified, so an object's repr became the attribute value. A model, client or config object renders its constructor state, which routinely includes an API key, and association properties are copied onto every descendant span, so one such value spread across the whole trace. This path is also not gated by TRACELOOP_TRACE_CONTENT, so turning content capture off did not suppress it.
Forward plain data only. Primitives are unchanged, lists keep their primitive elements, and a mapping is kept as JSON when every value in it is serializable (json.dumps with no default, so a mapping holding an object raises and the key is dropped). Anything else sanitizes to None and the key is dropped rather than recorded as a stringified object.
Documented usage is unaffected: string and numeric labels such as user_id and session_id are primitives and still populate association properties.
feat(instrumentation): ...orfix(instrumentation): ....Summary by CodeRabbit
Bug Fixes
Tests