Class: Buildkite::Trace::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/buildkite/trace/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(hostname) ⇒ Client

Returns a new instance of Client.



6
7
8
# File 'lib/buildkite/trace/client.rb', line 6

def initialize(hostname)
  @uri = URI("http://#{hostname}:8126/v0.3/traces")
end

Instance Method Details

#submit_trace(array_of_spans) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/buildkite/trace/client.rb', line 10

def submit_trace(array_of_spans)
  array_of_traces = [array_of_spans]
  http = Net::HTTP.new(@uri.host, 8126)
  response = http.start do |http|
    request = Net::HTTP::Put.new(@uri.request_uri, { 'Content-Type' => 'application/json'})
    request.body = JSON.dump(array_of_traces)
    http.request(request)
  end
  response.code.to_i == 200
end