mtracker 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: beef150afdf62af78d7560e92d3a4b370a661d17e9895182f1efa4cf22d031c6
4
- data.tar.gz: c282b2acca5e650c79b0c177156f02817d846d6ac4bbd3f41b6cbfd3cdc6f2bb
3
+ metadata.gz: a5385ce98aa06094679fedf89c4de60817e3e0669b0ff7b986bbad589ead637f
4
+ data.tar.gz: c4f88b856c27b67582fb525c6c7d8c325cc53fbbc462915f4a58e75e195913f2
5
5
  SHA512:
6
- metadata.gz: cb3f1de3069dfc1acfdcb42890a330a8301173900de4169639e1307ffede9864c18d24a387bad49a3565d575d205700bef327512b1d5a494b90c7895744b37f5
7
- data.tar.gz: 57cf493ce4fae06dcb82188d46cde18f51eb7fd392672281e61b50082f90a4cd534cc958a5a368f34c89b9ab590e479b120ec39838f04a442c3827931941c8b4
6
+ metadata.gz: 1c79af1ffd3ec4ecda12fdade1e9bf6fdfe246d0d27b93aaff499ae8f1a3eba51bb92b2a5a915de3e54d54fe72f8bcf419742e9f01d4b2f2b6ac2fe0c78f4c64
7
+ data.tar.gz: b57e0a27b0ca97fb3652c49de30c3277043984160102a56aa1488fe9a183d27f7daba5fbc169c290caee3f35f60cc2d2f129cae1c829c686dc2e50a95c5179a5
data/CHANGE_LOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ = 0.3.4
2
+ - support newrelic
3
+
1
4
  = 0.2.1
2
5
  - return result of block
3
6
 
data/README.md CHANGED
@@ -68,7 +68,39 @@ Then you can see following output in your logger output as info level:
68
68
  [end] sample job (0.004353018 sec)
69
69
  ```
70
70
 
71
+ ## Usage with Newrelic
72
+ You can create newrelic segment with option `newrelic: true` .
73
+ It calls `NewRelic::Agent::Tracer.start_segment`.
74
+ ```
75
+ class Myclass
76
+ include Mtracker
77
+
78
+ def foo
79
+ track('sample job', newrelic: true) do
80
+ 'bar' * 1000000
81
+ end
82
+ end
83
+ end
84
+ ```
85
+
86
+ Child thread is supported.
87
+ ```
88
+ class Myclass
89
+ include Mtracker
90
+
91
+ def foo
92
+ transaction = NewRelic::Agent::Tracer.current_transaction
93
+ Parallel.each(['foo', 'bar'], in_threads: 2) do |s|
94
+ Thread.current[:nr_transaction] = transaction
95
+ track('sample job', newrelic: true) do
96
+ s * 1000000
97
+ end
98
+ end
99
+ end
100
+ end
101
+ ```
71
102
 
103
+ See: [official document](https://docs.newrelic.com/docs/apm/agents/ruby-agent/api-guides/ruby-custom-instrumentation/)
72
104
 
73
105
  ## Contributing
74
106
 
@@ -1,3 +1,3 @@
1
1
  module Mtracker
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
data/lib/mtracker.rb CHANGED
@@ -5,18 +5,25 @@ module Mtracker
5
5
  attr_accessor :mtracker_log_pid_and_tid, :mtracker_slack_url
6
6
 
7
7
  def track(label, options = {})
8
- slack = options[:slack]
8
+ slack = options[:slack] # Bool
9
+ newrelic = options[:newrelic] || false # Bool
10
+ nr_tracer = NewRelic::Agent::Tracer if defined?(NewRelic::Agent::Tracer) && newrelic
9
11
 
10
12
  start_time = Time.now
11
13
  increment_nest_level
12
14
 
13
15
  start_msg = "#{indent}[start#{pid_and_tid}] #{label}"
14
16
  put_track_info start_msg, slack
17
+ if nr_tracer
18
+ nr_segment = nr_tracer.start_segment(name: "Custom/#{label}", parent: nr_tracer.current_segment)
19
+ Thread.current[:nr_transaction]&.add_segment(nr_segment)
20
+ end
15
21
 
16
22
  result = yield
17
23
 
18
24
  finish_msg = "#{indent}[end #{pid_and_tid}] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
19
25
  put_track_info finish_msg, slack
26
+ nr_segment&.finish
20
27
 
21
28
  decrement_nest_level
22
29
  result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Murata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-29 00:00:00.000000000 Z
11
+ date: 2023-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.2.15
76
+ rubygems_version: 3.4.1
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Simple time tracker better than benchmark.