Class: OpticsAgent::Reporting::QueryTrace

Inherits:
Object
  • Object
show all
Includes:
Apollo::Optics::Proto, OpticsAgent::Reporting
Defined in:
lib/optics-agent/reporting/query-trace.rb

Overview

A trace is just a different view of a single query report, with full information about start and end times

Constant Summary

Constants included from Apollo::Optics::Proto

Apollo::Optics::Proto::Error, Apollo::Optics::Proto::Field, Apollo::Optics::Proto::FieldStat, Apollo::Optics::Proto::Id128, Apollo::Optics::Proto::ReportHeader, Apollo::Optics::Proto::SchemaReport, Apollo::Optics::Proto::StatsPerClientName, Apollo::Optics::Proto::StatsPerSignature, Apollo::Optics::Proto::StatsReport, Apollo::Optics::Proto::Timestamp, Apollo::Optics::Proto::Trace, Apollo::Optics::Proto::TracesReport, Apollo::Optics::Proto::Type, Apollo::Optics::Proto::TypeStat

Constants included from OpticsAgent::Reporting

OPTICS_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OpticsAgent::Reporting

#add_latency, #client_info, #duration_nanos, #generate_report_header, #generate_timestamp, #send_message

Constructor Details

#initialize(query, rack_env, start_time, end_time) ⇒ QueryTrace

Returns a new instance of QueryTrace.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/optics-agent/reporting/query-trace.rb', line 14

def initialize(query, rack_env, start_time, end_time)
  trace = Trace.new({
    start_time: generate_timestamp(start_time),
    end_time: generate_timestamp(end_time),
    duration_ns: duration_nanos(start_time, end_time),
    signature: query.signature
  })

  # XXX: report trace details (not totally clear yet from the JS agent what should be here)
  trace.details = Trace::Details.new({})

  info = client_info(rack_env)
  trace.client_name = info[:client_name]
  trace.client_version = info[:client_version]
  trace.client_address = info[:client_address]
  trace.http = Trace::HTTPInfo.new({
    host: "localhost:8080",
    path: "/graphql"
  })

  nodes = []
  query.each_report do |type_name, field_name, field_start_time, field_end_time|
    nodes << Trace::Node.new({
      field_name: "#{type_name}.#{field_name}",
      start_time: duration_nanos(start_time, field_start_time),
      end_time: duration_nanos(start_time, field_end_time)
    })
  end
  trace.execute = Trace::Node.new({
    child: nodes
  })

  @report = TracesReport.new({
    header: generate_report_header,
    trace: [trace]
  })
end

Instance Attribute Details

#reportObject

Returns the value of attribute report.



12
13
14
# File 'lib/optics-agent/reporting/query-trace.rb', line 12

def report
  @report
end

Instance Method Details

#sendObject



52
53
54
# File 'lib/optics-agent/reporting/query-trace.rb', line 52

def send
  send_message('/api/ss/traces', @report)
end