File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ def instrument_call(method, &block)
88 @instrumentation_data = { }
99 add_instrumentation_data ( method : method )
1010
11+ result = yield block
12+
1113 if respond_to? ( :client ) && client
1214 add_instrumentation_data ( client : client )
1315 end
1416
15- result = yield block
16-
1717 result
1818 ensure
1919 end_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
Original file line number Diff line number Diff line change @@ -159,6 +159,53 @@ class ServerTest < ActiveSupport::TestCase
159159 assert_instrumentation_data ( { method : "initialize" } )
160160 end
161161
162+ test "#handle initialize request with clientInfo includes client in instrumentation data" do
163+ client_info = { name : "test_client" , version : "1.0.0" }
164+ request = {
165+ jsonrpc : "2.0" ,
166+ method : "initialize" ,
167+ id : 1 ,
168+ params : {
169+ clientInfo : client_info ,
170+ } ,
171+ }
172+
173+ @server . handle ( request )
174+ assert_instrumentation_data ( { method : "initialize" , client : client_info } )
175+ end
176+
177+ test "instrumentation data includes client info for subsequent requests after initialize" do
178+ client_info = { name : "test_client" , version : "1.0.0" }
179+ initialize_request = {
180+ jsonrpc : "2.0" ,
181+ method : "initialize" ,
182+ id : 1 ,
183+ params : {
184+ clientInfo : client_info ,
185+ } ,
186+ }
187+ @server . handle ( initialize_request )
188+
189+ ping_request = {
190+ jsonrpc : "2.0" ,
191+ method : "ping" ,
192+ id : 2 ,
193+ }
194+ @server . handle ( ping_request )
195+ assert_instrumentation_data ( { method : "ping" , client : client_info } )
196+ end
197+
198+ test "instrumentation data does not include client key when no clientInfo provided" do
199+ request = {
200+ jsonrpc : "2.0" ,
201+ method : "ping" ,
202+ id : 1 ,
203+ }
204+
205+ @server . handle ( request )
206+ assert_instrumentation_data ( { method : "ping" } )
207+ end
208+
162209 test "#handle returns nil for notification requests" do
163210 request = {
164211 jsonrpc : "2.0" ,
You can’t perform that action at this time.
0 commit comments