feat(langchain): add tool, retriever E2E tests and changelog [5/5]#4454
feat(langchain): add tool, retriever E2E tests and changelog [5/5]#4454nagkumar91 wants to merge 5 commits intoopen-telemetry:mainfrom
Conversation
…nt recording modules Add foundation modules for enhanced LangChain GenAI semantic convention tracing: - semconv_attributes.py: Per-operation attribute matrix based on OTel GenAI semantic conventions. Single source of truth for which attributes apply to which operations (chat, text_completion, invoke_agent, execute_tool, invoke_workflow, retrieval). - operation_mapping.py: Callback-to-semconv operation mapping. Maps each LangChain callback to the correct GenAI semantic convention operation name. Includes heuristic classification for on_chain_start callbacks (agents vs workflows vs internal plumbing) and LangGraph marker recognition. - content_recording.py: Thin integration layer over the shared genai content capture utilities. Provides clear APIs for the callback handler to decide what content should be recorded on spans and events. Part 1 of a series breaking down open-telemetry#4389 into smaller reviewable PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…propagation utilities Add utility modules for the LangChain instrumentor: - utils.py: Provider name inference from LangChain callback data (ls_provider, base_url, class name, endpoint fields), server address/port extraction, and W3C trace context header extraction and propagation support. - message_formatting.py: Message, tool, and document serialization with content-redaction support. Converts LangChain message objects into the compact JSON format expected by OpenTelemetry GenAI semantic conventions. Part 2 of a series breaking down open-telemetry#4389 into smaller reviewable PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enhance the span lifecycle manager and add event emission for non-LLM GenAI operations: - span_manager.py: Enhanced with ignored-run walkthrough (re-parenting children of skipped internal runs), per-thread agent stacks for hierarchy tracking, token usage accumulation and propagation to parent agent spans, and LangGraph Command(goto=...) transition support. - event_emitter.py: Emits semantic-convention-aligned log-record events for tool, agent, and retriever spans. All event emission is gated behind the content policy. Uses LogRecord instances linked to the active span context. Part 3 of a series breaking down open-telemetry#4389 into smaller reviewable PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…h wiring Wire all foundation modules into the callback handler and add comprehensive callback implementations: - callback_handler.py: Enhanced with model start/end/error (improved provider and server inference), chain start/end/error (with operation classification), agent action/finish, LLM new token (streaming chunk timing metrics), tool start/end/error, and retriever start/end/error callbacks. - __init__.py: Wire SpanManager, EventEmitter, and tracer into the instrumentor's _instrument method. - conftest.py: Updated test infrastructure for enhanced callback testing. Part 4 of a series breaking down open-telemetry#4389 into smaller reviewable PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add remaining test coverage for the LangChain enhanced tracing: - test_tool_callbacks.py: Tool start/end/error callbacks, content redaction, tool definitions formatting, event emission - test_retriever_callbacks.py: Retriever start/end/error callbacks, document serialization, query capture, content redaction - test_e2e_scenarios.py: End-to-end scenarios covering multi-step agent workflows, nested chains, concurrent execution, error propagation Update CHANGELOG.md with the enhancement entry. Part 5 (final) of a series breaking down open-telemetry#4389 into smaller reviewable PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| agent_name: str, | ||
| output_messages: Optional[str] = None, | ||
| ) -> None: | ||
| """Emit a ``gen_ai.agent.end`` event when an agent completes.""" |
There was a problem hiding this comment.
where do these conventions come from?
| ) | ||
|
|
||
| with self._lock: | ||
| self._spans[rid] = record |
There was a problem hiding this comment.
is there a way to write this instrumentation without accumulating state? can it be monkey-patching as usual that relies on genai-utils instead of relying on callback mechanism from langchain ? callback mechanism can never work properly with distributed tracing (context management, accumulating state, not getting proper signals when things fail or get cancelled). It's unrealistic to build anything long-term based on it and we'll need to rewrite it from scratch at some point.
I'd suggest this is the time to rewrite it to use monkey-patching and abandon any prior art langsmith put into it.
lmolkova
left a comment
There was a problem hiding this comment.
it seems this PR uses some unknown conventions and should be converted to draft for the time being. We also need to discuss if state accumulation and callback is the right path going forward and if we can do something better.
Description
Add remaining test coverage for the enhanced LangChain tracing and update the changelog.
Tests
test_tool_callbacks.pytest_retriever_callbacks.pytest_e2e_scenarios.pyChangelog
Updated
CHANGELOG.mdwith the enhancement entry for the full series.PR Series
This is PR 5 of 5 (final) breaking down #4389:
Depends on: #4453 (merge first)
Type of change
Checklist