Class: ElasticAPM::Transport::Connection Private
- Inherits:
-
Object
- Object
- ElasticAPM::Transport::Connection
- Includes:
- Logging
- Defined in:
- lib/elastic_apm/transport/connection.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.
Defined Under Namespace
Classes: FailedToConnectError, ModdedIO
Constant Summary collapse
- HEADERS =
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.
{ 'Content-Type' => 'application/x-ndjson', 'Transfer-Encoding' => 'chunked' }.freeze
- GZIP_HEADERS =
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.
HEADERS.merge('Content-Encoding' => 'gzip').freeze
Constants included from Logging
Logging::LEVELS, Logging::PREFIX
Instance Method Summary collapse
- #connected? ⇒ Boolean private
- #flush ⇒ Object private
-
#initialize(config, metadata) ⇒ Connection
constructor
private
A new instance of Connection.
- #write(str) ⇒ Object private
Methods included from Logging
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(config, metadata) ⇒ Connection
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 Connection.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/elastic_apm/transport/connection.rb', line 31 def initialize(config, ) @config = config @metadata = .to_json @url = config.server_url + '/intake/v2/events' headers = (@config.http_compression? ? GZIP_HEADERS : HEADERS).dup if (token = config.secret_token) headers['Authorization'] = "Bearer #{token}" end @client = HTTP.headers(headers).persistent(@url) @mutex = Mutex.new end |
Instance Method Details
#connected? ⇒ Boolean
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.
66 67 68 |
# File 'lib/elastic_apm/transport/connection.rb', line 66 def connected? @mutex.synchronize { @connected } end |
#flush ⇒ 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.
70 71 72 73 74 75 76 77 78 |
# File 'lib/elastic_apm/transport/connection.rb', line 70 def flush @mutex.synchronize do return unless @connected debug 'Closing request' @wr.close @conn_thread.join 5 if @conn_thread end end |
#write(str) ⇒ 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/elastic_apm/transport/connection.rb', line 49 def write(str) return if @config.disable_send connect_unless_connected @mutex.synchronize { append(str) } return unless @bytes_sent >= @config.api_request_size flush rescue FailedToConnectError => e error "Couldn't establish connection to APM Server:\n%p", e flush nil end |