instana 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +24 -2
  5. data/Gemfile +2 -22
  6. data/README.md +1 -1
  7. data/Rakefile +15 -0
  8. data/Tracing.md +29 -2
  9. data/gemfiles/libraries.gemfile +50 -0
  10. data/gemfiles/rails32.gemfile +45 -0
  11. data/gemfiles/rails42.gemfile +44 -0
  12. data/gemfiles/rails50.gemfile +44 -0
  13. data/instana.gemspec +6 -8
  14. data/lib/instana/config.rb +7 -5
  15. data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +55 -0
  16. data/lib/instana/frameworks/instrumentation/action_controller.rb +105 -0
  17. data/lib/instana/frameworks/instrumentation/active_record.rb +22 -0
  18. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +81 -0
  19. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +56 -0
  20. data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +71 -0
  21. data/lib/instana/frameworks/rails.rb +5 -0
  22. data/lib/instana/test.rb +40 -0
  23. data/lib/instana/tracer.rb +19 -0
  24. data/lib/instana/tracing/span.rb +3 -3
  25. data/lib/instana/version.rb +1 -1
  26. data/log/.keep +0 -0
  27. data/test/agent/agent_test.rb +139 -0
  28. data/test/apps/cuba.rb +15 -0
  29. data/test/apps/roda.rb +10 -0
  30. data/test/apps/sinatra.rb +5 -0
  31. data/test/config_test.rb +17 -0
  32. data/test/frameworks/cuba_test.rb +44 -0
  33. data/test/frameworks/rack_test.rb +152 -0
  34. data/test/frameworks/rails/actioncontroller_test.rb +123 -0
  35. data/test/frameworks/rails/activerecord3_test.rb +134 -0
  36. data/test/frameworks/rails/activerecord4_test.rb +134 -0
  37. data/test/frameworks/rails/activerecord5_test.rb +90 -0
  38. data/test/frameworks/roda_test.rb +44 -0
  39. data/test/frameworks/sinatra_test.rb +44 -0
  40. data/test/instana_test.rb +27 -0
  41. data/test/instrumentation/dalli_test.rb +274 -0
  42. data/test/instrumentation/excon_test.rb +171 -0
  43. data/test/instrumentation/net-http_test.rb +140 -0
  44. data/test/instrumentation/rest-client_test.rb +61 -0
  45. data/test/models/block.rb +18 -0
  46. data/test/servers/rackapp_6511.rb +20 -0
  47. data/test/servers/rails_3205.rb +95 -0
  48. data/test/test_helper.rb +39 -0
  49. data/test/tracing/custom_test.rb +143 -0
  50. data/test/tracing/id_management_test.rb +96 -0
  51. data/test/tracing/opentracing_test.rb +377 -0
  52. data/test/tracing/trace_test.rb +50 -0
  53. data/test/tracing/tracer_async_test.rb +298 -0
  54. data/test/tracing/tracer_test.rb +202 -0
  55. metadata +114 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83702cf490019361b99d4c0096e4e12297a915e4
4
- data.tar.gz: a7d1b3d505cc1466d1bf5bf784641bf07228f91c
3
+ metadata.gz: d305a85a9022580df0cb7f1a997ae3249761eeca
4
+ data.tar.gz: 4ced318153f068d2d78ad2b24b3f417bf4e38552
5
5
  SHA512:
6
- metadata.gz: a3950247007e4aa9b70d08257e7b9fbb5ccf99e211f454415edd1a9140840745b11e81e045b3596c22383c3d3405a0d4594a2858419b44bed49d3114af7c0c11
7
- data.tar.gz: cf9910fa2bfa9bfd5e80b24f64539fadb9d235b523f7f9bf4f6d81ba0daf10627b117d62d6c2502af8ee45e0b4d9064c2cd53af22335c9ceb9d2b0e9359259e5
6
+ metadata.gz: ceb52cced4e372faf89bd2fd8b0d98a05287da16518bb6532d39c2fa61877ad8d8d4e699d8c0ea5de6bf0c35b218c474ff0bfeab342deb79f316c7ebb9edc3ec
7
+ data.tar.gz: cd0c7cf3c526a3ae1e346db0ebf6b39fc9ff70b75dffc1f606b9fd8d213e783138e5711f7b482e414ee1f44c352463b5792859ae2c66a0376acccfc92b1fd631
@@ -15,6 +15,8 @@ engines:
15
15
  checks:
16
16
  Rubocop/Metrics/CyclomaticComplexity:
17
17
  enabled: false
18
+ Rubocop/Lint/RescueException:
19
+ enabled: false
18
20
  ratings:
19
21
  paths:
20
22
  - "**.inc"
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .ruby-version
11
+ gemfiles/*.lock
@@ -3,10 +3,10 @@ language: ruby
3
3
  cache:
4
4
  bundler: true
5
5
  directories:
6
- - vendor/bundle
6
+ - vendor/bundle
7
7
 
8
8
  rvm:
9
- - 2.3.2
9
+ - 2.3.3
10
10
  - 2.2.6
11
11
  - 2.1.9
12
12
  - ruby-2.0.0-p648
@@ -17,11 +17,33 @@ before_install:
17
17
  - gem update bundler
18
18
  - gem --version
19
19
 
20
+ before_script:
21
+ - psql -c 'create database travis_ci_test;' -U postgres
22
+
20
23
  script: "bundle exec rake test"
21
24
 
22
25
  services:
23
26
  - memcached
24
27
 
28
+ gemfile:
29
+ - Gemfile
30
+ - gemfiles/libraries.gemfile
31
+ - gemfiles/rails50.gemfile
32
+ - gemfiles/rails42.gemfile
33
+ - gemfiles/rails32.gemfile
34
+
35
+ matrix:
36
+ exclude:
37
+ # Rails 5.0+ requires Ruby 2.2.2 or higher
38
+ - rvm: 2.1.9
39
+ gemfile: gemfiles/rails50.gemfile
40
+ - rvm: ruby-2.0.0-p648
41
+ gemfile: gemfiles/rails50.gemfile
42
+ - rvm: ruby-2.0.0-p648
43
+ gemfile: gemfiles/rails42.gemfile
44
+ - rvm: ruby-2.0.0-p648
45
+ gemfile: gemfiles/rails32.gemfile
46
+
25
47
  notifications:
26
48
  slack:
27
49
  rooms:
data/Gemfile CHANGED
@@ -5,30 +5,14 @@ group :development, :test do
5
5
  gem 'minitest', '5.9.1'
6
6
  gem 'minitest-reporters'
7
7
  gem 'minitest-debugger', :require => false
8
- gem 'rack-test'
9
8
  gem 'webmock'
10
-
11
- # Frameworks
12
- gem "sinatra", '1.4.7'
13
- gem "cuba"
14
- gem "roda"
15
-
16
- # HTTP Clients
17
- gem 'rest-client'
18
-
19
- # Webservers
20
- gem "puma"
21
-
22
- # HTTP Clients
23
- gem 'excon'
24
-
25
- # Memcache
26
- gem 'dalli'
9
+ gem 'puma'
27
10
 
28
11
  # Rack v2 dropped support for Ruby 2.2 and higher.
29
12
  if RUBY_VERSION < '2.2'
30
13
  gem 'rack', '< 2.0'
31
14
  end
15
+ gem 'rack-test'
32
16
  end
33
17
 
34
18
  group :development do
@@ -43,9 +27,5 @@ group :development do
43
27
  end
44
28
  end
45
29
 
46
- gem 'get_process_mem'
47
- gem 'sys-proctable'
48
- gem 'timers'
49
-
50
30
  # instana.gemspec
51
31
  gemspec
data/README.md CHANGED
@@ -50,7 +50,7 @@ Although the gem has no configuration required for out of the box metrics and tr
50
50
 
51
51
  ## Tracing
52
52
 
53
- See [Tracing.md](https://github.com/instana/ruby-sensor/blob/master/Tracing.md)
53
+ This Ruby gem provides a simple API for tracing and also supports [OpenTracing](http://opentracing.io/). See [Tracing.md](https://github.com/instana/ruby-sensor/blob/master/Tracing.md) for details.
54
54
 
55
55
  ## Documentation
56
56
 
data/Rakefile CHANGED
@@ -9,6 +9,21 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.libs << "test"
10
10
  t.libs << "lib"
11
11
  t.test_files = FileList['test/**/*_test.rb']
12
+
13
+ case File.basename(ENV['BUNDLE_GEMFILE']).split('.').first
14
+ when /rails50/
15
+ t.test_files = FileList['test/frameworks/rails/activerecord5_test.rb'] + FileList['test/frameworks/rails/actioncontroller_test.rb']
16
+ when /rails42/
17
+ t.test_files = FileList['test/frameworks/rails/activerecord4_test.rb'] + FileList['test/frameworks/rails/actioncontroller_test.rb']
18
+ when /rails32/
19
+ t.test_files = FileList['test/frameworks/rails/activerecord3_test.rb'] + FileList['test/frameworks/rails/actioncontroller_test.rb']
20
+ when /libraries/
21
+ t.test_files = FileList['test/instrumentation/*_test.rb']
22
+ else
23
+ t.test_files = FileList['test/agent/*_test.rb'] +
24
+ FileList['test/tracing/*_test.rb'] +
25
+ FileList['test/profiling/*_test.rb']
26
+ end
12
27
  end
13
28
 
14
29
  task :environment do
data/Tracing.md CHANGED
@@ -1,9 +1,36 @@
1
1
  # Tracing
2
2
 
3
3
  Tracing with Instana is automatic but if you want even more visibility into custom code or some in-house
4
- component, you can use the following API to report additional trace data to Instana.
4
+ component, you can use Instana's tracing API or [OpenTracing](http://opentracing.io/).
5
5
 
6
- # The API
6
+ # OpenTracing
7
+
8
+ Existing applications that utilize the OpenTracing API or those who wish to add support should have no problem
9
+ as the Instana Ruby gem fully supports the OpenTracing specification.
10
+
11
+ To start, simply set the Instana tracer as the global tracer for OpenTracing:
12
+
13
+ ```Ruby
14
+ require 'opentracing'
15
+ OpenTracing.global_tracer = ::Instana.tracer
16
+ ```
17
+
18
+ Then OpenTracing code can be run normally:
19
+
20
+ ```Ruby
21
+ begin
22
+ span = OpenTracing.start_span('job')
23
+ # The code to be instrumented
24
+ @id = User.find_by_name('john.smith')
25
+ span.set_tag(:job_id, @id)
26
+ rescue => e
27
+ span.set_tag(:error, e.message)
28
+ ensure
29
+ span.finish
30
+ end
31
+ ```
32
+
33
+ # The Instana Ruby API
7
34
 
8
35
  The Instana Ruby gem provides a simple to use API to trace any arbitrary part of your application.
9
36
 
@@ -0,0 +1,50 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'rake'
5
+ gem 'minitest', '5.9.1'
6
+ gem 'minitest-reporters'
7
+ gem 'minitest-debugger', :require => false
8
+ gem 'rack-test'
9
+ gem 'webmock'
10
+ gem 'puma'
11
+ end
12
+
13
+ group :development do
14
+ gem 'ruby-debug', :platforms => [:mri_18, :jruby]
15
+ gem 'debugger', :platform => :mri_19
16
+ gem 'byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
17
+ if RUBY_VERSION > '1.8.7'
18
+ gem 'pry'
19
+ gem 'pry-byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
20
+ else
21
+ gem 'pry', '0.9.12.4'
22
+ end
23
+ end
24
+
25
+ # Frameworks
26
+ gem "sinatra", '1.4.7'
27
+ gem "cuba"
28
+ gem "roda"
29
+
30
+ # HTTP Clients
31
+ gem 'rest-client'
32
+
33
+ # Webservers
34
+ gem "puma"
35
+
36
+ # HTTP Clients
37
+ gem 'excon'
38
+
39
+ # Memcache
40
+ gem 'dalli'
41
+
42
+ # Rack v2 dropped support for Ruby 2.2 and higher.
43
+ if RUBY_VERSION < '2.2'
44
+ gem 'rack', '< 2.0'
45
+ end
46
+
47
+ # Include the Instana Ruby gem's base set of gems
48
+ gemspec :path => File.expand_path(File.dirname(__FILE__) + '/../')
49
+
50
+ # vim:syntax=ruby
@@ -0,0 +1,45 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'rake'
5
+ gem 'minitest', '5.9.1'
6
+ gem 'minitest-reporters'
7
+ gem 'minitest-debugger', :require => false
8
+ gem 'rack-test'
9
+ gem 'webmock'
10
+ gem 'puma'
11
+ end
12
+
13
+ group :development do
14
+ gem 'ruby-debug', :platforms => [:mri_18, :jruby]
15
+ gem 'debugger', :platform => :mri_19
16
+ gem 'byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
17
+ if RUBY_VERSION > '1.8.7'
18
+ gem 'pry'
19
+ gem 'pry-byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
20
+ else
21
+ gem 'pry', '0.9.12.4'
22
+ end
23
+ end
24
+
25
+ gem 'rails', '3.2.22.5'
26
+ gem 'pg'
27
+ gem 'mysql2', '~> 0.3.10'
28
+ gem 'mysql'
29
+
30
+ # Gems used only for assets and not required
31
+ # in production environments by default.
32
+ group :assets do
33
+ gem 'sass-rails', '~> 3.2.3'
34
+ gem 'coffee-rails', '~> 3.2.1'
35
+ gem 'therubyracer', :platforms => :ruby
36
+ gem 'uglifier', '>= 1.0.3'
37
+ end
38
+
39
+ gem 'jquery-rails'
40
+
41
+ # Include the Instana Ruby gem's base set of gems
42
+ gemspec :path => File.expand_path(File.dirname(__FILE__) + '/../')
43
+
44
+ # vim:syntax=ruby
45
+
@@ -0,0 +1,44 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'rake'
5
+ gem 'minitest', '5.9.1'
6
+ gem 'minitest-reporters'
7
+ gem 'minitest-debugger', :require => false
8
+ gem 'rack-test'
9
+ gem 'webmock'
10
+ gem 'puma'
11
+ end
12
+
13
+ group :development do
14
+ gem 'ruby-debug', :platforms => [:mri_18, :jruby]
15
+ gem 'debugger', :platform => :mri_19
16
+ gem 'byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
17
+ if RUBY_VERSION > '1.8.7'
18
+ gem 'pry'
19
+ gem 'pry-byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
20
+ else
21
+ gem 'pry', '0.9.12.4'
22
+ end
23
+ end
24
+
25
+ gem 'rails', '4.2.7.1'
26
+ gem 'sqlite3'
27
+ gem 'sass-rails', '~> 5.0'
28
+ gem 'uglifier', '>= 1.3.0'
29
+ gem 'coffee-rails', '~> 4.1.0'
30
+ gem 'therubyracer', platforms: :ruby
31
+
32
+ gem 'jquery-rails'
33
+ gem 'turbolinks'
34
+ gem 'jbuilder', '~> 2.0'
35
+ gem 'sdoc', '~> 0.4.0', group: :doc
36
+ gem "pg"
37
+ gem "mysql2"
38
+ gem "mysql"
39
+
40
+ # Include the Instana Ruby gem's base set of gems
41
+ gemspec :path => File.expand_path(File.dirname(__FILE__) + '/../')
42
+
43
+ # vim:syntax=ruby
44
+
@@ -0,0 +1,44 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'rake'
5
+ gem 'minitest', '5.9.1'
6
+ gem 'minitest-reporters'
7
+ gem 'minitest-debugger', :require => false
8
+ gem 'rack-test'
9
+ gem 'webmock'
10
+ gem 'puma'
11
+ end
12
+
13
+ group :development do
14
+ gem 'ruby-debug', :platforms => [:mri_18, :jruby]
15
+ gem 'debugger', :platform => :mri_19
16
+ gem 'byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
17
+ if RUBY_VERSION > '1.8.7'
18
+ gem 'pry'
19
+ gem 'pry-byebug', :platforms => [:mri_20, :mri_21, :mri_22, :mri_23]
20
+ else
21
+ gem 'pry', '0.9.12.4'
22
+ end
23
+ end
24
+
25
+ gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
26
+ gem 'sass-rails', '~> 5.0'
27
+ gem 'uglifier', '>= 1.3.0'
28
+ gem 'coffee-rails', '~> 4.2'
29
+ gem 'therubyracer', platforms: :ruby
30
+
31
+ gem 'jquery-rails'
32
+ gem 'turbolinks', '~> 5'
33
+ gem 'jbuilder', '~> 2.5'
34
+
35
+ gem 'pg'
36
+ gem 'mysql2'
37
+
38
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
39
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
40
+
41
+ # Include the Instana Ruby gem's base set of gems
42
+ gemspec :path => File.expand_path(File.dirname(__FILE__) + '/../')
43
+
44
+ # vim:syntax=ruby
@@ -13,18 +13,11 @@ Gem::Specification.new do |spec|
13
13
  spec.description = %q{Provides Ruby sensor instrumentation for Instana.}
14
14
  spec.homepage = "https://www.instana.com/"
15
15
 
16
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
- # delete this section to allow pushing this gem to any host.
18
- #if spec.respond_to?(:metadata)
19
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- #else
21
- # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- #end
23
-
24
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
17
  spec.bindir = "exe"
26
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
19
  spec.require_paths = ["lib"]
20
+ spec.test_files = Dir.glob("{test}/**/*.rb")
28
21
 
29
22
  spec.required_ruby_version = '>= 2.0'
30
23
 
@@ -32,6 +25,11 @@ Gem::Specification.new do |spec|
32
25
  spec.add_development_dependency "rake", "~> 10.0"
33
26
  spec.add_development_dependency "minitest", "~> 5.0"
34
27
 
28
+ # Development debugging
29
+ spec.add_development_dependency('byebug', '>= 8.0.0')
30
+ spec.add_development_dependency('pry', '>= 0.10.0')
31
+ spec.add_development_dependency('pry-byebug', '>= 3.0.0')
32
+
35
33
  spec.add_runtime_dependency('sys-proctable', '>= 1.1.3')
36
34
  spec.add_runtime_dependency('get_process_mem', '>= 0.2.1')
37
35
  spec.add_runtime_dependency('timers', '>= 4.1.0')
@@ -20,11 +20,13 @@ module Instana
20
20
  @config[:eum_api_key] = nil
21
21
  @config[:eum_baggage] = {}
22
22
 
23
- # HTTP Clients
24
- @config[:dalli] = { :enabled => true }
25
- @config[:excon] = { :enabled => true }
26
- @config[:nethttp] = { :enabled => true }
27
- @config[:'rest-client'] = { :enabled => true }
23
+ # Instrumentation
24
+ @config[:action_controller] = { :enabled => true }
25
+ @config[:active_record] = { :enabled => true }
26
+ @config[:dalli] = { :enabled => true }
27
+ @config[:excon] = { :enabled => true }
28
+ @config[:nethttp] = { :enabled => true }
29
+ @config[:'rest-client'] = { :enabled => true }
28
30
  end
29
31
 
30
32
  def [](key)
@@ -0,0 +1,55 @@
1
+ module Instana
2
+ module Instrumentation
3
+ module AbstractMysqlAdapter
4
+ IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN CACHE).freeze
5
+ EXPLAINED_SQLS = /\A\s*(with|select|update|delete|insert)\b/i
6
+
7
+ # This module supports instrumenting ActiveRecord with the mysql2 adapter.
8
+ #
9
+ def self.included(klass)
10
+ if ActiveRecord::VERSION::STRING >= '3.2'
11
+ Instana::Util.method_alias(klass, :execute)
12
+
13
+ @@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE)
14
+ end
15
+ end
16
+
17
+ # Collect up this DB connection info for reporting.
18
+ #
19
+ # @param sql [String]
20
+ # @return [Hash] Hash of collected KVs
21
+ #
22
+ def collect(sql)
23
+ payload = { :activerecord => {} }
24
+ payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?')
25
+ payload[:activerecord][:adapter] = @config[:adapter]
26
+ payload[:activerecord][:host] = @config[:host]
27
+ payload[:activerecord][:db] = @config[:database]
28
+ payload[:activerecord][:username] = @config[:username]
29
+ payload
30
+ end
31
+
32
+ # In the spirit of ::ActiveRecord::ExplainSubscriber.ignore_payload? There are
33
+ # only certain calls that we're interested in tracing. e.g. No use to instrument
34
+ # framework caches.
35
+ #
36
+ # @param payload [String]
37
+ # @return [Boolean]
38
+ #
39
+ def ignore_payload?(name, sql)
40
+ IGNORED_PAYLOADS.include?(name) || sql !~ EXPLAINED_SQLS
41
+ end
42
+
43
+ def execute_with_instana(sql, name = nil)
44
+ if !::Instana.tracer.tracing? || ignore_payload?(name, sql)
45
+ return execute_without_instana(sql, name)
46
+ end
47
+
48
+ kv_payload = collect(sql)
49
+ ::Instana.tracer.trace(:activerecord, kv_payload) do
50
+ execute_without_instana(sql, name)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end