Skip to content

Commit d982272

Browse files
authored
Merge pull request #90 from appoptics/AO-13827_rails_6
AO 13827 Rails 6 instrumentation
2 parents 4715888 + ca69e21 commit d982272

File tree

11 files changed

+91
-38
lines changed

11 files changed

+91
-38
lines changed

.travis.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
- DBTYPE=mysql
1212

1313
rvm:
14-
- 2.6.3
14+
- 2.6.4
1515
- 2.5.5
1616
- 2.4.5
1717
- ruby-head
@@ -23,6 +23,7 @@ gemfile:
2323
- gemfiles/instrumentation_mocked.gemfile
2424
- gemfiles/instrumentation_mocked_oldgems.gemfile
2525
- gemfiles/frameworks.gemfile
26+
- gemfiles/rails60.gemfile
2627
- gemfiles/rails52.gemfile
2728
- gemfiles/rails42.gemfile
2829
- gemfiles/delayed_job.gemfile
@@ -32,11 +33,12 @@ matrix:
3233
exclude:
3334
- rvm: ruby-head
3435
gemfile: gemfiles/rails42.gemfile
35-
- rvm: 2.6.3
36+
- rvm: 2.6.4
3637
gemfile: gemfiles/rails42.gemfile
38+
- rvm: 2.4.5
39+
gemfile: gemfiles/rails60.gemfile
3740

38-
39-
- rmv: 2.6.3
41+
- rmv: 2.6.4
4042
env: DBTYPE=mysql
4143
- rvm: 2.5.5
4244
env: DBTYPE=mysql
@@ -57,10 +59,10 @@ matrix:
5759
env: DBTYPE=mysql
5860
- gemfile: gemfiles/frameworks.gemfile
5961
env: DBTYPE=mysql
60-
- gemfile: gemfiles/rails51.gemfile
61-
env: DBTYPE=mysql
6262
- gemfile: gemfiles/rails52.gemfile
6363
env: DBTYPE=mysql
64+
- gemfile: gemfiles/rails60.gemfile
65+
env: DBTYPE=mysql
6466
- gemfile: gemfiles/delayed_job.gemfile
6567
env: DBTYPE=mysql
6668

@@ -110,10 +112,8 @@ before_script:
110112
- export APPOPTICS_TOKEN_BUCKET_CAPACITY=1000
111113
- export APPOPTICS_TOKEN_BUCKET_RATE=1000
112114
- export OBOE_VERSION=5.1.1
113-
- bundle update --jobs=3 --retry=3
114-
- bundle exec rake fetch_ext_deps
115-
- bundle exec rake clean
116-
- bundle exec rake compile
115+
- bundle --jobs=3 --retry=3
116+
- bundle exec rake clean fetch compile
117117
- psql -c 'create database travis_ci_test;' -U postgres
118118
- mysql -e 'create database travis_ci_test;'
119119
- redis-server --requirepass secret_pass &

Rakefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ end
6666
desc "Run all test suites defined by travis"
6767
task "docker_tests" do
6868
Dir.chdir('test/run_tests')
69-
exec('docker-compose run ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh test --remove-orphans')
69+
exec('docker-compose run --rm ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh test --remove-orphans')
7070
end
7171

7272
desc "Start docker container for testing and debugging"
7373
task "docker" do
7474
Dir.chdir('test/run_tests')
75-
exec('docker-compose run ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh bash --remove-orphans')
75+
exec('docker-compose run --rm ruby_appoptics /code/ruby-appoptics/test/run_tests/ruby_setup.sh bash --remove-orphans')
7676
end
7777

7878
desc "Stop all containers that were started for testing and debugging"
@@ -84,11 +84,11 @@ end
8484
desc "Fetch extension dependency files"
8585
task :fetch_ext_deps do
8686
swig_version = %x{swig -version} rescue ''
87-
swig_version = swig_version.scan(/swig version 3.0.\d*/i)
87+
swig_version = swig_version.scan(/swig version [34]/i)
8888
if swig_version.empty?
8989
$stderr.puts '== ERROR ================================================================='
90-
$stderr.puts "Could not find required swig version 3.0.*, found #{swig_version.inspect}"
91-
$stderr.puts 'Please install swig "~ 3.0.8" and try again.'
90+
$stderr.puts "Could not find required swig version >= 3.0.8, found #{swig_version.inspect}"
91+
$stderr.puts 'Please install swig ">= 3.0.8" and try again.'
9292
$stderr.puts '=========================================================================='
9393
raise
9494
end
@@ -128,6 +128,8 @@ task :fetch_ext_deps do
128128
end
129129
end
130130

131+
task :fetch => :fetch_ext_deps
132+
131133
desc "Build the gem's c extension"
132134
task :compile do
133135
if !defined?(JRUBY_VERSION)

lib/appoptics_apm/frameworks/rails/inst/action_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ def render_with_appoptics(*args, &blk)
8484
end
8585

8686
# ActionController::Base
87-
if defined?(ActionController::Base) && AppOpticsAPM::Config[:action_controller][:enabled] && Rails::VERSION::MAJOR < 6
87+
if defined?(ActionController::Base) && AppOpticsAPM::Config[:action_controller][:enabled] && Rails::VERSION::MAJOR <= 6
8888
AppOpticsAPM.logger.info '[appoptics_apm/loading] Instrumenting actioncontroller' if AppOpticsAPM::Config[:verbose]
8989
require "appoptics_apm/frameworks/rails/inst/action_controller#{Rails::VERSION::MAJOR}"
90-
if Rails::VERSION::MAJOR == 5
90+
if Rails::VERSION::MAJOR >= 5
9191
ActionController::Base.send(:prepend, ::AppOpticsAPM::Inst::ActionController)
9292
elsif Rails::VERSION::MAJOR < 5
9393
AppOpticsAPM::Util.send_include(::ActionController::Base, AppOpticsAPM::Inst::ActionController)
9494
end
9595
end
9696

9797
# ActionController::API - Rails 5 or via the rails-api gem
98-
if defined?(ActionController::API) && AppOpticsAPM::Config[:action_controller_api][:enabled] && Rails::VERSION::MAJOR < 6
98+
if defined?(ActionController::API) && AppOpticsAPM::Config[:action_controller_api][:enabled] && Rails::VERSION::MAJOR <= 6
9999
AppOpticsAPM.logger.info '[appoptics_apm/loading] Instrumenting actioncontroller api' if AppOpticsAPM::Config[:verbose]
100100
require "appoptics_apm/frameworks/rails/inst/action_controller_api"
101101
ActionController::API.send(:prepend, ::AppOpticsAPM::Inst::ActionControllerAPI)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) 2016 SolarWinds, LLC.
2+
# All rights reserved.
3+
4+
module AppOpticsAPM
5+
module Inst
6+
#
7+
# ActionController
8+
#
9+
# This modules contains the instrumentation code specific
10+
# to Rails v6
11+
#
12+
module ActionController
13+
include AppOpticsAPM::Inst::RailsBase
14+
15+
def process_action(method_name, *args)
16+
kvs = {
17+
:Controller => self.class.name,
18+
:Action => self.action_name,
19+
}
20+
request.env['appoptics_apm.controller'] = kvs[:Controller]
21+
request.env['appoptics_apm.action'] = kvs[:Action]
22+
23+
return super(method_name, *args) unless AppOpticsAPM.tracing?
24+
begin
25+
kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:action_controller][:collect_backtraces]
26+
27+
AppOpticsAPM::API.log_entry('rails', kvs)
28+
super(method_name, *args)
29+
30+
rescue Exception => e
31+
AppOpticsAPM::API.log_exception('rails', e) if log_rails_error?(e)
32+
raise
33+
ensure
34+
AppOpticsAPM::API.log_exit('rails')
35+
end
36+
end
37+
38+
#
39+
# render
40+
#
41+
# Our render wrapper that calls 'trace', which will log if we are tracing
42+
#
43+
def render(*args, &blk)
44+
trace('actionview') do
45+
super(*args, &blk)
46+
end
47+
end
48+
end
49+
end
50+
end

lib/appoptics_apm/frameworks/rails/inst/active_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
require 'appoptics_apm/frameworks/rails/inst/connection_adapters/mysql2'
66
require 'appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql'
77

8-
if AppOpticsAPM::Config[:active_record][:enabled] && !defined?(JRUBY_VERSION) && Rails::VERSION::MAJOR < 6
8+
if AppOpticsAPM::Config[:active_record][:enabled] && !defined?(JRUBY_VERSION) && Rails::VERSION::MAJOR <= 6
99
begin
1010
adapter = ActiveRecord::Base.connection_config[:adapter]
1111

1212
if Rails::VERSION::MAJOR < 5
1313
require 'appoptics_apm/frameworks/rails/inst/connection_adapters/utils'
14-
elsif Rails::VERSION::MAJOR == 5
14+
elsif Rails::VERSION::MAJOR >= 5
1515
require 'appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x'
1616
end
1717

test/frameworks/rails5x_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
traces[4]['Layer'].must_equal "activerecord"
103103
traces[4]['Label'].must_equal "entry"
104104
traces[4]['Flavor'].must_equal "postgresql"
105-
traces[4]['Query'].must_equal "SELECT \"widgets\".* FROM \"widgets\" WHERE \"widgets\".\"name\" = $? ORDER BY \"widgets\".\"id\" ASC LIMIT $?"
105+
# using match because there is a 1 space difference between Rails 5 and Rails 6
106+
traces[4]['Query'].must_match /SELECT\s{1,2}\"widgets\".* FROM \"widgets\" WHERE \"widgets\".\"name\" = \$\? ORDER BY \"widgets\".\"id\" ASC LIMIT \$\?/
106107
traces[4]['Name'].must_equal "Widget Load"
107108
traces[4].key?('Backtrace').must_equal false
108109
traces[4].key?('QueryArgs').must_equal false
@@ -161,7 +162,8 @@
161162

162163
entry_traces[3]['Layer'].must_equal "activerecord"
163164
entry_traces[3]['Flavor'].must_equal "mysql"
164-
entry_traces[3]['Query'].must_equal "SELECT `widgets`.* FROM `widgets` WHERE `widgets`.`name` = 'blah' ORDER BY `widgets`.`id` ASC LIMIT 1"
165+
# using match because there is a 1 space difference between Rails 5 and Rails 6
166+
entry_traces[3]['Query'].must_match /SELECT\s{1,2}`widgets`.* FROM `widgets` WHERE `widgets`.`name` = 'blah' ORDER BY `widgets`.`id` ASC LIMIT 1/
165167
entry_traces[3]['Name'].must_equal "Widget Load"
166168
entry_traces[3].key?('Backtrace').must_equal false
167169
entry_traces[3].key?('QueryArgs').must_equal Rails.version < '5.2.0' ? true : false
@@ -203,7 +205,7 @@
203205

204206
entry_traces[3]['Layer'].must_equal "activerecord"
205207
entry_traces[3]['Flavor'].must_equal "mysql"
206-
entry_traces[3]['Query'].must_equal "SELECT `widgets`.* FROM `widgets` WHERE `widgets`.`name` = ? ORDER BY `widgets`.`id` ASC LIMIT ?"
208+
entry_traces[3]['Query'].must_match /SELECT\s{1,2}`widgets`.* FROM `widgets` WHERE `widgets`.`name` = \? ORDER BY `widgets`.`id` ASC LIMIT \?/
207209
entry_traces[3]['Name'].must_equal "Widget Load"
208210
entry_traces[3].key?('Backtrace').must_equal false
209211
entry_traces[3].key?('QueryArgs').must_equal false

test/minitest_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ def refute_raises *exp
106106
require './test/servers/delayed_job'
107107

108108
when /rails[56]/
109-
require './test/servers/rails5x_api_8150'
110109
require './test/servers/rails5x_8140'
110+
sleep 1
111+
require './test/servers/rails5x_api_8150'
111112
when /rails4/
112113
require './test/servers/rails4x_8140'
113114

test/run_tests/Dockerfile_test

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RUN apt-get update \
2323
libpq-dev \
2424
vim \
2525
less \
26+
tcl \
2627
tree \
2728
psmisc \
2829
&& rm -rf /var/lib/apt/lists/*
@@ -39,15 +40,16 @@ RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv \
3940

4041
# install rubies to build our gem against
4142
RUN . ~/.profile \
43+
&& cd /root/.rbenv/plugins/ruby-build && git pull && cd - \
4244
&& rbenv install 2.4.5 \
4345
&& rbenv install 2.5.5 \
44-
&& rbenv install 2.6.3
46+
&& rbenv install 2.6.4
4547
# && rbenv install jruby-9.1.16.0
4648

4749
# need to revert to using bundler 1.17.3 because some gems require bundler < 2.0
4850
RUN . ~/.profile && rbenv local 2.4.5 && gem uninstall bundler --quiet -x && gem install bundler -v 1.17.3
4951
RUN . ~/.profile && rbenv local 2.5.5 && gem uninstall bundler --quiet -x && gem install bundler -v 1.17.3
50-
RUN . ~/.profile && rbenv local 2.6.3 && gem uninstall bundler --quiet -x && gem install bundler -v 1.17.3
52+
RUN . ~/.profile && rbenv local 2.6.4 && gem uninstall bundler --quiet -x && gem install bundler -v 1.17.3
5153

5254
RUN echo 'gem: --no-document' >> ~/.gemrc
5355

@@ -59,10 +61,14 @@ RUN curl -SL http://kent.dl.sourceforge.net/project/swig/swig/swig-4.0.0/swig-4.
5961
&& cd - \
6062
&& rm -rf /tmp/swig-4.0.0
6163

62-
# install postgres, redis, and memcached
64+
# install redis-server version 4++
65+
RUN curl -SL http://download.redis.io/releases/redis-4.0.0.tar.gz | tar xzC /tmp \
66+
&& cd /tmp/redis-4.0.0/ \
67+
&& make && make install && cd -
68+
69+
# install postgres and memcached
6370
RUN apt-get update \
6471
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
65-
redis-server \
6672
memcached \
6773
postgresql \
6874
postgresql-contrib \

test/run_tests/docker-compose.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,17 @@ services:
7070
ao-ruby-rabbitmq:
7171
container_name: ao-ruby-rabbitmq
7272
image: rabbitmq:3-management
73-
# ports:
74-
# - "8080:15672"
75-
# - "5672:5672"
76-
# - "5671:5671"
7773

7874
ao-ruby-mysql:
7975
container_name: ao-ruby-mysql
8076
image: mysql:5.7.13
8177
environment:
8278
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
8379
- MYSQL_ROOT_PASSWORD=admin
84-
# ports:
85-
# - "3306:3306"
8680

8781
ao-ruby-mongo:
8882
container_name: ao-ruby-mongo
8983
image: mongo:3.4
90-
# ports:
91-
# - "27017:27017"
9284

9385
ao_ruby_wait:
9486
container_name: ao_ruby_wait
@@ -101,6 +93,4 @@ services:
10193
- ao-ruby-rabbitmq
10294
- ao-ruby-mysql
10395
- ao-ruby-mongo
104-
# environment:
105-
# - TARGETS=ao-ruby-mysql:3306;ao-ruby-rabbitmq:5672;ao-ruby-mongo:27017
10696

test/servers/rails5x_8140.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Rails50MetalStack < Rails::Application
4949
config.middleware.delete ActionDispatch::Flash
5050
config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
5151
config.secret_key_base = "2048671-96803948"
52+
config.active_record.sqlite3 = {} # deal with https://github.com/rails/rails/issues/37048
5253
end
5354

5455
class ApplicationController < ActionController::Base

0 commit comments

Comments
 (0)