@@ -9,13 +9,16 @@ const test = require('node:test')
99const assert = require ( 'node:assert' )
1010
1111const { removeModules } = require ( '../../lib/cache-buster' )
12- const { assertSegments } = require ( '../../lib/custom-assertions' )
12+ const { assertSegments, match } = require ( '../../lib/custom-assertions' )
1313const createOpenAIMockServer = require ( '../openai/mock-server' )
1414const helper = require ( '../../lib/agent_helper' )
1515
1616const config = {
1717 ai_monitoring : {
18- enabled : true
18+ enabled : true ,
19+ streaming : {
20+ enabled : true
21+ }
1922 }
2023}
2124
@@ -80,24 +83,50 @@ test('should create span on successful CompiledStateGraph.invoke', async (t) =>
8083 const { agent, langgraphAgent } = t . nr
8184
8285 await helper . runInTransaction ( agent , async ( tx ) => {
83- let content
84- try {
85- const result = await langgraphAgent . invoke (
86- { messages : [ { role : 'user' , content : 'You are a scientist.' } ] }
87- )
88- content = result ?. messages ?. [ 1 ] ?. content ?? ''
89- } catch ( err ) {
90- assert . fail ( err )
91- }
86+ const result = await langgraphAgent . invoke (
87+ { messages : [ { role : 'user' , content : 'You are a scientist.' } ] }
88+ )
89+ const content = result ?. messages ?. [ 1 ] ?. content
9290 assert . equal ( content , '212 degrees Fahrenheit is equal to 100 degrees Celsius.' , 'should output correct content' )
93- assertSegments ( tx . trace , tx . trace . root , [ 'Llm/agent/LangGraph/invoke /LangGraphReactAgent' ] , {
91+ assertSegments ( tx . trace , tx . trace . root , [ 'Llm/agent/LangGraph/stream /LangGraphReactAgent' ] , {
9492 exact : false
9593 } )
9694
9795 tx . end ( )
9896 } )
9997} )
10098
99+ test ( 'should create LlmAgent event for CompiledStateGraph.invoke' , async ( t ) => {
100+ const { agent, langgraphAgent } = t . nr
101+
102+ await helper . runInTransaction ( agent , async ( tx ) => {
103+ const result = await langgraphAgent . invoke (
104+ { messages : [ { role : 'user' , content : 'You are a scientist.' } ] }
105+ )
106+ const content = result ?. messages ?. [ 1 ] ?. content
107+ assert . ok ( content )
108+ // Check for LlmAgent event
109+ const events = agent . customEventAggregator . events . toArray ( )
110+ const agentEvents = events . filter ( ( e ) => e [ 0 ] . type === 'LlmAgent' )
111+ assert . ok ( agentEvents . length > 0 )
112+
113+ const [ [ { type } , agentEvent ] ] = agentEvents
114+ assert . equal ( type , 'LlmAgent' )
115+ const [ segment ] = tx . trace . getChildren ( tx . trace . root . id )
116+
117+ match ( agentEvent , {
118+ id : / [ a - f 0 - 9 ] { 36 } / ,
119+ name : 'LangGraphReactAgent' ,
120+ span_id : segment . id ,
121+ trace_id : tx . traceId ,
122+ ingest_source : 'Node' ,
123+ vendor : 'langgraph'
124+ } )
125+
126+ tx . end ( )
127+ } )
128+ } )
129+
101130test ( 'should not create segment or events when ai_monitoring.enabled is false' , async ( t ) => {
102131 const { agent, langgraphAgent } = t . nr
103132
0 commit comments