ruby-sdk/lib/model_context_protocol/instrumentation.rb
Topher Bullock d2b6a33788 Internal Release 0.5.1
- Allow protocol version to be set at the server level through configuration instead of a class method, providing more flexibility in protocol version management [#43](https://github.com/Shopify/mcp-ruby/pull/43) @topherbullock

- Fixed instrumentation handling to ensure accurate timing information and proper error reporting [#42](https://github.com/Shopify/mcp-ruby/pull/42) @tobiasbales
  - Improved error handling and reporting in the server
  - Fixed timing information collection in instrumentation
  - Added proper error types for different failure scenarios
  - Enhanced test coverage for error cases

- [Allow protocol version to be set at the server level #43](https://github.com/Shopify/mcp-ruby/pull/43) @topherbullock
- [Fix instrumentation handling #42](https://github.com/Shopify/mcp-ruby/pull/42) @tobiasbales
2025-05-08 17:38:05 -04:00

26 lines
671 B
Ruby

# frozen_string_literal: true
module ModelContextProtocol
module Instrumentation
def instrument_call(method, &block)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
begin
@instrumentation_data = {}
add_instrumentation_data(method:)
result = yield block
result
ensure
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
add_instrumentation_data(duration: end_time - start_time)
configuration.instrumentation_callback.call(@instrumentation_data)
end
end
def add_instrumentation_data(**kwargs)
@instrumentation_data.merge!(kwargs)
end
end
end