Update auto instrument langchain support#153
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the LangChain auto-instrumentation to work with langchain_core>=1.2.0 and to ensure that gen-AI input/output attributes emitted from LangChain traces conform to the expected string / string-list patterns, including new support for invoke-agent style spans coming from LangGraph.
Changes:
- Adjusts
input_messagesandoutput_messagesinutils.pyto emit JSON-serialized arrays of message contents, ensuringgen_ai.input.messages/gen_ai.output.messagesare strings (JSON) produced from string lists. - Enhances tool-related telemetry extraction in
utils.py(including explicit execute-tool operation naming, tool call IDs, arguments, and results) and adds helpers for invoke-agent spans (invoke_agent_input_message,invoke_agent_output_message,set_execution_type, and improved operation-type mapping). - Updates tracer behavior in
tracer.pyto customize span naming for tools and invoke-agent/LangGraph chains and to route invoke-agent spans through the new helpers, and tightens the instrumentor dependency intracer_instrumentor.pytolangchain_core >= 1.2.0.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
libraries/microsoft-agents-a365-observability-extensions-langchain/microsoft_agents_a365/observability/extensions/langchain/utils.py |
Refactors message extraction to emit JSON string arrays, enriches tool call attributes (including results), adds invoke-agent message helpers and execution type tagging, and extends operation-type mapping for execute_tool and invoke_agent spans. |
libraries/microsoft-agents-a365-observability-extensions-langchain/microsoft_agents_a365/observability/extensions/langchain/tracer_instrumentor.py |
Narrows the instrumentation dependency to langchain_core >= 1.2.0 to match and enforce the new LangChain API expectations. |
libraries/microsoft-agents-a365-observability-extensions-langchain/microsoft_agents_a365/observability/extensions/langchain/tracer.py |
Adjusts span naming for tool and LangGraph (invoke_agent) runs and switches span enrichment to use the new invoke-agent helpers and updated message/tool extraction utilities. |
...ility-extensions-langchain/microsoft_agents_a365/observability/extensions/langchain/utils.py
Show resolved
Hide resolved
...ility-extensions-langchain/microsoft_agents_a365/observability/extensions/langchain/utils.py
Show resolved
Hide resolved
...ility-extensions-langchain/microsoft_agents_a365/observability/extensions/langchain/utils.py
Show resolved
Hide resolved
|
Where gen_ai.conversation.id is set? same question for other attributes like gen_ai.channel.name. |
|
instrumentationScope is useful to check if the trace is auto instrument or manual instrument. But it is not in the output. |
This is set as a baggage property on the sample app I am using. |
Can you share what you mean by instrumentation scope? is it a scope langchain creates in nodejs? |
|
"gen_ai.tool.arguments": "{'expression': '15 % 4'}" not a valid json output. |

Task
Update auto instrumentation. Ensure input and output attributes are string or string list.
Solution
Verified against v1.2.0 langchain