diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /lib/error_tracking/sentry_client.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'lib/error_tracking/sentry_client.rb')
-rw-r--r-- | lib/error_tracking/sentry_client.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/error_tracking/sentry_client.rb b/lib/error_tracking/sentry_client.rb index 6a341ddbe86..029389ab5d6 100644 --- a/lib/error_tracking/sentry_client.rb +++ b/lib/error_tracking/sentry_client.rb @@ -10,16 +10,32 @@ module ErrorTracking Error = Class.new(StandardError) MissingKeysError = Class.new(StandardError) + ResponseInvalidSizeError = Class.new(StandardError) + + RESPONSE_SIZE_LIMIT = 1.megabyte attr_accessor :url, :token - def initialize(api_url, token) + def initialize(api_url, token, validate_size_guarded_by_feature_flag: false) @url = api_url @token = token + @validate_size_guarded_by_feature_flag = validate_size_guarded_by_feature_flag + end + + def validate_size_guarded_by_feature_flag? + @validate_size_guarded_by_feature_flag end private + def validate_size(response) + return if Gitlab::Utils::DeepSize.new(response, max_size: RESPONSE_SIZE_LIMIT).valid? + + limit = ActiveSupport::NumberHelper.number_to_human_size(RESPONSE_SIZE_LIMIT) + message = "Sentry API response is too big. Limit is #{limit}." + raise ResponseInvalidSizeError, message + end + def api_urls @api_urls ||= SentryClient::ApiUrls.new(@url) end @@ -86,6 +102,8 @@ module ErrorTracking def handle_response(response) raise_error "Sentry response status code: #{response.code}" unless response.code.between?(200, 204) + validate_size(response.parsed_response) if validate_size_guarded_by_feature_flag? + { body: response.parsed_response, headers: response.headers } end |