optics-agent 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6c80fb6905bbb97a8edee4ae2fb1d57d9cca76c
4
- data.tar.gz: 969d07c49e74405731ba62ab699982f86c41daa4
3
+ metadata.gz: c2b2a148777b845f0cf7b9857985e17546a70320
4
+ data.tar.gz: 48aab1abbf6eb781bf9a1744e0ffec7ac551c85a
5
5
  SHA512:
6
- metadata.gz: 8b6dbc2a2f0a7f259ba2b4994be4c054e05bdc8ec8fe6d8a4da484830bcdbc5c5afa739dea52a62a4765750b73947ebe9c2a096a7b345383ae0e7c7beb0e92fa
7
- data.tar.gz: af83946a5b4e0990de46b802865a95fecd8612a2adb085fafe5c0b4b6d8caa69b86909c0cdb29077e9989ec0238ae55a56048dc83c90946fe91d1f50f4231063
6
+ metadata.gz: 2179a4eb6d2d6be7cdd61be3aa84a66e82afcba9687023a4106cc4671533bc4c158c7c0c6af6a3449755611ed174b20c22db078a7ec99fb273c2398829369cb2
7
+ data.tar.gz: 98079604f11e6cf92e5ebdcbabbffa389fac48ded7f0560444f6866f0d674775a95111b794d5884a53f22df841778fb7f391ed9510a29b8df221356c1f21883d
data/README.md CHANGED
@@ -69,7 +69,8 @@ agent.configure do
69
69
  # The schema you wish to instrument
70
70
  schema YourSchema
71
71
 
72
- # Your API key for the Optics service. This defaults to the OPTICS_API_KEY environment variable, but can be overridden here.
72
+ # Your API key for the Optics service. This defaults to the OPTICS_API_KEY
73
+ # environment variable, but can be overridden here.
73
74
  api_key ENV['OPTICS_API_KEY']
74
75
 
75
76
  # Log detailed debugging messages
@@ -84,13 +85,17 @@ agent.configure do
84
85
  # Send detailed traces along with usage reports
85
86
  report_traces true
86
87
 
87
- # How long to wait before sending a schema report after startup, in, milliseconds
88
+ # How long to wait before sending a schema report after startup, in
89
+ # milliseconds
88
90
  schema_report_delay_ms 10 * 1000
89
91
 
90
- # How often to send reports in milliseconds. Defaults to 1 minute. Minimum 10 seconds. You shouldn't need to set this unless you are debugging.
92
+ # How often to send reports in milliseconds. Defaults to 1 minute.
93
+ # You shouldn't need to set this unless you are debugging.
91
94
  report_interval_ms 60 * 1000
92
95
 
93
- # Where to send the reports. Defaults to the production Optics endpoint, or the `OPTICS_ENDPOINT_URL` environment variable if it is set. You shouldn't need to set this unless you are debugging
96
+ # Where to send the reports. Defaults to the production Optics endpoint,
97
+ # or the `OPTICS_ENDPOINT_URL` environment variable if it is set.
98
+ # You shouldn't need to set this unless you are debugging
94
99
  endpoint_url 'https://optics-report.apollodata.com'
95
100
  end
96
101
  ```
data/lib/optics-agent.rb CHANGED
@@ -3,3 +3,5 @@ end
3
3
 
4
4
  require 'optics-agent/agent'
5
5
  require 'optics-agent/instrumenters/patch-graphql-schema'
6
+
7
+ require 'optics-agent/railtie' if defined?(Rails)
@@ -10,6 +10,12 @@ module OpticsAgent
10
10
  class Agent
11
11
  include OpticsAgent::Reporting
12
12
 
13
+ class << self
14
+ attr_accessor :logger
15
+ end
16
+
17
+ self.logger = Logger.new(STDOUT)
18
+
13
19
  attr_reader :schema, :report_traces
14
20
 
15
21
  def initialize
@@ -150,17 +156,18 @@ Use the `schema` configuration setting, or call `agent.instrument_schema`
150
156
 
151
157
  def log(message = nil)
152
158
  message = yield unless message
153
- puts "optics-agent: #{message}"
159
+ self.class.logger.info "optics-agent: #{message}"
154
160
  end
155
161
 
156
162
  def warn(message = nil)
157
- log "WARNING: #{message}"
163
+ self.class.logger.warn "optics-agent: WARNING: #{message}"
158
164
  end
159
165
 
166
+ # Should we be using built in debug levels rather than our own "debug" flag?
160
167
  def debug(message = nil)
161
168
  if @configuration.debug
162
169
  message = yield unless message
163
- log "DEBUG: #{message} <#{Process.pid} | #{Thread.current.object_id}>"
170
+ self.class.logger.info "optics-agent: DEBUG: #{message} <#{Process.pid} | #{Thread.current.object_id}>"
164
171
  end
165
172
  end
166
173
  end
@@ -27,7 +27,8 @@ module OpticsAgent
27
27
  when executing your graphql query.
28
28
  If you don't want to instrument this query, pass `context: {optics_agent: :skip}`.
29
29
  """
30
- return
30
+ # don't warn again for this query
31
+ agent_context = query_context[:optics_agent] = :skip
31
32
  end
32
33
 
33
34
  # This happens when an introspection query occurs (reporting schema)
@@ -29,7 +29,7 @@ module OpticsAgent
29
29
 
30
30
  agent.debug { "rack-middleware: request finished" }
31
31
  if (query.document)
32
- agent.debug { "rack-middleware: adding query to agent" }
32
+ agent.debug { "rack-middleware: Adding a query with #{query.reports.length} field reports" }
33
33
  query.finish!
34
34
  agent.add_query(query, env)
35
35
  end
@@ -0,0 +1,7 @@
1
+ module OpticsAgent
2
+ class Railtie < Rails::Railtie
3
+ initializer "optics_agent_logger_initialization" do
4
+ OpticsAgent::Agent.logger = Rails.logger
5
+ end
6
+ end
7
+ end
@@ -17,7 +17,7 @@ module OpticsAgent::Reporting
17
17
  extend Forwardable
18
18
 
19
19
  attr_accessor :document
20
- attr_reader :start_time, :end_time
20
+ attr_reader :start_time, :end_time, :reports
21
21
  def_delegators :@interval, :duration, :duration_so_far
22
22
 
23
23
  def initialize
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optics-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Tom Coleman '
@@ -126,6 +126,7 @@ files:
126
126
  - lib/optics-agent/normalization/latency.rb
127
127
  - lib/optics-agent/normalization/query.rb
128
128
  - lib/optics-agent/rack-middleware.rb
129
+ - lib/optics-agent/railtie.rb
129
130
  - lib/optics-agent/reporting/helpers.rb
130
131
  - lib/optics-agent/reporting/query-trace.rb
131
132
  - lib/optics-agent/reporting/query.rb