Skip to content
10 changes: 9 additions & 1 deletion gems/smithy-client/lib/smithy-client/pageable_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def next_page(params = {})
raise LastPageError, self if last_page?

params = next_page_params(params)
context.client.send(context.operation_name, params)
with_metric { context.client.send(context.operation_name, params) }
end

# Yields the current and each following response to the given block.
Expand Down Expand Up @@ -133,6 +133,14 @@ def next_page_params(params)
new_params = context.params.except(*prev_tokens)
new_params.merge!(@paginator.next_tokens(data).merge(params))
end

def with_metric(&block)
Thread.current[:aws_sdk_core_user_agent_metric] ||= []
Comment thread
mullermp marked this conversation as resolved.
Outdated
Thread.current[:aws_sdk_core_user_agent_metric] << 'C'
block.call
ensure
Thread.current[:aws_sdk_core_user_agent_metric].pop
end
end
end
end
13 changes: 12 additions & 1 deletion gems/smithy-client/lib/smithy-client/plugins/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ class Protocol < Plugin
class BuildHandler < Handler
def call(context)
context.config.protocol.build_request(context)
@handler.call(context)
with_metric(context.config.protocol) { @handler.call(context) }
end

def with_metric(protocol, &block)
metric = protocol.is_a?(Smithy::Client::RPCv2CBOR::Protocol) ? 'M' : nil
return block.call unless metric

Thread.current[:smithy_ruby_user_agent_metric] ||= []
Thread.current[:smithy_ruby_user_agent_metric] << metric
block.call
ensure
Comment thread
mullermp marked this conversation as resolved.
Outdated
Thread.current[:smithy_ruby_user_agent_metric].pop
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def call(context)
end
end
end
@handler.call(context)
with_metric(selected_encoding) { @handler.call(context) }
end

private
Expand Down Expand Up @@ -149,6 +149,17 @@ def update_content_encoding(encoding, context)
end
end

def with_metric(encoding, &block)
metric = encoding == 'gzip' ? 'L' : nil
return block.call unless metric

Thread.current[:smithy_ruby_user_agent_metric] ||= []
Thread.current[:smithy_ruby_user_agent_metric] << metric
block.call
ensure
Thread.current[:smithy_ruby_user_agent_metric].pop
end

# @api private
class GzipIO
def initialize(body)
Expand Down
14 changes: 14 additions & 0 deletions gems/smithy-client/lib/smithy-client/plugins/retry_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ def reset_response(context, response)
context.http_response.reset
response.error = nil
end

def with_metric(retry_strategy, &block)
metric = case retry_strategy
when Retry::Standard then 'E'
when Retry::Adaptive then 'F'
else return block.call
end

Thread.current[:smithy_ruby_user_agent_metric] ||= []
Thread.current[:smithy_ruby_user_agent_metric] << metric
block.call
ensure
Thread.current[:smithy_ruby_user_agent_metric].pop if metric
end
end

handler(Handler, step: :retry)
Expand Down
10 changes: 9 additions & 1 deletion gems/smithy-client/lib/smithy-client/waiters/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call(client, params)
@input = params
request = client.build_request(@operation_name, params)
request.handlers.remove(Plugins::RaiseResponseErrors::Handler)
response = request.send_request
response = with_metric { request.send_request }
status = evaluate_acceptors(response)
[response, status.to_sym]
end
Expand Down Expand Up @@ -87,6 +87,14 @@ def anyStringEquals?(actual, expected)
actual.any? { |value| value == expected }
end
# rubocop:enable Naming/MethodName

def with_metric (&block)
Thread.current[:smithy_ruby_user_agent_metric] ||= []
Thread.current[:smithy_ruby_user_agent_metric] << 'B'
Comment thread
mullermp marked this conversation as resolved.
Outdated
block.call
ensure
Thread.current[:smithy_ruby_user_agent_metric].pop
end
end
end
end
Expand Down
Loading