opinionated-metrics 0.0.3 → 0.0.4
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 +4 -4
- data/lib/metrics_service.rb +9 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84705f7a3ee86c20a07a84db7e9a78e82a8747d050f78f5ca8db1892a201699b
|
|
4
|
+
data.tar.gz: 2d7f49f956652d651b035e5b005412dc3ddbb7a8c931c8fce87b272007f4d4e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc29989b1bcd051bbf079933fb4a3590b6382e481343ee0c7a0fe6fbbe0ddf248333f0176460db0d3472927643b1b844ed57cab17c6e42df00d9fed50d293601
|
|
7
|
+
data.tar.gz: 9ec84f4dc4141cd1068b7ad2966826e23129542581f1326db604b053fc7cd2841fab19cd632e524b45d16d209786c100f1c52df5bb84ebd4d200d354f3f18a62
|
data/lib/metrics_service.rb
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
##
|
|
4
4
|
# An object with methods for tracking basic, consistent metrics
|
|
5
5
|
class MetricsService
|
|
6
|
+
##
|
|
7
|
+
# Must be set in application bootstrap before use
|
|
8
|
+
LOGGER = nil
|
|
9
|
+
|
|
6
10
|
##
|
|
7
11
|
# Track a basic event; intended for COUNT queries. Outputs `TrackedEvent`
|
|
8
12
|
#
|
|
@@ -20,10 +24,9 @@ class MetricsService
|
|
|
20
24
|
raise 'A block is required for time_operation calls' unless block_given?
|
|
21
25
|
|
|
22
26
|
start = Time.current
|
|
23
|
-
yield
|
|
27
|
+
result = yield
|
|
24
28
|
duration_start_end(name, start, Time.current, **additional_properties)
|
|
25
|
-
|
|
26
|
-
Rails.logger.error("Failed reporting timing to NewRelic: #{e}")
|
|
29
|
+
result
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
##
|
|
@@ -35,7 +38,7 @@ class MetricsService
|
|
|
35
38
|
def self.duration_start_end(name, start, finish, **additional_properties)
|
|
36
39
|
duration(name, (finish - start).seconds, **additional_properties)
|
|
37
40
|
rescue StandardError => e
|
|
38
|
-
|
|
41
|
+
LOGGER.error("Failed reporting duration to NewRelic: #{e}")
|
|
39
42
|
end
|
|
40
43
|
|
|
41
44
|
##
|
|
@@ -48,7 +51,7 @@ class MetricsService
|
|
|
48
51
|
properties = { name: name, duration: duration.in_milliseconds }.merge(additional_properties)
|
|
49
52
|
::NewRelic::Agent.record_custom_event('OpDurationMs', properties)
|
|
50
53
|
rescue StandardError => e
|
|
51
|
-
|
|
54
|
+
LOGGER.error("Failed reporting duration to NewRelic: #{e}")
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
##
|
|
@@ -67,6 +70,6 @@ class MetricsService
|
|
|
67
70
|
properties = { error_name: name }.merge(additional_properties)
|
|
68
71
|
::NewRelic::Agent.record_custom_event('Error', properties)
|
|
69
72
|
rescue StandardError => e
|
|
70
|
-
|
|
73
|
+
LOGGER.error("Failed reporting error to NewRelic: #{e}")
|
|
71
74
|
end
|
|
72
75
|
end
|