opinionated-metrics 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/metrics_service.rb +38 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6f358f4ab7a7d418697861f4c1fa40e1db2d29f8
4
- data.tar.gz: 34c680435c3da6555381174d16b8e49dcb72d368
2
+ SHA256:
3
+ metadata.gz: 125809985163fe5f5a5e0abb99e64b96c362f680e63cd0aed5052c12eecb7f11
4
+ data.tar.gz: 21e293db7ff53f5a2867f17fe2a5f7f6fb42dc731184a32f2787b33c1942e431
5
5
  SHA512:
6
- metadata.gz: c760761d49da445c13f9684ecf4f826f780d01f9ef5b632ab9ee42552ab6131706a8e76de5c52d4dbb5b5bdf4763cee90ff1e7759b524a3954274132a638e9ba
7
- data.tar.gz: be5dd54881a0f45250b5604a1b3aeef72d9355320129e7a933433166e87192ba959185cf3c1744b32e798aad54916f86495d6c82f0637199611c9e6d1caac431
6
+ metadata.gz: 95883e31abd394627da9f5f76bdb079b62fe36e47c347d507d9d02cf60579336396a8f8df9f03321fa8830ad6482bd4aa6d8a5226537485244500002660cc8b0
7
+ data.tar.gz: f96c67253bdde4806992c8fd7fa159600fa91bcb3726f00d941acd31d36c7a54d78ffffce71050ad071ad85e180eec181826f4586ba52123cf27a22a8e1b3d85
@@ -1,9 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # An object with methods for tracking basic, consistent metrics
1
5
  class MetricsService
6
+ ##
7
+ # Track a basic event; intended for COUNT queries. Outputs `TrackedEvent`
8
+ #
9
+ # @param [String] name A name for filtering within WHERE queries
2
10
  def self.event(name, **additional_properties)
3
- properties = {name: name}.merge(additional_properties)
4
- ::NewRelic::Agent.record_custom_event("TrackedEvent", properties)
11
+ properties = { name: name }.merge(additional_properties)
12
+ ::NewRelic::Agent.record_custom_event('TrackedEvent', properties)
5
13
  end
6
14
 
15
+ ##
16
+ # Given a name and a block, tracks the milliseconds involved in processing the operation. Outputs `OpDurationMs`
17
+ #
18
+ # @param [String] name A name for filtering within WHERE queries
7
19
  def self.time_operation(name, **additional_properties)
8
20
  raise 'A block is required for time_operation calls' unless block_given?
9
21
 
@@ -14,26 +26,46 @@ class MetricsService
14
26
  Rails.logger.error("Failed reporting timing to NewRelic: #{e}")
15
27
  end
16
28
 
29
+ ##
30
+ # Given a name and a start/finish time, tracks the milliseconds involved in processing the operation. Outputs `OpDurationMs`
31
+ #
32
+ # @param [String] name A name for filtering within WHERE queries
33
+ # @param [Time] start The start time of the operation
34
+ # @param [Time] end The end time of the operation
17
35
  def self.duration_start_end(name, start, finish, **additional_properties)
18
36
  duration(name, (finish - start).seconds, **additional_properties)
19
37
  rescue StandardError => e
20
38
  Rails.logger.error("Failed reporting duration to NewRelic: #{e}")
21
39
  end
22
40
 
41
+ ##
42
+ # Given a name and a duration, tracks the milliseconds involved in processing the operation. Outputs `OpDurationMs`
43
+ #
44
+ # @param [String] name A name for filtering within WHERE queries
45
+ # @param [Time] start The start time of the operation
46
+ # @param [Time] end The end time of the operation
23
47
  def self.duration(name, duration, **additional_properties)
24
- properties = {name: name, duration: duration.in_milliseconds}.merge(additional_properties)
25
- ::NewRelic::Agent.record_custom_event("OpDurationMs", properties)
48
+ properties = { name: name, duration: duration.in_milliseconds }.merge(additional_properties)
49
+ ::NewRelic::Agent.record_custom_event('OpDurationMs', properties)
26
50
  rescue StandardError => e
27
51
  Rails.logger.error("Failed reporting duration to NewRelic: #{e}")
28
52
  end
29
53
 
54
+ ##
55
+ # Tracks an exception for error reporting when errors are suppressable for the purpose of HTTP status codes. Outputs `Error`
56
+ #
57
+ # @param [String] name A name for filtering within WHERE queries
30
58
  def self.exception(name, exception)
31
59
  error(name, type: exception.class.name, message: exception&.message)
32
60
  end
33
61
 
62
+ ##
63
+ # Tracks an error for error reporting with arbitrary additional named argument properties. Outputs `Error`
64
+ #
65
+ # @param [String] name A name for filtering within WHERE queries
34
66
  def self.error(name, **additional_properties)
35
- properties = {error_name: name}.merge(additional_properties)
36
- ::NewRelic::Agent.record_custom_event("Error", properties)
67
+ properties = { error_name: name }.merge(additional_properties)
68
+ ::NewRelic::Agent.record_custom_event('Error', properties)
37
69
  rescue StandardError => e
38
70
  Rails.logger.error("Failed reporting error to NewRelic: #{e}")
39
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opinionated-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Wyant
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 2.6.14.3
41
+ rubygems_version: 2.7.6
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Simple metrics gem built to abstract out metrics provider differences