Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions grape-middleware-lograge.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = 'grape-middleware-lograge'
spec.version = '1.2.3'
spec.version = '1.2.4'
spec.platform = Gem::Platform::RUBY
spec.authors = ['Ryan Buckley', 'Paul Chavard']
spec.email = ['arebuckley@gmail.com', 'paul+github@chavard.net']
Expand All @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'grape', '>= 0.14', '< 1'
spec.add_dependency 'grape', '>= 0.14'
spec.add_dependency 'lograge', '~> 0.3'

spec.add_development_dependency 'bundler', '~> 1.7'
Expand Down
10 changes: 5 additions & 5 deletions lib/grape/middleware/lograge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ def initialize(_, options = {})
def before
super

@db_duration = 0
@db_runtime = 0

@db_subscription = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
@db_duration += event.duration
@db_subscription = ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, start, ending, _transaction_id, _payload|
@db_runtime += 1000.0 * (ending - start) if ending && start
end if defined?(ActiveRecord)

ActiveSupport::Notifications.instrument("start_processing.grape", raw_payload)
Expand Down Expand Up @@ -63,10 +62,11 @@ def call!(env)
end

def after(payload, status)
ActiveSupport::Notifications.unsubscribe(@db_subscription) if @db_subscription
payload[:status] = status
payload[:format] = env['api.format']
payload[:version] = env['api.version']
payload[:db_runtime] = @db_duration
payload[:db_runtime] = @db_runtime
end

def after_exception(payload, e)
Expand Down