appsignal 3.0.2-java → 3.0.6-java

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.semaphore/semaphore.yml +64 -199
  3. data/CHANGELOG.md +42 -18
  4. data/Rakefile +12 -4
  5. data/appsignal.gemspec +19 -4
  6. data/build_matrix.yml +16 -24
  7. data/ext/agent.yml +17 -17
  8. data/ext/base.rb +12 -1
  9. data/gemfiles/capistrano2.gemfile +0 -1
  10. data/gemfiles/capistrano3.gemfile +0 -1
  11. data/gemfiles/grape.gemfile +0 -1
  12. data/gemfiles/no_dependencies.gemfile +2 -6
  13. data/gemfiles/rails-3.2.gemfile +2 -0
  14. data/gemfiles/rails-4.2.gemfile +6 -0
  15. data/gemfiles/resque-2.gemfile +0 -4
  16. data/gemfiles/sequel-435.gemfile +0 -1
  17. data/gemfiles/sequel.gemfile +0 -1
  18. data/gemfiles/sinatra.gemfile +0 -1
  19. data/lib/appsignal/extension.rb +50 -0
  20. data/lib/appsignal/helpers/instrumentation.rb +2 -2
  21. data/lib/appsignal/hooks.rb +2 -1
  22. data/lib/appsignal/hooks/excon.rb +19 -0
  23. data/lib/appsignal/integrations/excon.rb +20 -0
  24. data/lib/appsignal/integrations/padrino.rb +1 -1
  25. data/lib/appsignal/integrations/railtie.rb +1 -1
  26. data/lib/appsignal/integrations/redis.rb +8 -5
  27. data/lib/appsignal/integrations/sinatra.rb +1 -1
  28. data/lib/appsignal/transaction.rb +2 -2
  29. data/lib/appsignal/version.rb +1 -1
  30. data/mono.yml +16 -0
  31. data/spec/lib/appsignal/cli/diagnose_spec.rb +1 -0
  32. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -7
  33. data/spec/lib/appsignal/extension_spec.rb +43 -9
  34. data/spec/lib/appsignal/hooks/excon_spec.rb +74 -0
  35. data/spec/lib/appsignal/hooks/redis_spec.rb +34 -10
  36. data/spec/lib/appsignal/hooks_spec.rb +4 -1
  37. data/spec/lib/appsignal/transaction_spec.rb +17 -0
  38. data/spec/lib/appsignal/utils/data_spec.rb +133 -87
  39. data/spec/lib/appsignal_spec.rb +2 -2
  40. data/spec/lib/puma/appsignal_spec.rb +1 -1
  41. data/spec/spec_helper.rb +22 -0
  42. data/spec/support/testing.rb +11 -1
  43. data/support/install_deps +9 -8
  44. metadata +8 -5
  45. data/gemfiles/rails-4.0.gemfile +0 -6
  46. data/gemfiles/rails-4.1.gemfile +0 -6
@@ -4,7 +4,3 @@ gem 'resque', "~> 2.0"
4
4
  gem 'sinatra'
5
5
 
6
6
  gemspec :path => '../'
7
-
8
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1.0")
9
- gem 'nokogiri', '~> 1.6.0'
10
- end
@@ -6,6 +6,5 @@ if RUBY_PLATFORM == "java"
6
6
  else
7
7
  gem 'sqlite3'
8
8
  end
9
- gem 'rack', '~> 1.6'
10
9
 
11
10
  gemspec :path => '../'
@@ -6,6 +6,5 @@ if RUBY_PLATFORM == "java"
6
6
  else
7
7
  gem 'sqlite3'
8
8
  end
9
- gem 'rack', '~> 1.6'
10
9
 
11
10
  gemspec :path => '../'
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'sinatra'
4
- gem 'rack', '~> 1.6'
5
4
 
6
5
  gemspec :path => '../'
@@ -40,6 +40,16 @@ module Appsignal
40
40
  def method_missing(m, *args, &block)
41
41
  super if Appsignal.testing?
42
42
  end
43
+
44
+ unless Appsignal.extension_loaded?
45
+ def data_map_new
46
+ Appsignal::Extension::MockData.new
47
+ end
48
+
49
+ def data_array_new
50
+ Appsignal::Extension::MockData.new
51
+ end
52
+ end
43
53
  end
44
54
 
45
55
  if Appsignal::System.jruby?
@@ -62,5 +72,45 @@ module Appsignal
62
72
  "#<#{self.class.name}:#{object_id} #{self}>"
63
73
  end
64
74
  end
75
+
76
+ # Mock of the {Data} class. This mock is used when the extension cannot be
77
+ # loaded. This mock listens to all method calls and does nothing, and
78
+ # prevents NoMethodErrors from being raised.
79
+ #
80
+ # Disabled in testing so we can make sure that we don't miss an extension
81
+ # function implementation.
82
+ #
83
+ # This class inherits from the {Data} class so that it passes type checks.
84
+ class MockData < Data
85
+ def initialize(*_args)
86
+ # JRuby extension requirement, as it sends a pointer to the Data object
87
+ # when creating it
88
+ end
89
+
90
+ def method_missing(_method, *_args, &_block)
91
+ super if Appsignal.testing?
92
+ end
93
+
94
+ def to_s
95
+ "{}"
96
+ end
97
+ end
98
+
99
+ # Mock of the {Transaction} class. This mock is used when the extension
100
+ # cannot be loaded. This mock listens to all method calls and does nothing,
101
+ # and prevents NoMethodErrors from being raised.
102
+ #
103
+ # Disabled in testing so we can make sure that we don't miss an extension
104
+ # function implementation.
105
+ class MockTransaction
106
+ def initialize(*_args)
107
+ # JRuby extension requirement, as it sends a pointer to the Transaction
108
+ # object when creating it
109
+ end
110
+
111
+ def method_missing(_method, *_args, &_block)
112
+ super if Appsignal.testing?
113
+ end
114
+ end
65
115
  end
66
116
  end
@@ -223,7 +223,7 @@ module Appsignal
223
223
  "The namespace argument for `Appsignal.send_error` is deprecated. " \
224
224
  "Please use the block method to set the namespace instead.\n\n" \
225
225
  " Appsignal.send_error(error) do |transaction|\n" \
226
- " transaction.namespace(#{namespace.inspect})\n" \
226
+ " transaction.set_namespace(#{namespace.inspect})\n" \
227
227
  " end\n\n" \
228
228
  "Appsignal.send_error called on location: #{call_location}"
229
229
  end
@@ -316,7 +316,7 @@ module Appsignal
316
316
  "The namespace argument for `Appsignal.set_error` is deprecated. " \
317
317
  "Please use the block method to set the namespace instead.\n\n" \
318
318
  " Appsignal.set_error(error) do |transaction|\n" \
319
- " transaction.namespace(#{namespace.inspect})\n" \
319
+ " transaction.set_namespace(#{namespace.inspect})\n" \
320
320
  " end\n\n" \
321
321
  "Appsignal.set_error called on location: #{call_location}"
322
322
  end
@@ -32,7 +32,7 @@ module Appsignal
32
32
  return unless dependencies_present?
33
33
  return if installed?
34
34
 
35
- Appsignal.logger.info("Installing #{name} hook")
35
+ Appsignal.logger.debug("Installing #{name} hook")
36
36
  begin
37
37
  install
38
38
  @installed = true
@@ -108,3 +108,4 @@ require "appsignal/hooks/mongo_ruby_driver"
108
108
  require "appsignal/hooks/webmachine"
109
109
  require "appsignal/hooks/data_mapper"
110
110
  require "appsignal/hooks/que"
111
+ require "appsignal/hooks/excon"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appsignal
4
+ class Hooks
5
+ # @api private
6
+ class ExconHook < Appsignal::Hooks::Hook
7
+ register :excon
8
+
9
+ def dependencies_present?
10
+ Appsignal.config && defined?(::Excon)
11
+ end
12
+
13
+ def install
14
+ require "appsignal/integrations/excon"
15
+ ::Excon.defaults[:instrumentor] = Appsignal::Integrations::ExconIntegration
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appsignal
4
+ module Integrations
5
+ module ExconIntegration
6
+ def self.instrument(name, data, &block)
7
+ namespace, *event = name.split(".")
8
+ rails_name = [event, namespace].flatten.join(".")
9
+
10
+ title =
11
+ if rails_name == "response.excon"
12
+ data[:host]
13
+ else
14
+ "#{data[:method].to_s.upcase} #{data[:scheme]}://#{data[:host]}"
15
+ end
16
+ Appsignal.instrument(rails_name, title, &block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -7,7 +7,7 @@ module Appsignal
7
7
  # @api private
8
8
  module PadrinoPlugin
9
9
  def self.init
10
- Appsignal.logger.info("Loading Padrino (#{Padrino::VERSION}) integration")
10
+ Appsignal.logger.debug("Loading Padrino (#{Padrino::VERSION}) integration")
11
11
 
12
12
  root = Padrino.mounted_root
13
13
  Appsignal.config = Appsignal::Config.new(root, Padrino.env)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Appsignal.logger.info("Loading Rails (#{Rails.version}) integration")
3
+ Appsignal.logger.debug("Loading Rails (#{Rails.version}) integration")
4
4
 
5
5
  require "appsignal/utils/rails_helper"
6
6
  require "appsignal/rack/rails_instrumentation"
@@ -3,12 +3,15 @@
3
3
  module Appsignal
4
4
  module Integrations
5
5
  module RedisIntegration
6
- def process(commands, &block)
7
- sanitized_commands = commands.map do |command, *args|
8
- "#{command}#{" ?" * args.size}"
9
- end.join("\n")
6
+ def write(command)
7
+ sanitized_command =
8
+ if command[0] == :eval
9
+ "#{command[1]}#{" ?" * (command.size - 3)}"
10
+ else
11
+ "#{command[0]}#{" ?" * (command.size - 1)}"
12
+ end
10
13
 
11
- Appsignal.instrument "query.redis", id, sanitized_commands do
14
+ Appsignal.instrument "query.redis", id, sanitized_command do
12
15
  super
13
16
  end
14
17
  end
@@ -3,7 +3,7 @@
3
3
  require "appsignal"
4
4
  require "appsignal/rack/sinatra_instrumentation"
5
5
 
6
- Appsignal.logger.info("Loading Sinatra (#{Sinatra::VERSION}) integration")
6
+ Appsignal.logger.debug("Loading Sinatra (#{Sinatra::VERSION}) integration")
7
7
 
8
8
  app_settings = ::Sinatra::Application.settings
9
9
  Appsignal.config = Appsignal::Config.new(
@@ -90,7 +90,7 @@ module Appsignal
90
90
  @transaction_id,
91
91
  @namespace,
92
92
  self.class.garbage_collection_profiler.total_time
93
- )
93
+ ) || Appsignal::Extension::MockTransaction.new
94
94
  end
95
95
 
96
96
  def nil_transaction?
@@ -228,7 +228,7 @@ module Appsignal
228
228
  # "Web" and "background_job" gets transformed to "Background".
229
229
  #
230
230
  # @example
231
- # transaction.set_action("admin")
231
+ # transaction.set_namespace("background")
232
232
  #
233
233
  # @param namespace [String] namespace name to use for this transaction.
234
234
  # @return [void]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "3.0.2".freeze
4
+ VERSION = "3.0.6".freeze
5
5
  end
data/mono.yml ADDED
@@ -0,0 +1,16 @@
1
+ ---
2
+ language: ruby
3
+ repo: "https://github.com/appsignal/appsignal-ruby"
4
+ bootstrap:
5
+ post:
6
+ - "rake extension:install"
7
+ clean:
8
+ post:
9
+ - "bundle exec rake extension:clean"
10
+ - "rm -rf pkg"
11
+ build:
12
+ command: "bundle exec rake build:all"
13
+ publish:
14
+ gem_files_dir: pkg/
15
+ test:
16
+ command: "bundle exec rake test"
@@ -115,6 +115,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
115
115
  it "logs to the log file" do
116
116
  run
117
117
  log_contents = File.read(config.log_file_path)
118
+ p log_contents
118
119
  expect(log_contents).to contains_log :info, "Starting AppSignal diagnose"
119
120
  end
120
121
 
@@ -1,13 +1,6 @@
1
1
  describe Appsignal::Extension, :extension_installation_failure do
2
2
  context "when the extension library cannot be loaded" do
3
- # This test breaks the installation on purpose and is not run by default.
4
- # See `rake test:failure`. If this test was run, run `rake
5
- # extension:install` again to fix the extension installation.
6
3
  it "prints and logs an error" do
7
- # ENV var to make sure installation fails on purpurse
8
- ENV["_TEST_APPSIGNAL_EXTENSION_FAILURE"] = "true"
9
- `rake extension:install` # Run installation
10
-
11
4
  require "open3"
12
5
  _stdout, stderr, _status = Open3.capture3("bin/appsignal --version")
13
6
  expect(stderr).to include("ERROR: AppSignal failed to load extension")
@@ -119,22 +119,56 @@ describe Appsignal::Extension do
119
119
  end
120
120
  end
121
121
 
122
- context "when the extension library cannot be loaded" do
123
- subject { Appsignal::Extension }
122
+ context "when the extension library cannot be loaded", :extension_installation_failure do
123
+ let(:ext) { Appsignal::Extension }
124
124
 
125
- before do
126
- allow(Appsignal).to receive(:extension_loaded).and_return(false)
127
- allow(Appsignal).to receive(:testing?).and_return(false)
125
+ around do |example|
126
+ Appsignal::Testing.without_testing { example.run }
128
127
  end
129
128
 
130
129
  it "should indicate that the extension is not loaded" do
131
130
  expect(Appsignal.extension_loaded?).to be_falsy
132
131
  end
133
132
 
134
- it "should not raise errors when methods are called" do
135
- expect do
136
- subject.something
137
- end.not_to raise_error
133
+ it "does not raise errors when methods are called" do
134
+ ext.appsignal_start
135
+ ext.something
136
+ end
137
+
138
+ describe Appsignal::Extension::MockData do
139
+ it "does not error on missing data_map_new extension method calls" do
140
+ map = ext.data_map_new
141
+ expect(map).to be_kind_of(Appsignal::Extension::MockData)
142
+ # Does not raise errors any arbitrary method call that does not exist
143
+ map.set_string("key", "value")
144
+ map.set_int("key", 123)
145
+ map.something
146
+ end
147
+
148
+ it "does not error on missing data_array_new extension method calls" do
149
+ array = ext.data_array_new
150
+ expect(array).to be_kind_of(Appsignal::Extension::MockData)
151
+ # Does not raise errors any arbitrary method call that does not exist
152
+ array.append_string("value")
153
+ array.append_int(123)
154
+ array.something
155
+ end
156
+ end
157
+
158
+ describe Appsignal::Extension::MockTransaction do
159
+ it "does not error on missing transaction extension method calls" do
160
+ transaction = described_class.new
161
+
162
+ transaction.start_event(0)
163
+ transaction.finish_event(
164
+ "name",
165
+ "title",
166
+ "body",
167
+ Appsignal::EventFormatter::DEFAULT,
168
+ 0
169
+ )
170
+ transaction.something
171
+ end
138
172
  end
139
173
  end
140
174
  end
@@ -0,0 +1,74 @@
1
+ describe Appsignal::Hooks::ExconHook do
2
+ before :context do
3
+ start_agent
4
+ end
5
+
6
+ context "with Excon" do
7
+ before(:context) do
8
+ class Excon
9
+ def self.defaults
10
+ @defaults ||= {}
11
+ end
12
+ end
13
+ Appsignal::Hooks::ExconHook.new.install
14
+ end
15
+ after(:context) { Object.send(:remove_const, :Excon) }
16
+
17
+ describe "#dependencies_present?" do
18
+ subject { described_class.new.dependencies_present? }
19
+
20
+ it { is_expected.to be_truthy }
21
+ end
22
+
23
+ describe "#install" do
24
+ it "adds the AppSignal instrumentor to Excon" do
25
+ expect(Excon.defaults[:instrumentor]).to eql(Appsignal::Integrations::ExconIntegration)
26
+ end
27
+ end
28
+
29
+ describe "instrumentation" do
30
+ let!(:transaction) do
31
+ Appsignal::Transaction.create("uuid", Appsignal::Transaction::HTTP_REQUEST, "test")
32
+ end
33
+ around { |example| keep_transactions { example.run } }
34
+
35
+ it "instruments a http request" do
36
+ data = {
37
+ :host => "www.google.com",
38
+ :method => :get,
39
+ :scheme => "http"
40
+ }
41
+ Excon.defaults[:instrumentor].instrument("excon.request", data) {}
42
+
43
+ expect(transaction.to_h["events"]).to include(
44
+ hash_including(
45
+ "name" => "request.excon",
46
+ "title" => "GET http://www.google.com",
47
+ "body" => ""
48
+ )
49
+ )
50
+ end
51
+
52
+ it "instruments a http response" do
53
+ data = { :host => "www.google.com" }
54
+ Excon.defaults[:instrumentor].instrument("excon.response", data) {}
55
+
56
+ expect(transaction.to_h["events"]).to include(
57
+ hash_including(
58
+ "name" => "response.excon",
59
+ "title" => "www.google.com",
60
+ "body" => ""
61
+ )
62
+ )
63
+ end
64
+ end
65
+ end
66
+
67
+ context "without Excon" do
68
+ describe "#dependencies_present?" do
69
+ subject { described_class.new.dependencies_present? }
70
+
71
+ it { is_expected.to be_falsy }
72
+ end
73
+ end
74
+ end
@@ -33,16 +33,17 @@ describe Appsignal::Hooks::RedisHook do
33
33
 
34
34
  context "instrumentation" do
35
35
  before do
36
+ start_agent
36
37
  # Stub Redis::Client class so that it doesn't perform an actual
37
38
  # Redis query. This class will be included (prepended) with the
38
39
  # AppSignal Redis integration.
39
40
  stub_const("Redis::Client", Class.new do
40
41
  def id
41
- :stub_id
42
+ "stub_id"
42
43
  end
43
44
 
44
- def process(_commands)
45
- :stub_process
45
+ def write(_commands)
46
+ "stub_write"
46
47
  end
47
48
  end)
48
49
  # Load the integration again for the stubbed Redis::Client class.
@@ -50,17 +51,40 @@ describe Appsignal::Hooks::RedisHook do
50
51
  # track if it was installed already or not.
51
52
  Appsignal::Hooks::RedisHook.new.install
52
53
  end
54
+ let!(:transaction) do
55
+ Appsignal::Transaction.create("uuid", Appsignal::Transaction::HTTP_REQUEST, "test")
56
+ end
57
+ around { |example| keep_transactions { example.run } }
53
58
 
54
59
  it "instrument a redis call" do
55
- Appsignal::Transaction.create("uuid", Appsignal::Transaction::HTTP_REQUEST, "test")
56
- expect(Appsignal::Transaction.current).to receive(:start_event)
57
- .at_least(:once)
58
- expect(Appsignal::Transaction.current).to receive(:finish_event)
59
- .at_least(:once)
60
- .with("query.redis", :stub_id, "get ?", 0)
60
+ client = Redis::Client.new
61
+ expect(client.write([:get, "key"])).to eql("stub_write")
61
62
 
63
+ transaction_hash = transaction.to_h
64
+ expect(transaction_hash["events"]).to include(
65
+ hash_including(
66
+ "name" => "query.redis",
67
+ "body" => "get ?",
68
+ "title" => "stub_id"
69
+ )
70
+ )
71
+ end
72
+
73
+ it "instrument a redis script call" do
62
74
  client = Redis::Client.new
63
- expect(client.process([[:get, "key"]])).to eql(:stub_process)
75
+ script = "return redis.call('set',KEYS[1],ARGV[1])"
76
+ keys = ["foo"]
77
+ argv = ["bar"]
78
+ expect(client.write([:eval, script, keys.size, keys, argv])).to eql("stub_write")
79
+
80
+ transaction_hash = transaction.to_h
81
+ expect(transaction_hash["events"]).to include(
82
+ hash_including(
83
+ "name" => "query.redis",
84
+ "body" => "#{script} ? ?",
85
+ "title" => "stub_id"
86
+ )
87
+ )
64
88
  end
65
89
  end
66
90
  end