@@ -223,6 +223,35 @@ func TestIntegrationToolCallError(t *testing.T) {
223223 assert .Contains (t , toolSpan .Meta , "input" )
224224}
225225
226+ func TestWithTracingWithCustomHooks (t * testing.T ) {
227+ tt := testTracer (t )
228+ defer tt .Stop ()
229+
230+ customHookCalled := false
231+ customHooks := & server.Hooks {}
232+ customHooks .AddBeforeInitialize (func (ctx context.Context , id any , request * mcp.InitializeRequest ) {
233+ customHookCalled = true
234+ })
235+
236+ srv := server .NewMCPServer ("test-server" , "1.0.0" ,
237+ WithTracing (& TracingConfig {Hooks : customHooks }))
238+
239+ ctx := context .Background ()
240+ initRequest := `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}`
241+
242+ response := srv .HandleMessage (ctx , []byte (initRequest ))
243+ assert .NotNil (t , response )
244+
245+ assert .True (t , customHookCalled , "custom hook should have been called" )
246+
247+ spans := tt .WaitForLLMObsSpans (t , 1 )
248+ require .Len (t , spans , 1 )
249+
250+ taskSpan := spans [0 ]
251+ assert .Equal (t , "mcp.initialize" , taskSpan .Name )
252+ assert .Equal (t , "task" , taskSpan .Meta ["span.kind" ])
253+ }
254+
226255// Test helpers
227256
228257// testTracer creates a testtracer with LLMObs enabled for integration tests
0 commit comments