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

JSON_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"
NDJSON_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/x-ndjson; charset=UTF-8"
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` is prefixed along with `/1/` (API v1 endpoint).

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

    AppSignal configuration to use for this transmission.

[View source]

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

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.


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

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.


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

def config
  @config
end

Instance Method Details

#transmit(payload, format: :json) ⇒ 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.

[View source]

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

def transmit(payload, format: :json)
  Appsignal.internal_logger.debug "Transmitting payload to #{uri}"
  http_client.request(http_post(payload, :format => format))
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.

[View source]

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

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