From 02411d309b7d8dcc48ff0e989419b30b8ef9cc50 Mon Sep 17 00:00:00 2001 From: Manu Vasconcelos <87862340+vasconsaurus@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:54:38 -0300 Subject: [PATCH] send facebook response with exception message (#395) We are not sure how this will affect issue grouping in Sentry, but want to test it out. It's important to be able to access the facebook error data. --- app/models/metrics.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/metrics.rb b/app/models/metrics.rb index 438ef481..09583670 100644 --- a/app/models/metrics.rb +++ b/app/models/metrics.rb @@ -97,21 +97,22 @@ def verify_facebook_metrics_response(url, response) error = JSON.parse(response.body)['error'] is_retryable = (RETRYABLE_FACEBOOK_ERROR_CODES + FACEBOOK_RATE_LIMIT_CODES).include?(error['code'].to_i) + fb_error_hash = { + 'app.api_key' => ApiKey.current&.id, + 'facebook.metrics.error.code' => error['code'], + 'facebook.metrics.error.message' => error['message'], + 'facebook.metrics.url' => url, + 'facebook.metrics.retryable' => is_retryable + } Rails.logger.warn level: 'WARN', message: "Facebook metrics error: #{error['code']} - #{error['message']}", url: url, key_id: ApiKey.current&.id, error: error, retryable: is_retryable TracingService.set_error_status( "Facebook metrics error", - attributes: { - 'app.api_key' => ApiKey.current&.id, - 'facebook.metrics.error.code' => error['code'], - 'facebook.metrics.error.message' => error['message'], - 'facebook.metrics.url' => url, - 'facebook.metrics.retryable' => is_retryable - } + attributes: fb_error_hash ) if is_retryable @locker.lock(3600) if FACEBOOK_RATE_LIMIT_CODES.include?(error['code'].to_i) - raise Pender::Exception::RetryLater, 'Metrics request failed' + raise Pender::Exception::RetryLater, "Metrics request failed.\n#{fb_error_hash.to_json}" end end