@@ -68,8 +68,13 @@ func TestIntegrationSessionInitialize(t *testing.T) {
6868 srv := server .NewMCPServer ("test-server" , "1.0.0" ,
6969 server .WithHooks (hooks ))
7070
71- // Create initialize request
71+ // Create initialize request with session
7272 ctx := context .Background ()
73+ sessionID := "test-session-init"
74+ session := & mockSession {id : sessionID }
75+ session .Initialize ()
76+ ctx = srv .WithContext (ctx , session )
77+
7378 initRequest := `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}`
7479
7580 // Send initialize request
@@ -96,6 +101,9 @@ func TestIntegrationSessionInitialize(t *testing.T) {
96101 assert .Equal (t , "mcp.initialize" , taskSpan .Name )
97102 assert .Equal (t , "task" , taskSpan .Meta ["span.kind" ])
98103
104+ // Verify session ID tag is set
105+ assert .Contains (t , taskSpan .Tags , "mcp_session_id:test-session-init" )
106+
99107 // Verify input/output annotations exist
100108 assert .Contains (t , taskSpan .Meta , "input" )
101109 assert .Contains (t , taskSpan .Meta , "output" )
@@ -166,11 +174,16 @@ func TestIntegrationToolCallSuccess(t *testing.T) {
166174 session .Initialize ()
167175 ctx = srv .WithContext (ctx , session )
168176
177+ // Send initialize request first
178+ initRequest := `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}`
179+ response := srv .HandleMessage (ctx , []byte (initRequest ))
180+ assert .NotNil (t , response )
181+
169182 // Create the actual MCP tools/call request as JSON
170183 toolCallRequest := `{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"calculator","arguments":{"operation":"add","x":5,"y":3}}}`
171184
172185 // Call the actual MCP server's HandleMessage method
173- response : = srv .HandleMessage (ctx , []byte (toolCallRequest ))
186+ response = srv .HandleMessage (ctx , []byte (toolCallRequest ))
174187 assert .NotNil (t , response )
175188
176189 // Marshal response to check it
@@ -184,17 +197,31 @@ func TestIntegrationToolCallSuccess(t *testing.T) {
184197 assert .Equal (t , "2.0" , resp ["jsonrpc" ])
185198 assert .NotNil (t , resp ["result" ])
186199
187- // Verify LLMObs tool span was created
188- spans := tt .WaitForLLMObsSpans (t , 1 )
189- require .Len (t , spans , 1 )
200+ // Verify LLMObs spans were created for both initialize and tool call
201+ spans := tt .WaitForLLMObsSpans (t , 2 )
202+ require .Len (t , spans , 2 )
203+
204+ // Find initialize and tool spans
205+ var initSpan , toolSpan * testtracer.LLMObsSpan
206+ for i := range spans {
207+ if spans [i ].Name == "mcp.initialize" {
208+ initSpan = & spans [i ]
209+ } else if spans [i ].Name == "calculator" {
210+ toolSpan = & spans [i ]
211+ }
212+ }
213+
214+ require .NotNil (t , initSpan , "initialize span not found" )
215+ require .NotNil (t , toolSpan , "tool span not found" )
216+
217+ // Verify both spans have the same session ID tag
218+ expectedTag := "mcp_session_id:test-session-123"
219+ assert .Contains (t , initSpan .Tags , expectedTag )
220+ assert .Contains (t , toolSpan .Tags , expectedTag )
190221
191- toolSpan := spans [0 ]
192222 assert .Equal (t , "calculator" , toolSpan .Name )
193223 assert .Equal (t , "tool" , toolSpan .Meta ["span.kind" ])
194224
195- // Verify session ID tag is set
196- assert .Contains (t , toolSpan .Tags , "mcp_session_id:test-session-123" )
197-
198225 // Verify input/output annotations exist
199226 assert .Contains (t , toolSpan .Meta , "input" )
200227 assert .Contains (t , toolSpan .Meta , "output" )
0 commit comments