simple_apm 1.0.8 → 1.0.9

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: 7022496ba04174ad3f103383c9388b3b5203c79f22eec0381bb50f6d2d8d6f14
4
- data.tar.gz: 2e6faa25b91f124e29c9c092cb432fcfd3593631daecc18edd61182f19a9d10b
3
+ metadata.gz: 5c91db688c65ce6f3494af08efe52113e34f6b717b70ad1bbd7f7940d7439734
4
+ data.tar.gz: 5d4d4b1d8ed80f91f07a8e11a41e884aaf7ac057c592a3d9adb214844ab7bf41
5
5
  SHA512:
6
- metadata.gz: bafd772296505aae3f057b5a6a51fed6aba84f1c31dc81245b80c989b6c9f9845b0e16d99e769e7a7f74e6e538402ff7bd0983b8817c74a6990aa29c64804e64
7
- data.tar.gz: e8393025dec36cf4a329a10f69a4a187d5361a07f8e59d3dc1751aa931562a323cf2e3ff34e11d2808a20ef8ac721d83ed56c4e7e5983e08758092b91a31c012
6
+ metadata.gz: 451a075c9e513bd609d990a8907b985fa9afec5449327cb4542eddde3de91c2446649e0edbced46347ae85b6c164d7e1258234d0477c8a6f5356f502a8f28ede
7
+ data.tar.gz: 68e68a6dc70ee52c31141de9023f58f25187a47699589f92789c47235f4344d4b37b644fe88184a2a821695efca16ac558b68a5a9474e02ce1eaffbcdf701a08
@@ -29,7 +29,9 @@
29
29
  <tr>
30
30
  <td>
31
31
  <%= sec_str r.during %>
32
- (DB: <%= sec_str r.db_runtime %> , View: <%= sec_str r.view_runtime %>)
32
+ (DB: <%= sec_str r.db_runtime %> ,
33
+ View: <%= sec_str r.view_runtime %>
34
+ <%= "HTTP: #{sec_str r.net_http_during}" if r.net_http_during.to_f > 0 %>)
33
35
  </td>
34
36
  <td><%= time_label r.started %></td>
35
37
  <td><%= link_to r.request_id, show_path(id: r.request_id) %></td>
@@ -12,8 +12,8 @@
12
12
  <span>
13
13
  <%= sec_str @request.during %>
14
14
  (数据库:<%= sec_str @request.db_runtime %>,
15
- View: <%= sec_str @request.view_runtime %>,
16
- 外部请求: <%= sec_str @request.net_http_during %>)
15
+ View: <%= sec_str @request.view_runtime %>
16
+ <%= ",外部请求: #{sec_str @request.net_http_during}" if @request.net_http_during.to_f>0 %>)
17
17
  </span>
18
18
  </p>
19
19
  <p>
@@ -42,15 +42,15 @@
42
42
  <table class="table table-bordered">
43
43
  <tr>
44
44
  <th>开始时间</th>
45
- <th>URL</th>
46
45
  <th>耗时</th>
46
+ <th>URL</th>
47
47
  <th>其他信息</th>
48
48
  </tr>
49
49
  <% @request.net_http_requests.each do |r| %>
50
50
  <tr>
51
51
  <td><%= time_label r.started %></td>
52
- <td><%= r.url %></td>
53
52
  <td><%= sec_str r.during %></td>
53
+ <td><%= r.url %></td>
54
54
  <td><%= "#{r.filename}: #{r.line}" if r.filename.present? %></td>
55
55
  </tr>
56
56
  <% end %>
data/lib/simple_apm.rb CHANGED
@@ -27,7 +27,9 @@ module SimpleApm
27
27
  th = Thread.current['action_dispatch.request_id'].present? ? Thread.current : Thread.main
28
28
  request_id = th['action_dispatch.request_id']
29
29
  if request_id
30
- during = finished - started
30
+ # Net::HTTP请求分两步,do_start和request,RestClient会预先do_start在调用request,HTTParty则会直接调用request
31
+ real_start_time = payload[:real_start_time] || started
32
+ during = finished - real_start_time
31
33
  th[:net_http_during] += during if th[:net_http_during]
32
34
  if dev_caller = caller.detect {|c| c.include?(Rails.root.to_s) && !c.include?('/vendor/')}
33
35
  c = ::Callsite.parse(dev_caller)
@@ -36,7 +38,7 @@ module SimpleApm
36
38
  ProcessingThread.add_event(
37
39
  name: name,
38
40
  request_id: request_id,
39
- started: started, finished: finished,
41
+ started: real_start_time, finished: finished,
40
42
  payload: payload
41
43
  )
42
44
  end
@@ -1,9 +1,16 @@
1
+ require 'net/http'
1
2
  module SimpleApm
2
3
  class NetHttp
3
4
  class << self
4
5
  def install
5
6
  Net::HTTP.class_eval do
6
- alias orig_request_apm request unless method_defined?(:orig_request)
7
+ alias origin_request_apm request unless method_defined?(:origin_request_apm)
8
+ alias origin_do_start_apm do_start unless method_defined?(:origin_do_start_apm)
9
+
10
+ def do_start
11
+ Thread.current[:injection_net_http_request_start_time] = Time.now
12
+ origin_do_start_apm
13
+ end
7
14
 
8
15
  def request(req, body = nil, &block)
9
16
  url = if @port == '80'
@@ -13,14 +20,17 @@ module SimpleApm
13
20
  else
14
21
  "http://#{@address}:#{@port}#{req.path}"
15
22
  end
16
- # 会调用两次(HTTParty)
23
+ payload = {
24
+ real_start_time: Thread.current[:injection_net_http_request_start_time],
25
+ url: url, host: @address, path: req.path
26
+ }
17
27
  if started?
18
- ActiveSupport::Notifications.instrument "net_http.request", url: url, host: @address, path: req.path do
19
- @response = orig_request_apm(req, body, &block)
28
+ ActiveSupport::Notifications.instrument 'net_http.request', payload do
29
+ @response = origin_request_apm(req, body, &block)
20
30
  end
21
31
  else
22
32
  # 去connect
23
- @response = orig_request_apm(req, body, &block)
33
+ @response = origin_request_apm(req, body, &block)
24
34
  end
25
35
  @response
26
36
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleApm
2
- VERSION = '1.0.8'
2
+ VERSION = '1.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuanyin.xia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails