Class: Chef::Telemetry::Client

Inherits:
Object
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/chef/telemetry/client.rb

Constant Summary collapse

TELEMETRY_ENDPOINT =
"https://telemetry.chef.io".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = TELEMETRY_ENDPOINT) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
# File 'lib/chef/telemetry/client.rb', line 14

def initialize(endpoint = TELEMETRY_ENDPOINT)
  super()
  uri = URI(endpoint)
  @http = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = uri.scheme == "https"
  @http.start
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



13
14
15
# File 'lib/chef/telemetry/client.rb', line 13

def http
  @http
end

Instance Method Details

#fire(event) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/chef/telemetry/client.rb', line 22

def fire(event)
  req = Net::HTTP::Post.new("/events")
  req["Content-Type"] = "application/json"
  req.body = JSON.dump(event)
  # TODO: @cwolfe use response and at least debug log status
  http.request req
end