appsignal 3.2.1-java → 3.3.0-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.
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ if DependencyHelper.hanami2_present?
4
+ describe "Hanami integration" do
5
+ require "appsignal/integrations/hanami"
6
+
7
+ before do
8
+ allow(Appsignal).to receive(:active?).and_return(true)
9
+ allow(Appsignal).to receive(:start).and_return(true)
10
+ allow(Appsignal).to receive(:start_logger).and_return(true)
11
+ end
12
+
13
+ describe Appsignal::Integrations::HanamiPlugin do
14
+ it "starts AppSignal on init" do
15
+ expect(Appsignal).to receive(:start)
16
+ end
17
+
18
+ it "starts the logger on init" do
19
+ expect(Appsignal).to receive(:start_logger)
20
+ end
21
+
22
+ it "prepends the integration to Hanami" do
23
+ expect(::Hanami::Action).to receive(:send).with(:prepend, Appsignal::Integrations::HanamiIntegration)
24
+ end
25
+
26
+ context "when not active" do
27
+ before { allow(Appsignal).to receive(:active?).and_return(false) }
28
+
29
+ it "does not prepend the integration" do
30
+ expect(::Hanami::Action).to_not receive(:send).with(:prepend, Appsignal::Integrations::HanamiIntegration)
31
+ end
32
+ end
33
+
34
+ context "when APPSIGNAL_APP_ENV ENV var is provided" do
35
+ it "uses this as the environment" do
36
+ ENV["APPSIGNAL_APP_ENV"] = "custom"
37
+
38
+ # Reset the plugin to pull down the latest data
39
+ Appsignal::Integrations::HanamiPlugin.init
40
+
41
+ expect(Appsignal.config.env).to eq("custom")
42
+ end
43
+ end
44
+
45
+ context "when APPSIGNAL_APP_ENV ENV var is not provided" do
46
+ it "uses the Hanami environment" do
47
+ # Reset the plugin to pull down the latest data
48
+ Appsignal::Integrations::HanamiPlugin.init
49
+
50
+ expect(Appsignal.config.env).to eq("test")
51
+ end
52
+ end
53
+
54
+ after { Appsignal::Integrations::HanamiPlugin.init }
55
+ end
56
+
57
+ describe "Hanami Actions" do
58
+ let(:env) do
59
+ Rack::MockRequest.env_for(
60
+ "/books",
61
+ "router.params" => router_params,
62
+ :method => "GET"
63
+ )
64
+ end
65
+
66
+ let(:router_params) { { :foo => "bar", :baz => "qux" } }
67
+
68
+ describe "#call", :error => false do
69
+ it "sets params" do
70
+ expect_any_instance_of(Appsignal::Transaction).to receive(:params=).with(router_params)
71
+ end
72
+
73
+ it "sets the action name" do
74
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_action_if_nil).with("HanamiApp::Actions::Books::Index")
75
+ end
76
+
77
+ it "sets the metadata" do
78
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).with("status", "200")
79
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).with("path", "/books")
80
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).with("method", "GET")
81
+ end
82
+
83
+ it "sets the queue start" do
84
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_http_or_background_queue_start)
85
+ end
86
+
87
+ context "with error", :error => true do
88
+ let(:error) { HanamiApp::ExampleError }
89
+
90
+ it "records the exception" do
91
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_error).with(error)
92
+ end
93
+
94
+ it "sets the status to 500" do
95
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).with("status", "500")
96
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).twice
97
+ end
98
+ end
99
+
100
+ after(:error => false) do
101
+ Appsignal::Integrations::HanamiPlugin.init
102
+
103
+ action = HanamiApp::Actions::Books::Index.new
104
+ action.call(env)
105
+ end
106
+
107
+ after(:error => true) do
108
+ Appsignal::Integrations::HanamiPlugin.init
109
+
110
+ action = HanamiApp::Actions::Books::Error.new
111
+ expect { action.call(env) }.to raise_error(error)
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -42,6 +42,20 @@ describe Appsignal::Logger do
42
42
  logger.add(::Logger::DEBUG, "Log message")
43
43
  end
44
44
  end
45
+
46
+ context "with a formatter set" do
47
+ before do
48
+ logger.formatter = proc do |_level, _timestamp, _appname, message|
49
+ "formatted: '#{message}'"
50
+ end
51
+ end
52
+
53
+ it "should log with a level, message and group" do
54
+ expect(Appsignal::Extension).to receive(:log)
55
+ .with("other_group", 3, "formatted: 'Log message'", instance_of(Appsignal::Extension::Data))
56
+ logger.add(::Logger::INFO, "Log message", "other_group")
57
+ end
58
+ end
45
59
  end
46
60
 
47
61
  [
@@ -89,6 +103,20 @@ describe Appsignal::Logger do
89
103
  end
90
104
  end
91
105
  end
106
+
107
+ context "with a formatter set" do
108
+ before do
109
+ logger.formatter = proc do |_level, _timestamp, _appname, message|
110
+ "formatted: '#{message}'"
111
+ end
112
+ end
113
+
114
+ it "should log with a level, message and group" do
115
+ expect(Appsignal::Extension).to receive(:log)
116
+ .with("group", method[1], "formatted: 'Log message'", instance_of(Appsignal::Extension::Data))
117
+ logger.send(method[0], "Log message")
118
+ end
119
+ end
92
120
  end
93
121
  end
94
122
  end
@@ -42,10 +42,15 @@ describe Appsignal::Probes::MriProbe do
42
42
  allow(GC::Profiler).to receive(:enabled?).and_return(true)
43
43
  end
44
44
 
45
- it "should track vm metrics" do
45
+ it "should track vm cache metrics" do
46
46
  probe.call
47
- expect_gauge_value("ruby_vm", :tags => { :metric => :class_serial })
48
- expect_gauge_value("ruby_vm", :tags => { :metric => :global_constant_state })
47
+ if DependencyHelper.ruby_3_2_or_newer?
48
+ expect_gauge_value("ruby_vm", :tags => { :metric => :constant_cache_invalidations })
49
+ expect_gauge_value("ruby_vm", :tags => { :metric => :constant_cache_misses })
50
+ else
51
+ expect_gauge_value("ruby_vm", :tags => { :metric => :class_serial })
52
+ expect_gauge_value("ruby_vm", :tags => { :metric => :global_constant_state })
53
+ end
49
54
  end
50
55
 
51
56
  it "tracks thread counts" do
data/spec/spec_helper.rb CHANGED
@@ -29,6 +29,11 @@ if DependencyHelper.rails_present?
29
29
  require f
30
30
  end
31
31
  end
32
+ if DependencyHelper.hanami2_present?
33
+ Dir[File.join(DirectoryHelper.support_dir, "hanami", "*.rb")].each do |f|
34
+ require f
35
+ end
36
+ end
32
37
  require "pry" if DependencyHelper.dependency_present?("pry")
33
38
  require "appsignal"
34
39
  # Include patches of AppSignal modules and classes to make test helpers
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami"
4
+ require "hanami/action"
5
+
6
+ module HanamiApp
7
+ class App < Hanami::App
8
+ end
9
+
10
+ class Routes < Hanami::Routes
11
+ get "/books", :to => "books.index"
12
+ end
13
+
14
+ module Actions
15
+ module Books
16
+ class Index < Hanami::Action
17
+ def handle(_request, response)
18
+ response.body = "YOU REQUESTED BOOKS!"
19
+ end
20
+ end
21
+
22
+ class Error < Hanami::Action
23
+ def handle(_request, _response)
24
+ raise ExampleError
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ class ExampleError < StandardError; end
31
+ end
@@ -9,10 +9,18 @@ module DependencyHelper
9
9
  ruby_version.segments.take(2) == [2, 0]
10
10
  end
11
11
 
12
+ def ruby_3_0_or_newer?
13
+ ruby_version >= Gem::Version.new("3.0.0")
14
+ end
15
+
12
16
  def ruby_3_1_or_newer?
13
17
  ruby_version >= Gem::Version.new("3.1.0")
14
18
  end
15
19
 
20
+ def ruby_3_2_or_newer?
21
+ ruby_version >= Gem::Version.new("3.2.0")
22
+ end
23
+
16
24
  def running_jruby?
17
25
  Appsignal::System.jruby?
18
26
  end
@@ -111,6 +119,14 @@ module DependencyHelper
111
119
  dependency_present? "que"
112
120
  end
113
121
 
122
+ def hanami_present?
123
+ dependency_present? "hanami"
124
+ end
125
+
126
+ def hanami2_present?
127
+ ruby_3_0_or_newer? && hanami_present? && Gem.loaded_specs["hanami"].version >= Gem::Version.new("2.0")
128
+ end
129
+
114
130
  def dependency_present?(dependency_file)
115
131
  Gem.loaded_specs.key? dependency_file
116
132
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: java
6
6
  authors:
7
7
  - Robert Beekman
8
8
  - Thijs Cadier
9
9
  - Tom de Bruijn
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-11-21 00:00:00.000000000 Z
13
+ date: 2022-12-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -175,6 +175,7 @@ files:
175
175
  - gemfiles/capistrano2.gemfile
176
176
  - gemfiles/capistrano3.gemfile
177
177
  - gemfiles/grape.gemfile
178
+ - gemfiles/hanami.gemfile
178
179
  - gemfiles/http5.gemfile
179
180
  - gemfiles/no_dependencies.gemfile
180
181
  - gemfiles/padrino.gemfile
@@ -254,6 +255,7 @@ files:
254
255
  - lib/appsignal/integrations/delayed_job_plugin.rb
255
256
  - lib/appsignal/integrations/excon.rb
256
257
  - lib/appsignal/integrations/grape.rb
258
+ - lib/appsignal/integrations/hanami.rb
257
259
  - lib/appsignal/integrations/http.rb
258
260
  - lib/appsignal/integrations/mongo_ruby_driver.rb
259
261
  - lib/appsignal/integrations/net_http.rb
@@ -353,6 +355,7 @@ files:
353
355
  - spec/lib/appsignal/hooks_spec.rb
354
356
  - spec/lib/appsignal/integrations/data_mapper_spec.rb
355
357
  - spec/lib/appsignal/integrations/grape_spec.rb
358
+ - spec/lib/appsignal/integrations/hanami_spec.rb
356
359
  - spec/lib/appsignal/integrations/http_spec.rb
357
360
  - spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb
358
361
  - spec/lib/appsignal/integrations/object_spec.rb
@@ -392,6 +395,7 @@ files:
392
395
  - spec/support/fixtures/projects/valid/config/environments/test.rb
393
396
  - spec/support/fixtures/projects/valid/log/.gitkeep
394
397
  - spec/support/fixtures/uploaded_file.txt
398
+ - spec/support/hanami/hanami_app.rb
395
399
  - spec/support/helpers/action_mailer_helpers.rb
396
400
  - spec/support/helpers/activejob_helpers.rb
397
401
  - spec/support/helpers/api_request_helper.rb
@@ -432,7 +436,7 @@ metadata:
432
436
  documentation_uri: https://docs.appsignal.com/ruby/
433
437
  homepage_uri: https://docs.appsignal.com/ruby/
434
438
  source_code_uri: https://github.com/appsignal/appsignal-ruby
435
- post_install_message:
439
+ post_install_message:
436
440
  rdoc_options: []
437
441
  require_paths:
438
442
  - lib
@@ -448,8 +452,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
448
452
  - !ruby/object:Gem::Version
449
453
  version: '0'
450
454
  requirements: []
451
- rubygems_version: 3.3.7
452
- signing_key:
455
+ rubygems_version: 3.1.4
456
+ signing_key:
453
457
  specification_version: 4
454
458
  summary: Logs performance and exception data from your app to appsignal.com
455
459
  test_files:
@@ -508,6 +512,7 @@ test_files:
508
512
  - spec/lib/appsignal/hooks_spec.rb
509
513
  - spec/lib/appsignal/integrations/data_mapper_spec.rb
510
514
  - spec/lib/appsignal/integrations/grape_spec.rb
515
+ - spec/lib/appsignal/integrations/hanami_spec.rb
511
516
  - spec/lib/appsignal/integrations/http_spec.rb
512
517
  - spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb
513
518
  - spec/lib/appsignal/integrations/object_spec.rb
@@ -547,6 +552,7 @@ test_files:
547
552
  - spec/support/fixtures/projects/valid/config/environments/test.rb
548
553
  - spec/support/fixtures/projects/valid/log/.gitkeep
549
554
  - spec/support/fixtures/uploaded_file.txt
555
+ - spec/support/hanami/hanami_app.rb
550
556
  - spec/support/helpers/action_mailer_helpers.rb
551
557
  - spec/support/helpers/activejob_helpers.rb
552
558
  - spec/support/helpers/api_request_helper.rb