Class: OpticsAgent::Instrumenters::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/optics-agent/instrumenters/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



6
7
8
# File 'lib/optics-agent/instrumenters/query.rb', line 6

def agent
  @agent
end

Instance Method Details

#after_query(query) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/optics-agent/instrumenters/query.rb', line 33

def after_query(query)
  return unless @agent
  query_context = query.context[:optics_agent]
  return if query_context == :skip

  agent.debug { "query_instrumenter: query completed" }
  query_context.query_finished!
end

#before_query(query) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/optics-agent/instrumenters/query.rb', line 8

def before_query(query)
  return unless @agent
  query_context = query.context[:optics_agent]
  return if query_context == :skip

  @agent.ensure_reporting_stats!

  # the rack request didn't add the agent, maybe there is none?
  unless query_context
    @agent.warn """No agent passed in graphql context.
Ensure you set `context: { optics_agent: env[:optics_agent] }` when executing your graphql query (where `env` is the rack environment).
If you aren't using the rack middleware, `context: {optics_agent: :no_rack}` to avoid this warning.
If you don't want to instrument this query, pass `context: {optics_agent: :skip}`.
  """
    query_context = :no_rack
  end

  if query_context == :no_rack
    query.context[:optics_agent] = QueryContext.new(agent)
    query_context = query.context[:optics_agent]
  end

  query_context.with_document(query.document.to_query_string)
end