raygun-apm-sidekiq 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 077f9679377d70bdf9e2eafe8a65d7c1b6bb09225ed69766f3858e21b0cb8fe7
4
+ data.tar.gz: 1e9aaa717e0a2889d776b53a0bea31e9eb3bed9901b73a8d07cdf1f8476fcc15
5
+ SHA512:
6
+ metadata.gz: 306d5d3c458e67a32727d2f09b435519ff0d9a6437750eeae249ee8abe78df7c5d95d794ac81a5e7330532d60f7ded7524ad7ee954d890fc6760480241f9ce23
7
+ data.tar.gz: 16aaca40a45458cb87f627b1b827c54b1ce4498671b1fde588c387f0f969f029b3008f77e8365cf6129f66b354f840863e1721367b00e52d8cb43a17faf0c4cb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ raygun-apm-rails (0.1.0)
5
+ raygun-apm (~> 0.0.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.13.0)
11
+ rake (10.5.0)
12
+ raygun-apm (0.0.8-x86-linux)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.17)
19
+ minitest (~> 5.0)
20
+ rake (~> 10.0)
21
+ raygun-apm-rails!
22
+
23
+ BUNDLED WITH
24
+ 1.17.3
data/README.rdoc ADDED
@@ -0,0 +1,82 @@
1
+ = Raygun Application Performance Monitoring
2
+
3
+ {Sidekiq}[https://github.com/mperham/sidekiq] for {Raygun Application Performance Monitoring}[https://raygun.com/platform/apm].
4
+
5
+ Distributed as a Rails and Sidekiq wrapper to inject the precompiled native profiler gem into Sidekiq jobs.
6
+
7
+ == Supported platforms
8
+ * x86-mingw32
9
+ * x64-mingw32
10
+ * x86-linux
11
+ * x86_64-linux
12
+ * universal-darwin
13
+
14
+ {Contact us}[https://raygun.com/about/contact] to support other platforms.
15
+
16
+ == Supported Ruby versions
17
+
18
+ The profiler only supports CRuby, also known as Matz's Ruby Interpreter (MRI).
19
+
20
+ * 2.5.x
21
+ * 2.6.x
22
+ * 2.7.x
23
+
24
+ {Contact us}[https://raygun.com/about/contact] to support other Ruby versions.
25
+
26
+ == Supported Rails versions
27
+
28
+ Rails 4 and up.
29
+
30
+ * Rails 4.x
31
+ * Rails 5.x
32
+ * Rails 6.x
33
+
34
+ {Contact us}[https://raygun.com/about/contact] to support other Rails versions.
35
+
36
+ == Agent Setup
37
+
38
+ The Profiler needs to be able to access the Raygun Agent over UDP.
39
+
40
+ The <code>RAYGUN_AGENT_TOKEN</code> needs to be supplied as an argument and is available under "Application Settings" at the {Raygun Application Performance Monitoring}[https://raygun.com/platform/apm] UI
41
+
42
+ To launch Raygun Agent using docker
43
+ docker pull raygunowner/raygun-apm
44
+ docker run -v raygun-agent:/usr/share/Raygun -e "RAYGUN_AGENT_TOKEN=<token>" -p 2790:2790 -p 2788:2788 -p 2799:2799/udp -it raygunowner/raygun-apm:latest
45
+
46
+ == Profiler Setup
47
+
48
+ Include the gem in your Gemfile and enable it for all environments:
49
+
50
+ gem 'raygun-apm-sidekiq'
51
+
52
+ Preferably this profiler should only be enabled for your production environment:
53
+
54
+ group :production do
55
+ gem 'raygun-apm-sidekiq'
56
+ end
57
+
58
+ It is intended to work best alongside the {raygun-apm-rails}[https://rubygems.org/gems/raygun-apm-rails] gem to profile both inline Web and async job work.
59
+
60
+
61
+ group :production do
62
+ gem 'raygun-apm-rails'
63
+ gem 'raygun-apm-sidekiq'
64
+ end
65
+
66
+
67
+ Run <code>bundle</code> to install the gem.
68
+
69
+ Alternatively install using rubygems <code>gem install raygun-apm-sidekiq</code>.
70
+
71
+ == Rails workloads supported
72
+
73
+ Currently we only hook into the framework with Rack middleware and thus only
74
+ instrument HTTP request / response workloads.
75
+
76
+ The following extended events are captured:
77
+
78
+ * HTTP inbound - the request URI, HTTP verb and other details of the current job
79
+ * HTTP outbound - the URI, HTTP verb and time taken (typically external APIs)
80
+ * Database queries - SQL statement, provider, database etc.
81
+
82
+ {Contact us}[https://raygun.com/about/contact] to support other specific background processing frameworks.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require 'rdoc/task'
4
+
5
+ RDoc::Task.new do |rdoc|
6
+ rdoc.main = "README.rdoc"
7
+ rdoc.rdoc_files.include("README.rdoc", "lib/raygun/apm/*.rb", "lib/raygun/apm/sidekiq/*.rb")
8
+ end
9
+
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << "test"
12
+ t.libs << "lib"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
+ end
15
+
16
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "raygun/apm/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require "raygun/apm/sidekiq/version"
2
+
3
+ module Raygun
4
+ module Apm
5
+ module Sidekiq
6
+ class Error < StandardError; end
7
+
8
+ BLACKLIST = %w{
9
+ Sidekiq
10
+ Redis
11
+ +Raygun::Apm::Sidekiq::Middleware::start_of_trace
12
+ }
13
+ end
14
+ end
15
+ end
16
+
17
+ if defined?(::Rails) && !ENV['RAYGUN_SKIP_MIDDLEWARE']
18
+ require "raygun/apm/sidekiq/railtie"
19
+ end
@@ -0,0 +1,125 @@
1
+ module Raygun
2
+ module Apm
3
+ module Sidekiq
4
+ class Middleware
5
+ def initialize
6
+ @tracer = Raygun::Apm::Tracer.new
7
+ @tracer.udp_sink!
8
+ @tracer.process_started
9
+ ObjectSpace.define_finalizer(self, self.class.finalize(@tracer))
10
+
11
+ @sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
12
+ sql_handler(args)
13
+ end
14
+
15
+ # If any fatal errors on init, shutdown the tracer
16
+ rescue Raygun::Apm::FatalError => e
17
+ raygun_shutdown_handler(e)
18
+ end
19
+
20
+ def call(worker_instance, msg, queue)
21
+ # Can be nil if we had a fatal error
22
+ if @tracer
23
+ started = @tracer.now
24
+ Thread.current.thread_variable_set(:_raygun_apm_tracer, @tracer)
25
+ @tracer.start_trace
26
+ end
27
+ errored = false
28
+ start_of_trace do
29
+ yield
30
+ rescue
31
+ errored = true
32
+ end
33
+ # Can be nil if we had a fatal error
34
+ if @tracer
35
+ fake_http_in_handler(started, worker_instance, msg, queue, errored)
36
+ @tracer.end_trace
37
+ end
38
+ rescue Raygun::Apm::FatalError => e
39
+ raygun_shutdown_handler(e)
40
+ end
41
+
42
+ def raygun_shutdown_handler(exception)
43
+ warn "Raygun APM shutting down due to error - %s", exception.message
44
+ # Kill extended event subcriptions
45
+ ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
46
+ warn "[Raygun APM] notification hooks unsubscribed"
47
+ # Shutdown the tracepoint if enabled to reduce any overhead and stall emission
48
+ if @tracer.tracepoint.enabled?
49
+ @tracer.tracepoint.stop
50
+ warn "[Raygun APM] tracepoint stopped"
51
+ end
52
+ # Let the GC clean up the sink thread through the finalizer below
53
+ @tracer = nil
54
+ Thread.current.thread_variable_set(:_raygun_apm_tracer, nil)
55
+ end
56
+
57
+ def fake_http_in_handler(started, worker_instance, msg, queue, errored)
58
+ ended = @tracer.now
59
+ event = http_in_event
60
+ event[:url] = "sidekiq://#{queue}/#{msg["class"]}?#{msg["jid"]}"
61
+ event[:status] = errored ? 500 : 200
62
+ event[:duration] = ended - started
63
+ event[:timestamp] = @tracer.now
64
+ event[:tid] = @tracer.get_thread_id(Thread.current)
65
+ @tracer.emit(event)
66
+ rescue => e
67
+ warn "[Raygun APM] error reporting HTTP IN event"
68
+ raygun_shutdown_handler(e)
69
+ end
70
+
71
+ def http_in_event
72
+ @http_in_event ||= begin
73
+ event = Raygun::Apm::Event::HttpIn.new
74
+ event[:pid] = Process.pid
75
+ event[:verb] = "POST"
76
+ event
77
+ end
78
+ end
79
+
80
+ def sql_handler(args)
81
+ notification = ActiveSupport::Notifications::Event.new *args
82
+ connection = if notification.payload[:connection]
83
+ notification.payload[:connection]
84
+ else
85
+ ObjectSpace._id2ref(notification.payload[:connection_id])
86
+ end
87
+ event = sql_event
88
+ event[:query] = notification.payload[:sql]
89
+
90
+ # XXX this is hacky
91
+ if config = connection.instance_variable_get('@config')
92
+ event[:provider] = config[:adapter]
93
+ event[:host] = config[:host]
94
+ event[:database] = config[:database]
95
+ end
96
+
97
+ # XXX constant milliseconds to microseconds
98
+ event[:duration] = notification.duration * 1000
99
+ event[:timestamp] = notification.time.to_f * 1000000
100
+ event[:tid] = @tracer.get_thread_id(Thread.current)
101
+ @tracer.emit(event)
102
+ rescue => e
103
+ warn "[Raygun APM] error reporting SQL event"
104
+ raygun_shutdown_handler(e)
105
+ end
106
+
107
+ def sql_event
108
+ @sql_event ||= begin
109
+ event = Raygun::Apm::Event::Sql.new
110
+ event[:pid] = Process.pid
111
+ event
112
+ end
113
+ end
114
+
115
+ def start_of_trace
116
+ yield
117
+ end
118
+
119
+ def self.finalize(tracer)
120
+ proc {tracer.process_ended}
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,23 @@
1
+ module Raygun
2
+ module Apm
3
+ module Sidekiq
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "raygun.apm.sidekiq" do |app|
6
+ require "raygun/apm"
7
+ require "raygun/apm/sidekiq/middleware"
8
+ require "sidekiq"
9
+ 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
+ # Explictly enable instrumenting HTTP until a good control API is figured out
18
+ require "raygun/apm/hooks/net_http"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module Raygun
2
+ module Apm
3
+ module Sidekiq
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "raygun/apm/sidekiq/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "raygun-apm-sidekiq"
8
+ spec.version = Raygun::Apm::Sidekiq::VERSION
9
+ spec.authors = ["Erkki Eilonen"]
10
+ spec.email = ["erkki@bearmetal.eu"]
11
+
12
+ spec.summary = %q{Raygun application performance monitoring for Sidekiq}
13
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ #spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ #spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "raygun-apm", "~> 1.0.0"
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: raygun-apm-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Erkki Eilonen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: raygun-apm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - erkki@bearmetal.eu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.rdoc
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - lib/raygun/apm/sidekiq.rb
83
+ - lib/raygun/apm/sidekiq/middleware.rb
84
+ - lib/raygun/apm/sidekiq/railtie.rb
85
+ - lib/raygun/apm/sidekiq/version.rb
86
+ - raygun-apm-sidekiq.gemspec
87
+ homepage:
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.0.6
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Raygun application performance monitoring for Sidekiq
109
+ test_files: []