Class: GlassOctopus::Middleware::NewRelic

Inherits:
Object
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/glass_octopus/middleware/new_relic.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :name => "call",
  :category => "OtherTransaction/GlassOctopus",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, klass, options = {}) ⇒ NewRelic

Returns a new instance of NewRelic.



17
18
19
20
# File 'lib/glass_octopus/middleware/new_relic.rb', line 17

def initialize(app, klass, options={})
  @app = app
  @options = DEFAULT_OPTIONS.merge(class_name: klass.name).merge(options)
end

Instance Method Details

#call(ctx) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/glass_octopus/middleware/new_relic.rb', line 22

def call(ctx)
  options = @options.merge(params: {
    topic: ctx.message.topic,
    partition: ctx.message.partition,
    offset: ctx.message.offset,
  })
  perform_action_with_newrelic_trace(options) do
    @app.call(ctx)
  end
rescue Exception => ex
  ::NewRelic::Agent.notice_error(ex, :custom_params => { :message => ctx.message.to_h })
  raise
end