appsignal 2.10.6 → 2.11.0.alpha.1

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.
@@ -1,21 +1,18 @@
1
- if DependencyHelper.resque_present? && DependencyHelper.active_job_present?
1
+ if DependencyHelper.active_job_present?
2
2
  require "active_job"
3
+ require File.expand_path("lib/appsignal/integrations/resque_active_job.rb")
4
+
5
+ class TestActiveJob < ActiveJob::Base
6
+ include Appsignal::Integrations::ResqueActiveJobPlugin
7
+
8
+ def perform(_)
9
+ end
10
+ end
3
11
 
4
12
  describe Appsignal::Integrations::ResqueActiveJobPlugin do
5
- let(:file) { File.expand_path("lib/appsignal/integrations/resque_active_job.rb") }
6
13
  let(:args) { "argument" }
7
14
  let(:job) { TestActiveJob.new(args) }
8
- before do
9
- load file
10
- start_agent
11
-
12
- class TestActiveJob < ActiveJob::Base
13
- include Appsignal::Integrations::ResqueActiveJobPlugin
14
-
15
- def perform(_)
16
- end
17
- end
18
- end
15
+ before { start_agent }
19
16
 
20
17
  def perform
21
18
  keep_transactions do
@@ -141,5 +138,50 @@ if DependencyHelper.resque_present? && DependencyHelper.active_job_present?
141
138
  end
142
139
  end
143
140
  end
141
+
142
+ context "without queue time" do
143
+ it "does not add queue time to transaction" do
144
+ # TODO: Not available in transaction.to_h yet.
145
+ # https://github.com/appsignal/appsignal-agent/issues/293
146
+ expect(Appsignal).to receive(:monitor_single_transaction).with(
147
+ "perform_job.resque",
148
+ a_hash_including(:queue_start => nil)
149
+ ).and_call_original
150
+
151
+ perform
152
+ expect(last_transaction.to_h).to include(
153
+ "namespace" => Appsignal::Transaction::BACKGROUND_JOB,
154
+ "action" => "TestActiveJob#perform",
155
+ "events" => [
156
+ hash_including("name" => "perform_job.resque")
157
+ ]
158
+ )
159
+ end
160
+ end
161
+
162
+ if DependencyHelper.rails6_present?
163
+ context "with queue time" do
164
+ it "adds queue time to transction" do
165
+ queue_start = "2017-01-01 10:01:00UTC"
166
+ queue_start_time = Time.parse(queue_start)
167
+ # TODO: Not available in transaction.to_h yet.
168
+ # https://github.com/appsignal/appsignal-agent/issues/293
169
+ expect(Appsignal).to receive(:monitor_single_transaction).with(
170
+ "perform_job.resque",
171
+ a_hash_including(:queue_start => queue_start_time)
172
+ ).and_call_original
173
+ job.enqueued_at = queue_start
174
+
175
+ perform
176
+ expect(last_transaction.to_h).to include(
177
+ "namespace" => Appsignal::Transaction::BACKGROUND_JOB,
178
+ "action" => "TestActiveJob#perform",
179
+ "events" => [
180
+ hash_including("name" => "perform_job.resque")
181
+ ]
182
+ )
183
+ end
184
+ end
185
+ end
144
186
  end
145
187
  end
@@ -93,40 +93,4 @@ describe Appsignal::System do
93
93
  end
94
94
  end
95
95
  end
96
-
97
- describe ".ruby_2_or_up?" do
98
- around do |example|
99
- original_ruby_version = RUBY_VERSION
100
- Object.send(:remove_const, "RUBY_VERSION")
101
- Object.const_set("RUBY_VERSION", ruby_version)
102
- example.run
103
- Object.send(:remove_const, "RUBY_VERSION")
104
- Object.const_set("RUBY_VERSION", original_ruby_version)
105
- end
106
- subject { described_class.ruby_2_or_up? }
107
-
108
- context "when on Ruby 1.9" do
109
- let(:ruby_version) { "1.9.3-p533" }
110
-
111
- it "returns false" do
112
- is_expected.to be(false)
113
- end
114
- end
115
-
116
- context "when on Ruby 2.0" do
117
- let(:ruby_version) { "2.0.0" }
118
-
119
- it "returns true" do
120
- is_expected.to be(true)
121
- end
122
- end
123
-
124
- context "when on Ruby 2.x" do
125
- let(:ruby_version) { "2.1.0" }
126
-
127
- it "returns true" do
128
- is_expected.to be(true)
129
- end
130
- end
131
- end
132
96
  end
@@ -500,23 +500,40 @@ describe Appsignal::Transaction do
500
500
  end
501
501
 
502
502
  describe "#set_http_or_background_queue_start" do
503
- context "for a http transaction" do
504
- let(:namespace) { Appsignal::Transaction::HTTP_REQUEST }
505
- let(:env) { { "HTTP_X_REQUEST_START" => (fixed_time * 1000).to_s } }
503
+ let(:header_factor) { 1_000 }
504
+ let(:env_queue_start) { fixed_time + 20 } # in seconds
506
505
 
507
- it "should set the queue start on the transaction" do
508
- expect(transaction).to receive(:set_queue_start).with(13_897_836_000)
506
+ context "when a queue time is found in a request header" do
507
+ let(:header_time) { ((fixed_time + 10) * header_factor).to_i } # in milliseconds
508
+ let(:env) { { "HTTP_X_REQUEST_START" => "t=#{header_time}" } }
509
+
510
+ it "sets the http header value in milliseconds on the transaction" do
511
+ expect(transaction).to receive(:set_queue_start).with(1_389_783_610_000)
509
512
 
510
513
  transaction.set_http_or_background_queue_start
511
514
  end
515
+
516
+ context "when a :queue_start key is found in the transaction environment" do
517
+ let(:env) do
518
+ {
519
+ "HTTP_X_REQUEST_START" => "t=#{header_time}",
520
+ :queue_start => env_queue_start
521
+ }
522
+ end
523
+
524
+ it "sets the http header value in milliseconds on the transaction" do
525
+ expect(transaction).to receive(:set_queue_start).with(1_389_783_610_000)
526
+
527
+ transaction.set_http_or_background_queue_start
528
+ end
529
+ end
512
530
  end
513
531
 
514
- context "for a background transaction" do
515
- let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
516
- let(:env) { { :queue_start => fixed_time } }
532
+ context "when a :queue_start key is found in the transaction environment" do
533
+ let(:env) { { :queue_start => env_queue_start } } # in seconds
517
534
 
518
- it "should set the queue start on the transaction" do
519
- expect(transaction).to receive(:set_queue_start).with(1_389_783_600_000)
535
+ it "sets the :queue_start value in milliseconds on the transaction" do
536
+ expect(transaction).to receive(:set_queue_start).with(1_389_783_620_000)
520
537
 
521
538
  transaction.set_http_or_background_queue_start
522
539
  end
@@ -910,7 +927,7 @@ describe Appsignal::Transaction do
910
927
  context "when queue start is set" do
911
928
  let(:env) { background_env_with_data }
912
929
 
913
- it { is_expected.to eq 1_389_783_590_000 }
930
+ it { is_expected.to eq 1_389_783_600_000 }
914
931
  end
915
932
  end
916
933
 
@@ -949,7 +966,7 @@ describe Appsignal::Transaction do
949
966
  it { is_expected.to be_nil }
950
967
  end
951
968
 
952
- context "with some cruft" do
969
+ context "with unparsable content at the end" do
953
970
  let(:env) { { "HTTP_X_REQUEST_START" => "t=#{slightly_earlier_time_value}aaaa" } }
954
971
 
955
972
  it { is_expected.to eq 1_389_783_599_600 }
@@ -969,7 +986,7 @@ describe Appsignal::Transaction do
969
986
  end
970
987
  end
971
988
 
972
- context "time in miliseconds" do
989
+ context "time in milliseconds" do
973
990
  let(:factor) { 1_000 }
974
991
 
975
992
  it_should_behave_like "http queue start"
@@ -1,4 +1,6 @@
1
1
  describe Appsignal do
2
+ include EnvironmentMetadataHelper
3
+
2
4
  before do
3
5
  # Make sure we have a clean state because we want to test
4
6
  # initialization here.
@@ -80,18 +82,22 @@ describe Appsignal do
80
82
  allow(GC::Profiler).to receive(:enable)
81
83
  Appsignal.config.config_hash[:enable_allocation_tracking] = true
82
84
  Appsignal.config.config_hash[:enable_gc_instrumentation] = true
85
+ capture_environment_metadata_report_calls
83
86
  end
84
87
 
85
88
  it "should enable Ruby's GC::Profiler" do
86
89
  expect(GC::Profiler).to receive(:enable)
87
90
  Appsignal.start
91
+ expect_environment_metadata("ruby_gc_instrumentation_enabled", "true")
88
92
  end
89
93
 
90
94
  unless Appsignal::System.jruby?
95
+
91
96
  it "installs the allocation event hook" do
92
97
  expect(Appsignal::Extension).to receive(:install_allocation_event_hook)
93
98
  .and_call_original
94
99
  Appsignal.start
100
+ expect_environment_metadata("ruby_allocation_tracking_enabled", "true")
95
101
  end
96
102
  end
97
103
  end
@@ -100,6 +106,7 @@ describe Appsignal do
100
106
  before do
101
107
  Appsignal.config.config_hash[:enable_allocation_tracking] = false
102
108
  Appsignal.config.config_hash[:enable_gc_instrumentation] = false
109
+ capture_environment_metadata_report_calls
103
110
  end
104
111
 
105
112
  it "should not enable Ruby's GC::Profiler" do
@@ -110,11 +117,13 @@ describe Appsignal do
110
117
  it "should not install the allocation event hook" do
111
118
  expect(Appsignal::Minutely).not_to receive(:install_allocation_event_hook)
112
119
  Appsignal.start
120
+ expect_not_environment_metadata("ruby_allocation_tracking_enabled")
113
121
  end
114
122
 
115
123
  it "should not add the gc probe to minutely" do
116
124
  expect(Appsignal::Minutely).not_to receive(:register_garbage_collection_probe)
117
125
  Appsignal.start
126
+ expect_not_environment_metadata("ruby_gc_instrumentation_enabled")
118
127
  end
119
128
  end
120
129
 
@@ -139,6 +148,19 @@ describe Appsignal do
139
148
  Appsignal.start
140
149
  end
141
150
  end
151
+
152
+ describe "environment metadata" do
153
+ before { capture_environment_metadata_report_calls }
154
+
155
+ it "collects and reports environment metadata" do
156
+ Appsignal.start
157
+ expect_environment_metadata("ruby_version", "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}")
158
+ expect_environment_metadata("ruby_engine", RUBY_ENGINE)
159
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3.0")
160
+ expect_environment_metadata("ruby_engine_version", RUBY_ENGINE_VERSION)
161
+ end
162
+ end
163
+ end
142
164
  end
143
165
 
144
166
  context "with debug logging" do
@@ -9,6 +9,11 @@ module DependencyHelper
9
9
  dependency_present? "rails"
10
10
  end
11
11
 
12
+ def rails6_present?
13
+ rails_present? &&
14
+ Gem.loaded_specs["rails"].version >= Gem::Version.new("6.0.0")
15
+ end
16
+
12
17
  def sequel_present?
13
18
  dependency_present? "sequel"
14
19
  end
@@ -27,7 +27,7 @@ module EnvHelpers
27
27
  :priority => 1,
28
28
  :attempts => 0,
29
29
  :queue => "default",
30
- :queue_start => fixed_time - 10.0
30
+ :queue_start => fixed_time
31
31
  }.merge(args)
32
32
  end
33
33
  end
@@ -0,0 +1,16 @@
1
+ module EnvironmentMetadataHelper
2
+ def capture_environment_metadata_report_calls
3
+ allow(Appsignal::Extension).to receive(:set_environment_metadata)
4
+ .and_call_original
5
+ end
6
+
7
+ def expect_environment_metadata(key, value)
8
+ expect(Appsignal::Extension).to have_received(:set_environment_metadata)
9
+ .with(key, value)
10
+ end
11
+
12
+ def expect_not_environment_metadata(key)
13
+ expect(Appsignal::Extension).to_not have_received(:set_environment_metadata)
14
+ .with(key, anything)
15
+ end
16
+ 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: 2.10.6
4
+ version: 2.11.0.alpha.1
5
5
  platform: ruby
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: 2020-04-29 00:00:00.000000000 Z
13
+ date: 2020-06-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -190,6 +190,7 @@ files:
190
190
  - lib/appsignal/cli/notify_of_deploy.rb
191
191
  - lib/appsignal/config.rb
192
192
  - lib/appsignal/demo.rb
193
+ - lib/appsignal/environment.rb
193
194
  - lib/appsignal/event_formatter.rb
194
195
  - lib/appsignal/event_formatter/action_view/render_formatter.rb
195
196
  - lib/appsignal/event_formatter/active_record/instantiation_formatter.rb
@@ -227,7 +228,6 @@ files:
227
228
  - lib/appsignal/integrations/delayed_job_plugin.rb
228
229
  - lib/appsignal/integrations/grape.rb
229
230
  - lib/appsignal/integrations/mongo_ruby_driver.rb
230
- - lib/appsignal/integrations/net_http.rb
231
231
  - lib/appsignal/integrations/object.rb
232
232
  - lib/appsignal/integrations/padrino.rb
233
233
  - lib/appsignal/integrations/que.rb
@@ -275,6 +275,7 @@ files:
275
275
  - spec/lib/appsignal/cli_spec.rb
276
276
  - spec/lib/appsignal/config_spec.rb
277
277
  - spec/lib/appsignal/demo_spec.rb
278
+ - spec/lib/appsignal/environment_spec.rb
278
279
  - spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb
279
280
  - spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb
280
281
  - spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb
@@ -349,6 +350,7 @@ files:
349
350
  - spec/support/helpers/dependency_helper.rb
350
351
  - spec/support/helpers/directory_helper.rb
351
352
  - spec/support/helpers/env_helpers.rb
353
+ - spec/support/helpers/environment_metdata_helper.rb
352
354
  - spec/support/helpers/example_exception.rb
353
355
  - spec/support/helpers/example_standard_error.rb
354
356
  - spec/support/helpers/log_helpers.rb
@@ -380,7 +382,7 @@ metadata:
380
382
  documentation_uri: https://docs.appsignal.com/ruby/
381
383
  homepage_uri: https://docs.appsignal.com/ruby/
382
384
  source_code_uri: https://github.com/appsignal/appsignal-ruby
383
- post_install_message:
385
+ post_install_message:
384
386
  rdoc_options: []
385
387
  require_paths:
386
388
  - lib
@@ -392,12 +394,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
392
394
  version: '1.9'
393
395
  required_rubygems_version: !ruby/object:Gem::Requirement
394
396
  requirements:
395
- - - ">="
397
+ - - ">"
396
398
  - !ruby/object:Gem::Version
397
- version: '0'
399
+ version: 1.3.1
398
400
  requirements: []
399
- rubygems_version: 3.1.2
400
- signing_key:
401
+ rubygems_version: 3.1.4
402
+ signing_key:
401
403
  specification_version: 4
402
404
  summary: Logs performance and exception data from your app to appsignal.com
403
405
  test_files:
@@ -415,6 +417,7 @@ test_files:
415
417
  - spec/lib/appsignal/cli_spec.rb
416
418
  - spec/lib/appsignal/config_spec.rb
417
419
  - spec/lib/appsignal/demo_spec.rb
420
+ - spec/lib/appsignal/environment_spec.rb
418
421
  - spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb
419
422
  - spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb
420
423
  - spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb
@@ -489,6 +492,7 @@ test_files:
489
492
  - spec/support/helpers/dependency_helper.rb
490
493
  - spec/support/helpers/directory_helper.rb
491
494
  - spec/support/helpers/env_helpers.rb
495
+ - spec/support/helpers/environment_metdata_helper.rb
492
496
  - spec/support/helpers/example_exception.rb
493
497
  - spec/support/helpers/example_standard_error.rb
494
498
  - spec/support/helpers/log_helpers.rb
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Appsignal
4
- module Integrations
5
- module NetHttpIntegration
6
- def request(request, body = nil, &block)
7
- Appsignal.instrument(
8
- "request.net_http",
9
- "#{request.method} #{use_ssl? ? "https" : "http"}://#{request["host"] || address}"
10
- ) do
11
- super
12
- end
13
- end
14
- end
15
- end
16
- end