Class: Appsignal::Transmitter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/transmitter.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.

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.

"application/json; charset=UTF-8".freeze
HTTP_ERRORS =

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.

[
  EOFError,
  Errno::ECONNREFUSED,
  Errno::ECONNRESET,
  Errno::EINVAL,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  Timeout::Error,
  OpenSSL::SSL::SSLError
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri, config = Appsignal.config) ⇒ Transmitter

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 Transmitter.

Parameters:

  • base_uri (String)

    Base URI for the transmitter to use. If a full URI is given (including the HTTP protocol) it is used as the full base. If only a path is given the config[:endpoint] is prefixed along with /1/ (API v1 endpoint).

  • config (Appsignal::Config) (defaults to: Appsignal.config)

    AppSignal configuration to use for this transmission.



34
35
36
37
38
39
40
41
42
# File 'lib/appsignal/transmitter.rb', line 34

def initialize(base_uri, config = Appsignal.config)
  @base_uri =
    if base_uri.start_with? "http"
      base_uri
    else
      "#{config[:endpoint]}/1/#{base_uri}"
    end
  @config = config
end

Instance Attribute Details

#base_uriObject (readonly)

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.



26
27
28
# File 'lib/appsignal/transmitter.rb', line 26

def base_uri
  @base_uri
end

#configObject (readonly)

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.



26
27
28
# File 'lib/appsignal/transmitter.rb', line 26

def config
  @config
end

Instance Method Details

#transmit(payload) ⇒ 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.



56
57
58
59
# File 'lib/appsignal/transmitter.rb', line 56

def transmit(payload)
  config.logger.debug "Transmitting payload to #{uri}"
  http_client.request(http_post(payload))
end

#uriObject

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.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/appsignal/transmitter.rb', line 44

def uri
  @uri ||= URI(base_uri).tap do |uri|
    uri.query = ::Rack::Utils.build_query(
      :api_key => config[:push_api_key],
      :name => config[:name],
      :environment => config.env,
      :hostname => config[:hostname],
      :gem_version => Appsignal::VERSION
    )
  end
end