mtracker 0.3.2 → 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: 051ee370c33218d203cab9db0f43fc548b5d18f00ba5ae53481aa206ab458e67
4
- data.tar.gz: 3f4a4e10c5b9121f65ce90e62f74327568d06b76bd72a85b2970154498136c88
3
+ metadata.gz: a5385ce98aa06094679fedf89c4de60817e3e0669b0ff7b986bbad589ead637f
4
+ data.tar.gz: c4f88b856c27b67582fb525c6c7d8c325cc53fbbc462915f4a58e75e195913f2
5
5
  SHA512:
6
- metadata.gz: 83d563ef944e7deb0af47b73c230f485f302280107f491480f46ce8573f3195ae3d0db83ee29d3b76561945307224d77b991e463eaab86d9862138e2ea6e095a
7
- data.tar.gz: 897008f8e2eae9078e0d8d5b05a8dcd90f3341a49f6cf086c35315484f296e94944cd29402efc4e17643678c69ba54027fde76f0144efdb90c054f52824d2c4d
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.2'
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
@@ -25,7 +32,7 @@ module Mtracker
25
32
  private
26
33
 
27
34
  def indent
28
- '| ' * nest_level
35
+ '| ' * nest_level
29
36
  end
30
37
 
31
38
  def pid_and_tid
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.2
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.