Method: Sentry::HTTPTransport#send_data

Defined in:
lib/sentry/transport/http_transport.rb

#send_data(data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sentry/transport/http_transport.rb', line 31

def send_data(data)
  encoding = ""

  if should_compress?(data)
    data = Zlib.gzip(data)
    encoding = GZIP_ENCODING
  end

  headers = {
    "Content-Type" => CONTENT_TYPE,
    "Content-Encoding" => encoding,
    "User-Agent" => USER_AGENT
  }

  auth_header = generate_auth_header
  headers["X-Sentry-Auth"] = auth_header if auth_header

  response = do_request(endpoint, headers, data)

  if response.code.match?(/\A2\d{2}/)
    handle_rate_limited_response(response) if has_rate_limited_header?(response)
  elsif response.code == "429"
    log_debug("the server responded with status 429")
    handle_rate_limited_response(response)
  else
    error_info = "the server responded with status #{response.code}"
    error_info += "\nbody: #{response.body}"
    error_info += " Error in headers is: #{response['x-sentry-error']}" if response["x-sentry-error"]

    raise Sentry::ExternalError, error_info
  end
rescue SocketError, *HTTP_ERRORS => e
  on_error if respond_to?(:on_error)
  raise Sentry::ExternalError.new(e&.message)
end