Class: LogStash::Outputs::Elasticapm

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/elasticapm.rb

Overview

An elasticapm output that does nothing.

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



27
28
29
30
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
# File 'lib/logstash/outputs/elasticapm.rb', line 27

def receive(event)
  begin
    json = event.to_json
    #puts json
    headers = {}
    headers['Content-Type'] = 'application/x-protobuf'
    headers['Authorization'] = "ApiKey #{@api_key}"
    #puts @uri
    #puts headers
    results = JsonPath.new(@base64_encoded_proto_field).on(json)
    #puts results
    results.each do |item|
      #puts item
      requestBody = Base64.decode64(item)
      #puts requestBody
      response = RestClient.post(@uri, requestBody, headers)
      #puts response.code
      #puts response.body
      #puts response.headers
      unless response.code == 200
        puts "Elastic APM request failure: error code: #{response.code}, data=>#{event}"
        @logger.error("Elastic APM request failure: error code: #{response.code}, data=>#{event}")
      end
    end
  rescue Exception => ex
    puts "Exception occurred in posting to Elastic APM Server: '#{ex}', data=>#{event}"
    @logger.error("Exception occurred in posting to Elastic APM Server: '#{ex}', data=>#{event}")
  end
end

#registerObject



22
23
24
# File 'lib/logstash/outputs/elasticapm.rb', line 22

def register
 @uri = "#{@apm_server_uri}/v1/#{@otlp_type}"
end