Class: Airbrake::SyncSender Private

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/airbrake-ruby/sync_sender.rb

Overview

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.

Responsible for sending data to Airbrake synchronously via PUT or POST methods. Supports proxies.

See Also:

Since:

  • v1.0.0

Constant Summary collapse

CONTENT_TYPE =

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

Returns body for HTTP requests.

Returns:

  • (String)

    body for HTTP requests

Since:

  • v1.0.0

'application/json'.freeze
BACKLOGGABLE_STATUS_CODES =

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

Returns response codes that are good to be backlogged.

Returns:

  • (Array<Integer>)

    response codes that are good to be backlogged

Since:

  • v6.2.0

[
  Response::BAD_REQUEST,
  Response::FORBIDDEN,
  Response::ENHANCE_YOUR_CALM,
  Response::REQUEST_TIMEOUT,
  Response::CONFLICT,
  Response::TOO_MANY_REQUESTS,
  Response::INTERNAL_SERVER_ERROR,
  Response::BAD_GATEWAY,
  Response::GATEWAY_TIMEOUT,
].freeze

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(method = :post) ⇒ SyncSender

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.

Returns a new instance of SyncSender.

Parameters:

  • method (Symbol) (defaults to: :post)

    HTTP method to use to send payload

Since:

  • v1.0.0



29
30
31
32
33
34
# File 'lib/airbrake-ruby/sync_sender.rb', line 29

def initialize(method = :post)
  @config = Airbrake::Config.instance
  @method = method
  @rate_limit_reset = Time.now
  @backlog = Backlog.new(self) if @config.backlog
end

Instance Method Details

#closevoid

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.

This method returns an undefined value.

Closes all the resources that this sender has allocated.

Since:

  • v6.2.0



68
69
70
# File 'lib/airbrake-ruby/sync_sender.rb', line 68

def close
  @backlog.close
end

#send(data, promise, endpoint = @config.error_endpoint) ⇒ Hash{String=>String}

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.

Sends a POST or PUT request to the given endpoint with the data payload.

Parameters:

  • data (#to_json)
  • endpoint (URI::HTTPS) (defaults to: @config.error_endpoint)

Returns:

  • (Hash{String=>String})

    the parsed HTTP response

Since:

  • v1.0.0



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/airbrake-ruby/sync_sender.rb', line 41

def send(data, promise, endpoint = @config.error_endpoint)
  return promise if rate_limited_ip?(promise)

  req = build_request(endpoint, data)
  return promise if missing_body?(req, promise)

  begin
    response = build_https(endpoint).request(req)
  rescue StandardError => ex
    reason = "#{LOG_LABEL} HTTP error: #{ex}"
    logger.error(reason)
    return promise.reject(reason)
  end

  parsed_resp = Response.parse(response)
  handle_rate_limit(parsed_resp)
  @backlog << [data, endpoint] if add_to_backlog?(parsed_resp)

  return promise.reject(parsed_resp['error']) if parsed_resp.key?('error')

  promise.resolve(parsed_resp)
end