Internal Release 0.3.0
Add configurable exception reporter Avoid leaking tool exceptions by sending them to a configurable exception reporter Add optional context to pass to tools Add basic instrumentation data/labels
This commit is contained in:
parent
f5a3567494
commit
0645351585
1 changed files with 359 additions and 39 deletions
24
lib/model_context_protocol/instrumentation.rb
Normal file
24
lib/model_context_protocol/instrumentation.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ModelContextProtocol
|
||||
module Instrumentation
|
||||
def instrument_call(method, &block)
|
||||
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
@instrumentation_data = {}
|
||||
add_instrumentation_data(method:)
|
||||
|
||||
result = yield block
|
||||
|
||||
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
add_instrumentation_data(duration: end_time - start_time)
|
||||
|
||||
ModelContextProtocol.configuration.instrumentation_callback.call(@instrumentation_data)
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def add_instrumentation_data(**kwargs)
|
||||
@instrumentation_data.merge!(kwargs)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue