yabeda-grape 0.2.0 → 0.2.0.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
  SHA256:
3
- metadata.gz: 5b5483bc86a1844caa4d774bfa0a8c5133b890c46793e6277fcfa1b87d7a97b7
4
- data.tar.gz: adac8e5aecf73e7b38d15188bba999f1c39f313c27599a0c5380c80c59651697
3
+ metadata.gz: eb8d386795e0faab4a984b2dd3c0fed32d57b9fa37eeadd415ad647ad3688d7b
4
+ data.tar.gz: c08679820788f815d2676d8aced409d658035d1809f9ffa2046a5f15b197a1fd
5
5
  SHA512:
6
- metadata.gz: 56c75f0cba637fbfb0b051c81a25154cd39f88620e3d9d8f1c27ab23a6fad5cc72db8dbf6c9b60548fd8cd9383ba252d4c4cc4674a4939358a3c23a1f0931d7c
7
- data.tar.gz: f10e3a3f319aad9a9a32d5b01549b5ef4503ed15bdb1f44b38a67a6e2c794bd6035a5bb911cb8be4e5e4ac24570b4a488420f6ae35ad9627515eca993c01c7c8
6
+ metadata.gz: f36c90b42738159290ef31ac90fa4b90a3924e099b506cd095f7eb7337771e19db2234825ce53d64513db615ef9e891f5a98b58b4c932399eb82d1ea9b8a74d2
7
+ data.tar.gz: 6c7212a9d2b50ba1d39ab1143c8f5e041df2385d2e57519fc7a176dfb0ce57423c89411d308258ca7f3c04ce60ac62c3a9f8fbb9c17abc38db7b72cd2b4892ca
@@ -24,11 +24,7 @@ module Yabeda
24
24
  ActiveSupport::Notifications.subscribe 'endpoint_run.grape' do |*args|
25
25
  event = ActiveSupport::Notifications::Event.new(*args)
26
26
 
27
- labels = {
28
- method: event.payload[:endpoint].options[:method].first.downcase,
29
- path: event.payload[:endpoint].route.path,
30
- status: event.payload[:endpoint].status
31
- }
27
+ next unless (labels = Yabeda::Grape.extract_labels(event))
32
28
 
33
29
  grape_requests_total.increment(labels)
34
30
  grape_request_duration.measure(labels, Yabeda::Grape.ms2s(event.duration))
@@ -39,6 +35,20 @@ module Yabeda
39
35
  def ms2s(ms)
40
36
  (ms.to_f / 1000).round(3)
41
37
  end
38
+
39
+ def extract_labels(event)
40
+ return unless (endpoint = event.payload[:endpoint])
41
+
42
+ # endpoint.route.path can throw an error in Grape inside_route.rb, which
43
+ # is caught below
44
+ path = endpoint.route&.path # path description (e.g. /user/{id}.json)
45
+ method = endpoint.options[:method]&.first&.downcase # http method
46
+ status = endpoint.status # http code
47
+
48
+ { method: method, path: path, status: status }
49
+ rescue StandardError
50
+ nil
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -1,5 +1,5 @@
1
1
  module Yabeda
2
2
  module Grape
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadym Filipov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yabeda