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 +4 -4
- data/CHANGE_LOG.md +3 -0
- data/README.md +32 -0
- data/lib/mtracker/version.rb +1 -1
- data/lib/mtracker.rb +9 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5385ce98aa06094679fedf89c4de60817e3e0669b0ff7b986bbad589ead637f
|
4
|
+
data.tar.gz: c4f88b856c27b67582fb525c6c7d8c325cc53fbbc462915f4a58e75e195913f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c79af1ffd3ec4ecda12fdade1e9bf6fdfe246d0d27b93aaff499ae8f1a3eba51bb92b2a5a915de3e54d54fe72f8bcf419742e9f01d4b2f2b6ac2fe0c78f4c64
|
7
|
+
data.tar.gz: b57e0a27b0ca97fb3652c49de30c3277043984160102a56aa1488fe9a183d27f7daba5fbc169c290caee3f35f60cc2d2f129cae1c829c686dc2e50a95c5179a5
|
data/CHANGE_LOG.md
CHANGED
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
|
|
data/lib/mtracker/version.rb
CHANGED
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
|
-
'|
|
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.
|
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:
|
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.
|
76
|
+
rubygems_version: 3.4.1
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Simple time tracker better than benchmark.
|