fix(langchain): preserve error description on span status#4072
fix(langchain): preserve error description on span status#4072glogiotatidis wants to merge 1 commit intotraceloop:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSpan status setting in the LangChain OpenTelemetry callback was corrected to embed the exception message in the ChangesError Status Handling Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 6/8 reviews remaining, refill in 11 minutes and 21 seconds.Comment |
47447e0 to
ad68e02
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opentelemetry-instrumentation-langchain/tests/test_error_status.py`:
- Around line 38-52: The test is flakey because the session-scoped
InMemorySpanExporter (span_exporter) accumulates spans across tests; to isolate
this test call span_exporter.clear() at the start of the test_error_status
function (before the chain runs and before calling
span_exporter.get_finished_spans()) so get_finished_spans() only returns spans
produced by this test and the subsequent assertions on span.status.description
are reliable.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1d260691-e20a-4e39-80ba-55aea839ba52
📒 Files selected for processing (2)
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.pypackages/opentelemetry-instrumentation-langchain/tests/test_error_status.py
`Span.set_status(...)` per the OTel SDK contract silently drops the
`description` argument and emits a warning when the first argument is
already a `Status` object:
Description ... ignored. Use either `Status` or `(StatusCode, Description)`
`TraceloopCallbackHandler._handle_error` was calling
span.set_status(Status(StatusCode.ERROR), str(error))
so the human-readable error message was never set on the span's status,
and every callback error caused a warning to be logged from
`opentelemetry.sdk.trace`.
Pass the description inside `Status(...)` instead — matching the
canonical pattern used elsewhere in the openllmetry monorepo (see
PR traceloop#3970 for anthropic/groq/mistralai).
Adds `tests/test_error_status.py` as a regression test that pins the
behaviour: the span's status description equals the exception message,
and no `Description ... ignored` warning is emitted.
ad68e02 to
aab61fd
Compare
Span.set_status(...)per the OTel SDK contract silently drops thedescriptionargument and emits a warning when the first argument is already aStatusobject:TraceloopCallbackHandler._handle_errorwas callingso the human-readable error message was never set on the span's status, and every callback error caused a warning to be logged from
opentelemetry.sdk.trace.Pass the description inside
Status(...)instead — matching the canonical pattern used elsewhere in the openllmetry monorepo (see PR #3970 for anthropic/groq/mistralai).Adds
tests/test_error_status.pyas a regression test that pins the behaviour: the span's status description equals the exception message, and noDescription ... ignoredwarning is emitted.feat(instrumentation): ...orfix(instrumentation): ....Summary by CodeRabbit
Bug Fixes
Tests