raygun-apm-rails 0.1.3
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 +7 -0
- data/.gitignore +8 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/README.rdoc +74 -0
- data/Rakefile +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/raygun/apm/rails.rb +68 -0
- data/lib/raygun/apm/rails/middleware.rb +106 -0
- data/lib/raygun/apm/rails/railtie.rb +14 -0
- data/lib/raygun/apm/rails/version.rb +7 -0
- data/raygun-apm-rails-0.1.0.gem +0 -0
- data/raygun-apm-rails.gemspec +30 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 04470e2ef8a971fbd61675b771c0c10a6b95a6edb960526cf91c7ff244741b95
|
4
|
+
data.tar.gz: f312f4010d321dbe54af892983e3438e086472f77855c633dcc8977dc956bbe0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c3e1d70fa2af061757f42b36a9f39547a2086e9a6c09c97cc95d5031f3aadd22bb0083591a66a0331fcb62071bfd5ac4c17d2dca0207d577f3b2363155c1208
|
7
|
+
data.tar.gz: cfe6f36919254d79510ec4eb1ed55e5312298b0cefc89da971a0c0ff7a6b2afe266e0a08cfe728a21f82bde76ba0e8e46180cf6065bc8fc898af39c6861bf3d0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
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,74 @@
|
|
1
|
+
= Raygun Application Performance Monitoring
|
2
|
+
|
3
|
+
Rails Profiler for {Raygun Application Performance Monitoring}[https://raygun.com/platform/apm].
|
4
|
+
|
5
|
+
Distributed as a Rails wrapper to inject the precompiled native profiler gem.
|
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.4.x (End of life upstream release that does not receive backports anymore)
|
21
|
+
* 2.5.x
|
22
|
+
* 2.6.x
|
23
|
+
* 2.7.x (Preview release, still officially unreleased, but supported)
|
24
|
+
|
25
|
+
{Contact us}[https://raygun.com/about/contact] to support other Ruby versions.
|
26
|
+
|
27
|
+
== Supported Rails versions
|
28
|
+
|
29
|
+
Rails 4 and up.
|
30
|
+
|
31
|
+
* Rails 4.x
|
32
|
+
* Rails 5.x
|
33
|
+
* Rails 6.x
|
34
|
+
|
35
|
+
{Contact us}[https://raygun.com/about/contact] to support other Rails versions.
|
36
|
+
|
37
|
+
== Agent Setup
|
38
|
+
|
39
|
+
The Profiler needs to be able to access the Raygun Agent over UDP.
|
40
|
+
|
41
|
+
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
|
42
|
+
|
43
|
+
To launch Raygun Agent using docker
|
44
|
+
docker pull raygunowner/raygun-apm
|
45
|
+
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
|
46
|
+
|
47
|
+
== Profiler Setup
|
48
|
+
|
49
|
+
Include the gem in your Gemfile and enable it for all environments:
|
50
|
+
|
51
|
+
gem 'raygun-apm-rails'
|
52
|
+
|
53
|
+
Preferably this profiler should only be enabled for your production environment:
|
54
|
+
|
55
|
+
group :production do
|
56
|
+
gem 'raygun-apm-rails'
|
57
|
+
end
|
58
|
+
|
59
|
+
Run <code>bundle</code> to install the gem.
|
60
|
+
|
61
|
+
Alternatively install using rubygems <code>gem install raygun-apm-rails</code>.
|
62
|
+
|
63
|
+
== Rails workloads supported
|
64
|
+
|
65
|
+
Currently we only hook into the framework with Rack middleware and thus only
|
66
|
+
instrument HTTP request / response workloads.
|
67
|
+
|
68
|
+
The following extended events are captured:
|
69
|
+
|
70
|
+
* HTTP inbound - the request URI, HTTP verb and other details of the current request
|
71
|
+
* Database queries - SQL statement, provider, database etc.
|
72
|
+
|
73
|
+
{Contact us}[https://raygun.com/about/contact] to support other workloads such as
|
74
|
+
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/rails/*.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,68 @@
|
|
1
|
+
require "raygun/apm/rails/version"
|
2
|
+
|
3
|
+
module Raygun
|
4
|
+
module Apm
|
5
|
+
module Rails
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
# from https://api.rubyonrails.org/ , to automate
|
9
|
+
BLACKLIST = %w{
|
10
|
+
#<Class:
|
11
|
+
#<Module:
|
12
|
+
#<ActiveRecord:
|
13
|
+
#<ActiveModel:
|
14
|
+
Benchmark
|
15
|
+
BigDecimal
|
16
|
+
Concurrent
|
17
|
+
Date
|
18
|
+
DateAndTime
|
19
|
+
DateTime
|
20
|
+
Delegator
|
21
|
+
Digest
|
22
|
+
ERB
|
23
|
+
SecureRandom
|
24
|
+
URI
|
25
|
+
AbstractController
|
26
|
+
ActionCable
|
27
|
+
ActionController
|
28
|
+
ActionDispatch
|
29
|
+
ActionMailbox
|
30
|
+
ActionMailer
|
31
|
+
ActionText
|
32
|
+
ActionView
|
33
|
+
ActiveJob
|
34
|
+
ActiveModel
|
35
|
+
ActiveRecord
|
36
|
+
ActiveStorage
|
37
|
+
ActiveSupport
|
38
|
+
Arel
|
39
|
+
Mail
|
40
|
+
Mime
|
41
|
+
Rails
|
42
|
+
Rack
|
43
|
+
I18n
|
44
|
+
Bootsnap
|
45
|
+
Sprockets
|
46
|
+
Turbolinks
|
47
|
+
Pathname
|
48
|
+
MonitorMixin
|
49
|
+
Logger
|
50
|
+
Sprockets
|
51
|
+
ActionDispatch
|
52
|
+
ActiveSupport
|
53
|
+
ActionView
|
54
|
+
ApplicationHelper
|
55
|
+
SQLite3
|
56
|
+
Mysql2
|
57
|
+
Erubi
|
58
|
+
ApplicationController
|
59
|
+
RequestStore
|
60
|
+
WEBrick
|
61
|
+
Puma
|
62
|
+
}
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
require "raygun/apm/rails/railtie" if defined?(::Rails)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Raygun
|
2
|
+
module Apm
|
3
|
+
module Rails
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
@tracer = Raygun::Apm::Tracer.new
|
8
|
+
@tracer.udp_sink!
|
9
|
+
@tracer.process_started
|
10
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(@tracer))
|
11
|
+
|
12
|
+
@http_in_subscriber = ActiveSupport::Notifications.subscribe('process_action.action_controller') do |*args|
|
13
|
+
http_in_handler(args)
|
14
|
+
end
|
15
|
+
@sql_subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
|
16
|
+
sql_handler(args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# If any fatal errors on init, shutdown the tracer
|
20
|
+
rescue Raygun::Apm::FatalError => e
|
21
|
+
raygun_shutdown_handler(e)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
@status, @headers, @response = instrument(env)
|
26
|
+
[@status, @headers, @response]
|
27
|
+
end
|
28
|
+
|
29
|
+
def instrument(env)
|
30
|
+
res = nil
|
31
|
+
# Can be nil if we had a fatal error
|
32
|
+
@tracer.start_trace if @tracer
|
33
|
+
res = @app.call(env)
|
34
|
+
# Can be nil if we had a fatal error
|
35
|
+
@tracer.end_trace if @tracer
|
36
|
+
res
|
37
|
+
rescue Raygun::Apm::FatalError => e
|
38
|
+
raygun_shutdown_handler(e)
|
39
|
+
end
|
40
|
+
|
41
|
+
def raygun_shutdown_handler(exception)
|
42
|
+
warn "Raygun APM shutting down due to error - %s", e.message
|
43
|
+
# Kill extended event subcriptions
|
44
|
+
ActiveSupport::Notifications.unsubscribe(@http_in_subscriber)
|
45
|
+
ActiveSupport::Notifications.unsubscribe(@sql_subscriber)
|
46
|
+
# Shutdown the tracepoint if enabled to reduce any overhead and stall emission
|
47
|
+
@tracer.tracepoint.stop if @tracer.tracepoint.enabled?
|
48
|
+
# Let the GC clean up the sink thread through the finalizer below
|
49
|
+
@tracer = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def http_in_handler(args)
|
53
|
+
notification = ActiveSupport::Notifications::Event.new *args
|
54
|
+
if notification.payload[:exception]
|
55
|
+
# XXX notify?
|
56
|
+
return
|
57
|
+
end
|
58
|
+
req = Rack::Request.new notification.payload[:headers].env
|
59
|
+
event = Raygun::Apm::Event::HttpIn.new
|
60
|
+
event[:url] = req.url
|
61
|
+
event[:verb] = req.request_method
|
62
|
+
event[:status] = notification.payload[:status]
|
63
|
+
# XXX constant milliseconds to microseconds
|
64
|
+
event[:duration] = notification.duration * 1000
|
65
|
+
event[:timestamp] = Time.now.to_f*1000000
|
66
|
+
event[:pid] = Process.pid
|
67
|
+
event[:tid] = @tracer.get_thread_id(Thread.current)
|
68
|
+
@tracer.emit(event)
|
69
|
+
rescue => e
|
70
|
+
# XXX report
|
71
|
+
end
|
72
|
+
|
73
|
+
def sql_handler(args)
|
74
|
+
notification = ActiveSupport::Notifications::Event.new *args
|
75
|
+
connection = if notification.payload[:connection]
|
76
|
+
notification.payload[:connection]
|
77
|
+
else
|
78
|
+
ObjectSpace._id2ref(notification.payload[:connection_id])
|
79
|
+
end
|
80
|
+
event = Raygun::Apm::Event::Sql.new
|
81
|
+
event[:query] = notification.payload[:sql]
|
82
|
+
|
83
|
+
# XXX this is hacky
|
84
|
+
if config = connection.instance_variable_get('@config')
|
85
|
+
event[:provider] = config[:adapter]
|
86
|
+
event[:host] = config[:host]
|
87
|
+
event[:database] = config[:database]
|
88
|
+
end
|
89
|
+
|
90
|
+
# XXX constant milliseconds to microseconds
|
91
|
+
event[:duration] = notification.duration * 1000
|
92
|
+
event[:timestamp] = Time.now.to_f*1000000
|
93
|
+
event[:pid] = Process.pid
|
94
|
+
event[:tid] = @tracer.get_thread_id(Thread.current)
|
95
|
+
@tracer.emit(event)
|
96
|
+
rescue => e
|
97
|
+
# XXX report
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.finalize(tracer)
|
101
|
+
proc {tracer.process_ended}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Raygun
|
2
|
+
module Apm
|
3
|
+
module Rails
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer "raygun.apm" do |app|
|
6
|
+
require "raygun/apm"
|
7
|
+
require "raygun/apm/rails/middleware"
|
8
|
+
Raygun::Apm::Blacklist.extend_with Raygun::Apm::Rails::BLACKLIST
|
9
|
+
app.middleware.use Raygun::Apm::Rails::Middleware
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
Binary file
|
@@ -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/rails/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "raygun-apm-rails"
|
8
|
+
spec.version = Raygun::Apm::Rails::VERSION
|
9
|
+
spec.authors = ["Erkki Eilonen"]
|
10
|
+
spec.email = ["erkki@bearmetal.eu"]
|
11
|
+
|
12
|
+
spec.summary = %q{Raygun application performance monitoring for Rails}
|
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", "~> 0.0.10"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: raygun-apm-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erkki Eilonen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-28 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: 0.0.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
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
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- README.rdoc
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/raygun/apm/rails.rb
|
84
|
+
- lib/raygun/apm/rails/middleware.rb
|
85
|
+
- lib/raygun/apm/rails/railtie.rb
|
86
|
+
- lib/raygun/apm/rails/version.rb
|
87
|
+
- raygun-apm-rails-0.1.0.gem
|
88
|
+
- raygun-apm-rails.gemspec
|
89
|
+
homepage:
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubygems_version: 3.1.0.pre3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Raygun application performance monitoring for Rails
|
111
|
+
test_files: []
|