class OpenCensus::Trace::Exporters::Datadog::Transport
Constants
- DEFAULT_HOSTNAME
- DEFAULT_PORT
- RUBY_INTERPRETER
- TIMEOUT
- TRACER_VERSION
- TRACE_COUNT_HEADER
- TRACE_ENDPOINT
Public Class Methods
new(hostname, port)
click to toggle source
# File lib/opencensus/trace/exporters/datadog/transport.rb, line 18 def initialize(hostname, port) @hostname = hostname.nil? ? DEFAULT_HOSTNAME : hostname @port = port.nil? ? DEFAULT_PORT : port @headers = {} @headers['Datadog-Meta-Lang'] = 'ruby' @headers['Datadog-Meta-Lang-Version'] = RUBY_VERSION @headers['Datadog-Meta-Lang-Interpreter'] = RUBY_INTERPRETER @headers['Datadog-Meta-Tracer-Version'] = TRACER_VERSION @headers['Content-Type'] = 'application/msgpack' end
Public Instance Methods
upload(data, count = nil)
click to toggle source
# File lib/opencensus/trace/exporters/datadog/transport.rb, line 30 def upload(data, count = nil) begin headers = count.nil? ? {} : { TRACE_COUNT_HEADER => count.to_s } headers = headers.merge(@headers) request = Net::HTTP::Post.new(TRACE_ENDPOINT, headers) request.body = data response = Net::HTTP.start(@hostname, @port, read_timeout: TIMEOUT) { |http| http.request(request) } status_code = response.code.to_i if status_code >= 400 then Datadog.log.error("[daatadog-exporter] #{response.message} (status: #{status_code})") end status_code rescue StandardError => e Datadog.log.error("[daatadog-exporter] failed HTTP request to agent: #{e.message}") 500 end end