Class: ScoutApm::Instruments::Grape

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/grape.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Grape

Returns a new instance of Grape.



6
7
8
9
# File 'lib/scout_apm/instruments/grape.rb', line 6

def initialize(context)
  @context = context
  @installed = false
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/scout_apm/instruments/grape.rb', line 4

def context
  @context
end

Instance Method Details

#install(prepend:) ⇒ Object



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
# File 'lib/scout_apm/instruments/grape.rb', line 19

def install(prepend:)
  if defined?(::Grape) && defined?(::Grape::Endpoint)
    @installed = true

    # Grape >= 3.3.0 prepends a module of its own (Grape::Testing::RunBeforeEach)
    # in front of Grape::Endpoint#run. An alias-method chain built on a method
    # owned by a prepended module recurses infinitely (SystemStackError), because
    # the aliased copy's `super` resolves back into our wrapper. Whenever #run is
    # not owned by Grape::Endpoint itself, prepend is the only safe option.
    prepend = true unless endpoint_owns_run?

    logger.info "Instrumenting Grape::Endpoint. Prepend: #{prepend}"

    if prepend
      ::Grape::Endpoint.send(:prepend, GrapeEndpointInstrumentsPrepend)
    else
      ::Grape::Endpoint.class_eval do
        include ScoutApm::Instruments::GrapeEndpointInstruments

        alias run_without_scout_instruments run
        alias run run_with_scout_instruments
      end
    end
  end
end

#installed?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/scout_apm/instruments/grape.rb', line 15

def installed?
  @installed
end

#loggerObject



11
12
13
# File 'lib/scout_apm/instruments/grape.rb', line 11

def logger
  context.logger
end