Class: NitroIntelligence::Reporter
- Inherits:
-
Object
- Object
- NitroIntelligence::Reporter
- Defined in:
- lib/nitro_intelligence/reporter.rb
Defined Under Namespace
Classes: DatasetItemError
Instance Method Summary collapse
- #create_dataset_item(attributes) ⇒ Object
-
#initialize(observability_project_slug:) ⇒ Reporter
constructor
A new instance of Reporter.
- #score(trace_id:, name:, value:, id: "#{trace_id}-#{name}") ⇒ Object
Constructor Details
#initialize(observability_project_slug:) ⇒ Reporter
Returns a new instance of Reporter.
9 10 11 12 13 |
# File 'lib/nitro_intelligence/reporter.rb', line 9 def initialize(observability_project_slug:) @observability_project_slug = observability_project_slug @project_client = fetch_project_client @host = NitroIntelligence.config.observability_base_url end |
Instance Method Details
#create_dataset_item(attributes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nitro_intelligence/reporter.rb', line 15 def create_dataset_item(attributes) uri = URI("#{@host}/api/public/dataset-items") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" request = Net::HTTP::Post.new(uri) request["Content-Type"] = "application/json" request["Authorization"] = "Basic #{@project_client.project.auth_token}" request.body = attributes.to_json response = http.request(request) # Every other request in this gem raises on an unsuccessful response. Without this a # rejected write - bad credentials, a malformed item, a dataset that does not exist - # is indistinguishable from a successful one, and a caller building a dataset ends up # with a run against items that were never stored. unless response.is_a?(Net::HTTPSuccess) raise DatasetItemError, "#{response.code} creating dataset item: #{response.body}" end response end |
#score(trace_id:, name:, value:, id: "#{trace_id}-#{name}") ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/nitro_intelligence/reporter.rb', line 38 def score(trace_id:, name:, value:, id: "#{trace_id}-#{name}") @project_client.observability_client.create_score( id:, trace_id:, name:, value:, environment: NitroIntelligence.environment ) end |