raygun-apm-sidekiq 1.0.12 → 1.0.13

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: 9d7f0de52da00010cd3d499c15ceecf7f687983fd5a03b938768ec997e70a966
4
- data.tar.gz: 3dd1bbf9171539d4ec427cef365d712ccb02b54d02ba748e7d3882a7a13b1cd7
3
+ metadata.gz: 3303b715ab45873a92b2c813995c08d7717220a52ba9865f7477d6222f3376fd
4
+ data.tar.gz: 7ff2daab0dd3197775a258bf80376415982b3d07b3681c1dda3fea04350cd59c
5
5
  SHA512:
6
- metadata.gz: d38d374b6b8c4e29d015abbbca69b513cb934e4e5c942bfba619f9d23bcd85bb84c392080245ee578e0aa95ab74e04ff175732fedbf27503ecd4838afd25c9ee
7
- data.tar.gz: 42f5e127cdc0f3be52f953b3b73807a6fdd2097f77bde16b8663bce030e122073e6f266a7500072e927dcb238111e6ffbb6dc9b1a4689a3e530765e4caeaefea
6
+ metadata.gz: f2d888286ea06788a2ead521912a9d7cf43e3af539f083d12d0655c193db15922a7623a180f3c2430dd20bc97c4910c3974bcddb6ddb1b6480a847e4cbc73513
7
+ data.tar.gz: 976a82cf24f1fb7377a09a08e095e1d84b9edadb871e9d8e5c159fd870877755e7281ea84a88eef5481f39ef19a26cbd5c3ddbe4cbac60c36ded0c4afc08af53
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = Changelog
2
2
 
3
+ == 1.0.13 (April 2, 2020)
4
+
5
+ * Prefer hooking Sidekiq::Processor as Middleware does not wrap enough to intercept the raygun4ruby error handler as an HTTP OUT event
6
+
3
7
  == 1.0.12 (March 25, 2020)
4
8
 
5
9
  * Do not cache PID on HTTP OUT and SQL events
data/Gemfile.lock CHANGED
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- raygun-apm-rails (0.1.0)
5
- raygun-apm (~> 0.0.8)
4
+ raygun-apm-sidekiq (1.0.13)
5
+ raygun-apm (~> 1.0.15)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  minitest (5.13.0)
11
11
  rake (10.5.0)
12
- raygun-apm (0.0.8-x86-linux)
12
+ raygun-apm (1.0.24-x86-linux)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
16
16
 
17
17
  DEPENDENCIES
18
- bundler (~> 1.17)
18
+ bundler
19
19
  minitest (~> 5.0)
20
20
  rake (~> 10.0)
21
- raygun-apm-rails!
21
+ raygun-apm-sidekiq!
22
22
 
23
23
  BUNDLED WITH
24
24
  1.17.3
@@ -0,0 +1,136 @@
1
+ require "sidekiq"
2
+ require 'sidekiq/processor'
3
+
4
+ module Raygun
5
+ module Apm
6
+ module Sidekiq
7
+ module Hook
8
+ def self.finalize(tracer)
9
+ proc {tracer.process_ended}
10
+ end
11
+
12
+ def initialize(mgr)
13
+ super
14
+ @tracer = Raygun::Apm::Tracer.instance || init_tracer
15
+ end
16
+
17
+ def process(work)
18
+ job_hash = ::Sidekiq.load_json(work.job)
19
+ queue = work.queue_name
20
+ # Can be nil if we had a fatal error
21
+ if @tracer
22
+ @worker_started = @tracer.now
23
+ @tracer.start_trace
24
+ end
25
+ exception = nil
26
+ Ruby_APM_profiler_trace do
27
+ begin
28
+ super
29
+ fake_http_in_handler(@tracer, @worker_started, job_hash, queue, nil) if @tracer
30
+ rescue => e
31
+ fake_http_in_handler(@tracer, @worker_started, job_hash, queue, e) if @tracer
32
+ exception = e
33
+ end
34
+ end
35
+ # Can be nil if we had a fatal error
36
+ @tracer.end_trace if @tracer
37
+ raise exception if exception
38
+ rescue Raygun::Apm::FatalError => e
39
+ raygun_shutdown_handler(e)
40
+ end
41
+
42
+ private
43
+
44
+ def init_tracer
45
+ tracer = Raygun::Apm::Tracer.new
46
+ tracer.udp_sink!
47
+ tracer.process_started
48
+ ObjectSpace.define_finalizer(self, Hook.finalize(tracer))
49
+
50
+ ActiveSupport::Notifications.unsubscribe(@sql_subscriber) if @sql_subscriber
51
+ @sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
52
+ sql_handler(tracer, args)
53
+ end
54
+
55
+ GC.stress = true if ENV['RAYGUN_STRESS_GC']
56
+ Raygun::Apm::Tracer.instance = tracer
57
+ # If any fatal errors on init, shutdown the tracer
58
+ rescue Raygun::Apm::FatalError => e
59
+ raygun_shutdown_handler(e)
60
+ end
61
+
62
+ def raygun_shutdown_handler(exception)
63
+ warn "[Raygun APM] shutting down due to error - #{exception.message} #{exception.backtrace.join("\n")}"
64
+ # Kill extended event subcriptions
65
+ ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
66
+ warn "[Raygun APM] notification hooks unsubscribed"
67
+ # Let the GC clean up the sink thread through the finalizer below
68
+ @tracer = nil
69
+ Raygun::Apm::Tracer.instance = nil
70
+ raise(exception) unless (Raygun::Apm::FatalError === exception)
71
+ end
72
+
73
+ def fake_http_in_handler(tracer, started, msg, queue, exception)
74
+ ended = tracer.now
75
+ event = http_in_event
76
+ event[:pid] = Process.pid
77
+ event[:url] = "sidekiq://#{queue}/#{msg["class"]}?#{msg["jid"]}"
78
+ event[:status] = exception ? 500 : 200
79
+ event[:duration] = ended - started
80
+ event[:timestamp] = tracer.now
81
+ event[:tid] = tracer.get_thread_id(Thread.current)
82
+ tracer.emit(event)
83
+ rescue => e
84
+ warn "[Raygun APM] error reporting HTTP IN event #{e.class} #{e.backtrace.join("\n")}"
85
+ raygun_shutdown_handler(e)
86
+ end
87
+
88
+ def http_in_event
89
+ @http_in_event ||= begin
90
+ event = Raygun::Apm::Event::HttpIn.new
91
+ event[:verb] = "POST"
92
+ event
93
+ end
94
+ end
95
+
96
+ def sql_handler(tracer, args)
97
+ notification = ActiveSupport::Notifications::Event.new *args
98
+ connection = if notification.payload[:connection]
99
+ notification.payload[:connection]
100
+ else
101
+ ObjectSpace._id2ref(notification.payload[:connection_id])
102
+ end
103
+ event = sql_event
104
+ event[:pid] = Process.pid
105
+ event[:query] = notification.payload[:sql]
106
+
107
+ # XXX this is hacky
108
+ if config = connection.instance_variable_get('@config')
109
+ event[:provider] = config[:adapter]
110
+ event[:host] = config[:host]
111
+ event[:database] = config[:database]
112
+ end
113
+
114
+ # XXX constant milliseconds to microseconds
115
+ event[:duration] = notification.duration * 1000
116
+ event[:timestamp] = notification.time.to_f * 1000000
117
+ event[:tid] = tracer.get_thread_id(Thread.current)
118
+ tracer.emit(event)
119
+ rescue => e
120
+ warn "[Raygun APM] error reporting SQL event"
121
+ raygun_shutdown_handler(e)
122
+ end
123
+
124
+ def sql_event
125
+ @sql_event ||= Raygun::Apm::Event::Sql.new
126
+ end
127
+
128
+ def Ruby_APM_profiler_trace
129
+ yield
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ Sidekiq::Processor.prepend Raygun::Apm::Sidekiq::Hook
@@ -4,16 +4,8 @@ module Raygun
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer "raygun.apm.sidekiq" do |app|
6
6
  require "raygun/apm"
7
- require "raygun/apm/sidekiq/middleware"
8
- require "sidekiq"
7
+ require "raygun/apm/sidekiq/hook"
9
8
  Raygun::Apm::Blacklist.extend_with Raygun::Apm::Sidekiq::BLACKLIST
10
-
11
- ::Sidekiq.configure_server do |config|
12
- config.server_middleware do |chain|
13
- chain.prepend Raygun::Apm::Sidekiq::Middleware
14
- end
15
- end
16
-
17
9
  # Explictly enable instrumenting HTTP until a good control API is figured out
18
10
  require "raygun/apm/hooks/net_http"
19
11
  end
@@ -1,7 +1,7 @@
1
1
  module Raygun
2
2
  module Apm
3
3
  module Sidekiq
4
- VERSION = "1.0.12"
4
+ VERSION = "1.0.13"
5
5
  end
6
6
  end
7
7
  end
@@ -8,8 +8,13 @@ module Raygun
8
8
  BLACKLIST = %w{
9
9
  Sidekiq
10
10
  Redis
11
- +Raygun::Apm::Sidekiq::Middleware::Ruby_APM_profiler_trace
11
+ Raygun::Breadcrumbs
12
+ Raygun::Configuration
13
+ Raygun::config
14
+ +Raygun::Apm::Sidekiq::Hook::Ruby_APM_profiler_trace
15
+ +Raygun::track_exception
12
16
  }
17
+
13
18
  end
14
19
  end
15
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun-apm-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raygun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-03-25 00:00:00.000000000 Z
12
+ date: 2020-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: raygun-apm
@@ -75,6 +75,7 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".gitignore"
78
79
  - CHANGELOG.rdoc
79
80
  - Gemfile
80
81
  - Gemfile.lock
@@ -83,10 +84,9 @@ files:
83
84
  - bin/console
84
85
  - bin/setup
85
86
  - lib/raygun/apm/sidekiq.rb
86
- - lib/raygun/apm/sidekiq/middleware.rb
87
+ - lib/raygun/apm/sidekiq/hook.rb
87
88
  - lib/raygun/apm/sidekiq/railtie.rb
88
89
  - lib/raygun/apm/sidekiq/version.rb
89
- - raygun-apm-sidekiq-1.0.0.gem
90
90
  - raygun-apm-sidekiq.gemspec
91
91
  homepage: https://raygun.com/platform/apm
92
92
  licenses: []
@@ -1,124 +0,0 @@
1
- module Raygun
2
- module Apm
3
- module Sidekiq
4
- class Middleware
5
- def initialize
6
- @tracer = Raygun::Apm::Tracer.instance || self.class.init_tracer
7
- end
8
-
9
- def call(worker_instance, msg, queue)
10
- # Can be nil if we had a fatal error
11
- if @tracer
12
- started = @tracer.now
13
- @tracer.start_trace
14
- end
15
- exception = nil
16
- Ruby_APM_profiler_trace do
17
- yield
18
- self.class.fake_http_in_handler(@tracer, started, worker_instance, msg, queue, nil) if @tracer
19
- rescue => e
20
- self.class.fake_http_in_handler(@tracer, started, worker_instance, msg, queue, exception) if @tracer
21
- end
22
- # Can be nil if we had a fatal error
23
- @tracer.end_trace if @tracer
24
- rescue Raygun::Apm::FatalError => e
25
- self.class.raygun_shutdown_handler(e)
26
- end
27
-
28
- private
29
-
30
- def self.init_tracer
31
- tracer = Raygun::Apm::Tracer.new
32
- tracer.udp_sink!
33
- tracer.process_started
34
- ObjectSpace.define_finalizer(self, self.finalize(tracer))
35
-
36
- @sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
37
- sql_handler(tracer, args)
38
- end
39
-
40
- GC.stress = true if ENV['RAYGUN_STRESS_GC']
41
- Raygun::Apm::Tracer.instance = tracer
42
- # If any fatal errors on init, shutdown the tracer
43
- rescue Raygun::Apm::FatalError => e
44
- raygun_shutdown_handler(e)
45
- end
46
-
47
- def self.raygun_shutdown_handler(exception)
48
- warn "Raygun APM shutting down due to error - %s", exception.message
49
- # Kill extended event subcriptions
50
- ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
51
- warn "[Raygun APM] notification hooks unsubscribed"
52
- # Let the GC clean up the sink thread through the finalizer below
53
- @tracer = nil
54
- Raygun::Apm::Tracer.instance = nil
55
- raise(exception) unless (Raygun::Apm::FatalError === exception)
56
- end
57
-
58
- def self.fake_http_in_handler(tracer, started, worker_instance, msg, queue, exception)
59
- ended = tracer.now
60
- event = http_in_event
61
- event[:pid] = Process.pid
62
- event[:url] = "sidekiq://#{queue}/#{msg["class"]}?#{msg["jid"]}"
63
- event[:status] = exception ? 500 : 200
64
- event[:duration] = ended - started
65
- event[:timestamp] = tracer.now
66
- event[:tid] = tracer.get_thread_id(Thread.current)
67
- tracer.emit(event)
68
- raise(exception) if exception
69
- rescue => e
70
- warn "[Raygun APM] error reporting HTTP IN event"
71
- raygun_shutdown_handler(e)
72
- end
73
-
74
- def self.http_in_event
75
- @http_in_event ||= begin
76
- event = Raygun::Apm::Event::HttpIn.new
77
- event[:verb] = "POST"
78
- event
79
- end
80
- end
81
-
82
- def self.sql_handler(tracer, args)
83
- notification = ActiveSupport::Notifications::Event.new *args
84
- connection = if notification.payload[:connection]
85
- notification.payload[:connection]
86
- else
87
- ObjectSpace._id2ref(notification.payload[:connection_id])
88
- end
89
- event = sql_event
90
- event[:pid] = Process.pid
91
- event[:query] = notification.payload[:sql]
92
-
93
- # XXX this is hacky
94
- if config = connection.instance_variable_get('@config')
95
- event[:provider] = config[:adapter]
96
- event[:host] = config[:host]
97
- event[:database] = config[:database]
98
- end
99
-
100
- # XXX constant milliseconds to microseconds
101
- event[:duration] = notification.duration * 1000
102
- event[:timestamp] = notification.time.to_f * 1000000
103
- event[:tid] = tracer.get_thread_id(Thread.current)
104
- tracer.emit(event)
105
- rescue => e
106
- warn "[Raygun APM] error reporting SQL event"
107
- raygun_shutdown_handler(e)
108
- end
109
-
110
- def self.sql_event
111
- @sql_event ||= Raygun::Apm::Event::Sql.new
112
- end
113
-
114
- def Ruby_APM_profiler_trace
115
- yield
116
- end
117
-
118
- def self.finalize(tracer)
119
- proc {tracer.process_ended}
120
- end
121
- end
122
- end
123
- end
124
- end
Binary file