Class: Aws::Plugins::ClientMetricsPlugin::Handler Private

Inherits:
Seahorse::Client::Handler show all
Defined in:
lib/aws-sdk-core/plugins/client_metrics_plugin.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary

Attributes inherited from Seahorse::Client::Handler

#handler

Instance Method Summary collapse

Methods inherited from Seahorse::Client::Handler

#initialize, #inspect

Constructor Details

This class inherits a constructor from Seahorse::Client::Handler

Instance Method Details

#call(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/aws-sdk-core/plugins/client_metrics_plugin.rb', line 124

def call(context)
  publisher = context.config.client_side_monitoring_publisher
  service_id = context.config.api.["serviceId"]
  # serviceId not present in all versions, need a fallback
  service_id ||= _calculate_service_id(context)

  request_metrics = ClientSideMonitoring::RequestMetrics.new(
    service: service_id,
    operation: context.operation.name,
    client_id: context.config.client_side_monitoring_client_id,
    region: context.config.region,
    timestamp: DateTime.now.strftime('%Q').to_i,
  )
  context.[:client_metrics] = request_metrics
  start_time = Aws::Util.monotonic_milliseconds
  final_error_retryable = false
  final_aws_exception = nil
  final_aws_exception_message = nil
  final_sdk_exception = nil
  final_sdk_exception_message = nil
  begin
    @handler.call(context)
  rescue StandardError => e
    # Handle SDK Exceptions
    inspector = Retries::ErrorInspector.new(
      e,
      context.http_response.status_code
    )
    if inspector.retryable?(context)
      final_error_retryable = true
    end
    if request_metrics.api_call_attempts.empty?
      attempt = request_metrics.build_call_attempt
      attempt.sdk_exception = e.class.to_s
      attempt.sdk_exception_msg = e.message
      request_metrics.add_call_attempt(attempt)
    elsif request_metrics.api_call_attempts.last.aws_exception.nil?
      # Handle exceptions during response handlers
      attempt = request_metrics.api_call_attempts.last
      attempt.sdk_exception = e.class.to_s
      attempt.sdk_exception_msg = e.message
    elsif !e.class.to_s.match(request_metrics.api_call_attempts.last.aws_exception)
      # Handle response handling exceptions that happened in addition to
      # an AWS exception
      attempt = request_metrics.api_call_attempts.last
      attempt.sdk_exception = e.class.to_s
      attempt.sdk_exception_msg = e.message
    end # Else we don't have an SDK exception and are done.
    final_attempt = request_metrics.api_call_attempts.last
    final_aws_exception = final_attempt.aws_exception
    final_aws_exception_message = final_attempt.aws_exception_msg
    final_sdk_exception = final_attempt.sdk_exception
    final_sdk_exception_message = final_attempt.sdk_exception_msg
    raise e
  ensure
    end_time = Aws::Util.monotonic_milliseconds
    complete_opts = {
      latency: end_time - start_time,
      attempt_count: context.retries + 1,
      user_agent: context.http_request.headers["user-agent"],
      final_error_retryable: final_error_retryable,
      final_http_status_code: context.http_response.status_code,
      final_aws_exception: final_aws_exception,
      final_aws_exception_message: final_aws_exception_message,
      final_sdk_exception: final_sdk_exception,
      final_sdk_exception_message: final_sdk_exception_message
    }
    if context.[:redirect_region]
      complete_opts[:region] = context.[:redirect_region]
    end
    request_metrics.api_call.complete(complete_opts)
    # Report the metrics by passing the complete RequestMetrics object
    if publisher
      publisher.publish(request_metrics)
    end # Else we drop all this on the floor.
  end
end