Skip to content

feat(core): Instrument langgraph createReactAgent#20344

Draft
andreiborza wants to merge 1 commit intodevelopfrom
ab/langgraph-agents
Draft

feat(core): Instrument langgraph createReactAgent#20344
andreiborza wants to merge 1 commit intodevelopfrom
ab/langgraph-agents

Conversation

@andreiborza
Copy link
Copy Markdown
Member

This PR adds instrumentation for LangGraph's createReactAgent API.

It:

  • extracts agent name, LLM model, and tools from params
  • wraps compiled graph's invoke() with invoke_agent span
  • wraps tool invoke() with execute_tool spans (name, type, description, arguments, result per our new conventions)
  • injects LangChain callback handler + lc_agent_name metadata at invoke level for chat span creation and agent name propagation to all child spans
  • suppresses StateGraph.compile instrumentation inside createReactAgent to avoid duplicate spans

The LangChain callback handler was improved to:

  • read gen_ai.agent.name from metadata.lc_agent_name (this is a convention in newer versions of LangGraph createAgent so we took this over for our supported version)
  • suppresses chain and tool callback spans inside agent context to avoid duplicates with our direct instrumentation (based on metadata.loc_agent_name presence)
  • extracts tool definitions from extraParams in handleChatModelStart
  • supports OpenAI tool calls via message.tool_calls (not just Anthropic content scanning)
  • normalizes tool call format and use our new convention attributes
  • uses runName for tool name (set by LangChain's StructuredTool)

It exports:

  • instrumentCreateReactAgent from core, browser, cloudflare
  • New constants:
    • GEN_AI_TOOL_CALL_ARGUMENTS_ATTRIBUTE,
    • GEN_AI_TOOL_CALL_RESULT_ATTRIBUTE

Closes: #19372

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.78 kB - -
@sentry/browser - with treeshaking flags 24.27 kB - -
@sentry/browser (incl. Tracing) 43.61 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 45.32 kB - -
@sentry/browser (incl. Tracing, Profiling) 48.51 kB - -
@sentry/browser (incl. Tracing, Replay) 82.74 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.25 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 87.43 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 99.67 kB - -
@sentry/browser (incl. Feedback) 42.59 kB - -
@sentry/browser (incl. sendFeedback) 30.45 kB - -
@sentry/browser (incl. FeedbackAsync) 35.45 kB - -
@sentry/browser (incl. Metrics) 27.07 kB - -
@sentry/browser (incl. Logs) 27.2 kB - -
@sentry/browser (incl. Metrics & Logs) 27.89 kB - -
@sentry/react 27.53 kB - -
@sentry/react (incl. Tracing) 45.88 kB - -
@sentry/vue 30.61 kB - -
@sentry/vue (incl. Tracing) 45.45 kB - -
@sentry/svelte 25.8 kB - -
CDN Bundle 28.46 kB - -
CDN Bundle (incl. Tracing) 44.69 kB - -
CDN Bundle (incl. Logs, Metrics) 29.83 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 45.78 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.73 kB - -
CDN Bundle (incl. Tracing, Replay) 81.65 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 82.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 87.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 88.23 kB - -
CDN Bundle - uncompressed 83.12 kB - -
CDN Bundle (incl. Tracing) - uncompressed 133.64 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 137.05 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 210.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 250.87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 254.27 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 263.78 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 267.17 kB - -
@sentry/nextjs (client) 48.42 kB - -
@sentry/sveltekit (client) 44.06 kB - -
@sentry/node-core 57.94 kB +0.02% +7 B 🔺
@sentry/node 175.67 kB +0.52% +893 B 🔺
@sentry/node - without tracing 97.89 kB +0.03% +22 B 🔺
@sentry/aws-serverless 115.12 kB +0.01% +9 B 🔺

View base workflow run

This PR adds instrumentation for LangGraph's `createReactAgent` API.

It:
- extracts agent name, LLM model, and tools from params
- wraps compiled graph's `invoke()` with invoke_agent span
- wraps tool `invoke()` with execute_tool spans (name, type,
  description, arguments, result per our new conventions)
- injects LangChain callback handler + `lc_agent_name` metadata
  at invoke level for chat span creation and agent name
  propagation to all child spans
- suppresses `StateGraph.compile` instrumentation inside
  `createReactAgent` to avoid duplicate spans

The LangChain callback handler was improved to:
- read gen_ai.agent.name from `metadata.lc_agent_name` (this is a convention in
  newer versions of LangGraph createAgent so we took this over for our supported
version)
- suppresses chain and tool callback spans inside agent context
  to avoid duplicates with our direct instrumentation (based on
`metadata.loc_agent_name` presence)
- extracts tool definitions from `extraParams` in `handleChatModelStart`
- supports OpenAI tool calls via `message.tool_calls` (not just
  Anthropic content scanning)
- normalizes tool call format and use our new convention attributes
- uses `runName` for tool name (set by LangChain's StructuredTool)

It exports:
- `instrumentCreateReactAgent` from core, browser, cloudflare
- New constants:
   - GEN_AI_TOOL_CALL_ARGUMENTS_ATTRIBUTE,
   - GEN_AI_TOOL_CALL_RESULT_ATTRIBUTE

Closes: #19372
@andreiborza andreiborza force-pushed the ab/langgraph-agents branch from 09a4132 to e2d8d45 Compare April 16, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(core): Instrument langgraph createReactAgent

1 participant