appsignal 4.0.5-java → 4.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.
@@ -9,28 +9,16 @@ if DependencyHelper.que_present?
9
9
  :queue => "dfl",
10
10
  :job_class => "MyQueJob",
11
11
  :priority => 100,
12
- :args => %w[1 birds],
12
+ :args => %w[post_id_123 user_id_123],
13
13
  :run_at => fixed_time,
14
14
  :error_count => 0
15
- }
16
- end
17
- let(:env) do
18
- {
19
- :class => "MyQueJob",
20
- :method => "run",
21
- :metadata => {
22
- :id => 123,
23
- :queue => "dfl",
24
- :priority => 100,
25
- :run_at => fixed_time.to_s,
26
- :attempts => 0
27
- },
28
- :params => %w[1 birds]
29
- }
15
+ }.tap do |hash|
16
+ hash[:kwargs] = {} if DependencyHelper.que2_present?
17
+ end
30
18
  end
31
19
  let(:job) do
32
20
  Class.new(::Que::Job) do
33
- def run(*args)
21
+ def run(post_id, user_id)
34
22
  end
35
23
  end
36
24
  end
@@ -46,7 +34,7 @@ if DependencyHelper.que_present?
46
34
  job._run
47
35
  end
48
36
 
49
- context "success" do
37
+ context "without exception" do
50
38
  it "creates a transaction for a job" do
51
39
  expect do
52
40
  perform_que_job(instance)
@@ -64,7 +52,18 @@ if DependencyHelper.que_present?
64
52
  "name" => "perform_job.que",
65
53
  "title" => ""
66
54
  )
67
- expect(transaction).to include_params(%w[1 birds])
55
+ expect(transaction).to include_params(
56
+ "arguments" => %w[post_id_123 user_id_123]
57
+ )
58
+ if DependencyHelper.que2_present?
59
+ expect(transaction).to include_params(
60
+ "keyword_arguments" => {}
61
+ )
62
+ else
63
+ expect(transaction).to_not include_params(
64
+ "keyword_arguments" => anything
65
+ )
66
+ end
68
67
  expect(transaction).to include_tags(
69
68
  "attempts" => 0,
70
69
  "id" => 123,
@@ -93,7 +92,9 @@ if DependencyHelper.que_present?
93
92
  expect(transaction).to have_action("MyQueJob#run")
94
93
  expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
95
94
  expect(transaction).to have_error(error.class.name, error.message)
96
- expect(transaction).to include_params(%w[1 birds])
95
+ expect(transaction).to include_params(
96
+ "arguments" => %w[post_id_123 user_id_123]
97
+ )
97
98
  expect(transaction).to include_tags(
98
99
  "attempts" => 0,
99
100
  "id" => 123,
@@ -118,7 +119,9 @@ if DependencyHelper.que_present?
118
119
  expect(transaction).to have_action("MyQueJob#run")
119
120
  expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
120
121
  expect(transaction).to have_error(error.class.name, error.message)
121
- expect(transaction).to include_params(%w[1 birds])
122
+ expect(transaction).to include_params(
123
+ "arguments" => %w[post_id_123 user_id_123]
124
+ )
122
125
  expect(transaction).to include_tags(
123
126
  "attempts" => 0,
124
127
  "id" => 123,
@@ -130,6 +133,38 @@ if DependencyHelper.que_present?
130
133
  end
131
134
  end
132
135
 
136
+ if DependencyHelper.que2_present?
137
+ context "with keyword argument" do
138
+ let(:job_attrs) do
139
+ {
140
+ :job_id => 123,
141
+ :queue => "dfl",
142
+ :job_class => "MyQueJob",
143
+ :priority => 100,
144
+ :args => %w[post_id_123],
145
+ :kwargs => { :user_id => "user_id_123" },
146
+ :run_at => fixed_time,
147
+ :error_count => 0
148
+ }
149
+ end
150
+ let(:job) do
151
+ Class.new(::Que::Job) do
152
+ def run(post_id, user_id: nil)
153
+ end
154
+ end
155
+ end
156
+
157
+ it "reports keyword arguments as parameters" do
158
+ perform_que_job(instance)
159
+
160
+ expect(last_transaction).to include_params(
161
+ "arguments" => %w[post_id_123],
162
+ "keyword_arguments" => { "user_id" => "user_id_123" }
163
+ )
164
+ end
165
+ end
166
+ end
167
+
133
168
  context "when action set in job" do
134
169
  let(:job) do
135
170
  Class.new(::Que::Job) do
@@ -43,6 +43,9 @@ describe Appsignal::Probes do
43
43
  let(:log) { log_contents(log_stream) }
44
44
  before do
45
45
  Appsignal.internal_logger = test_logger(log_stream)
46
+ # TODO: These logs are here to debug an issue on CI
47
+ Appsignal.internal_logger.info("a" * 100)
48
+ Appsignal.internal_logger.info("b" * 100)
46
49
  speed_up_tests!
47
50
  end
48
51
 
@@ -211,15 +211,15 @@ describe Appsignal::Transaction do
211
211
 
212
212
  context "when a transaction has errors" do
213
213
  let(:error) do
214
- e = ExampleStandardError.new("test message")
215
- allow(e).to receive(:backtrace).and_return(["line 1"])
216
- e
214
+ ExampleStandardError.new("test message").tap do |e|
215
+ e.set_backtrace(["line 1"])
216
+ end
217
217
  end
218
218
 
219
219
  let(:other_error) do
220
- e = ExampleStandardError.new("other test message")
221
- allow(e).to receive(:backtrace).and_return(["line 2"])
222
- e
220
+ ExampleStandardError.new("other test message").tap do |e|
221
+ e.set_backtrace(["line 2"])
222
+ end
223
223
  end
224
224
 
225
225
  context "when an error is already set on the transaction" do
@@ -1526,9 +1526,9 @@ describe Appsignal::Transaction do
1526
1526
  let(:transaction) { create_transaction }
1527
1527
 
1528
1528
  let(:error) do
1529
- e = ExampleStandardError.new("test message")
1530
- allow(e).to receive(:backtrace).and_return(["line 1"])
1531
- e
1529
+ ExampleStandardError.new("test message").tap do |e|
1530
+ e.set_backtrace(["line 1"])
1531
+ end
1532
1532
  end
1533
1533
 
1534
1534
  context "when error argument is not an error" do
@@ -1588,9 +1588,9 @@ describe Appsignal::Transaction do
1588
1588
 
1589
1589
  context "when an error is already set in the transaction" do
1590
1590
  let(:other_error) do
1591
- e = ExampleStandardError.new("other test message")
1592
- allow(e).to receive(:backtrace).and_return(["line 2"])
1593
- e
1591
+ ExampleStandardError.new("other test message").tap do |e|
1592
+ e.set_backtrace(["line 2"])
1593
+ end
1594
1594
  end
1595
1595
 
1596
1596
  before { transaction.set_error(other_error) }
@@ -1697,12 +1697,92 @@ describe Appsignal::Transaction do
1697
1697
  end
1698
1698
  end
1699
1699
  end
1700
+
1701
+ context "with a PG::UniqueViolation" do
1702
+ let(:error) do
1703
+ PG::UniqueViolation.new(
1704
+ "ERROR: duplicate key value violates unique constraint " \
1705
+ "\"index_users_on_email\" DETAIL: Key (email)=(test@test.com) already exists."
1706
+ )
1707
+ end
1708
+ before do
1709
+ stub_const("PG::UniqueViolation", Class.new(StandardError))
1710
+ transaction.add_error(error)
1711
+ end
1712
+
1713
+ it "returns a sanizited error message" do
1714
+ expect(transaction).to have_error(
1715
+ "PG::UniqueViolation",
1716
+ "ERROR: duplicate key value violates unique constraint " \
1717
+ "\"index_users_on_email\" DETAIL: Key (email)=(?) already exists."
1718
+ )
1719
+ end
1720
+ end
1721
+
1722
+ context "with a ActiveRecord::RecordNotUnique" do
1723
+ let(:error) do
1724
+ ActiveRecord::RecordNotUnique.new(
1725
+ "PG::UniqueViolation: ERROR: duplicate key value violates unique constraint " \
1726
+ "\"example_constraint\"\nDETAIL: Key (email)=(foo@example.com) already exists."
1727
+ )
1728
+ end
1729
+ before do
1730
+ stub_const("ActiveRecord::RecordNotUnique", Class.new(StandardError))
1731
+ transaction.add_error(error)
1732
+ end
1733
+
1734
+ it "returns a sanizited error message" do
1735
+ expect(transaction).to have_error(
1736
+ "ActiveRecord::RecordNotUnique",
1737
+ "PG::UniqueViolation: ERROR: duplicate key value violates unique constraint " \
1738
+ "\"example_constraint\"\nDETAIL: Key (email)=(?) already exists."
1739
+ )
1740
+ end
1741
+ end
1742
+
1743
+ context "with Rails module but without backtrace_cleaner method" do
1744
+ it "returns the backtrace uncleaned" do
1745
+ stub_const("Rails", Module.new)
1746
+ error = ExampleStandardError.new("error message")
1747
+ error.set_backtrace(["line 1", "line 2"])
1748
+ transaction.add_error(error)
1749
+
1750
+ expect(last_transaction).to have_error(
1751
+ "ExampleStandardError",
1752
+ "error message",
1753
+ ["line 1", "line 2"]
1754
+ )
1755
+ end
1756
+ end
1757
+
1758
+ if rails_present?
1759
+ context "with Rails" do
1760
+ it "cleans the backtrace with the Rails backtrace cleaner" do
1761
+ ::Rails.backtrace_cleaner.add_filter do |line|
1762
+ line.tr("2", "?")
1763
+ end
1764
+
1765
+ error = ExampleStandardError.new("error message")
1766
+ error.set_backtrace(["line 1", "line 2"])
1767
+ transaction.add_error(error)
1768
+ expect(last_transaction).to have_error(
1769
+ "ExampleStandardError",
1770
+ "error message",
1771
+ ["line 1", "line ?"]
1772
+ )
1773
+ end
1774
+ end
1775
+ end
1700
1776
  end
1701
1777
 
1702
1778
  describe "#_set_error" do
1703
1779
  let(:transaction) { new_transaction }
1704
1780
  let(:env) { http_request_env_with_data }
1705
- let(:error) { ExampleStandardError.new("test message") }
1781
+ let(:error) do
1782
+ ExampleStandardError.new("test message").tap do |e|
1783
+ e.set_backtrace(["line 1"])
1784
+ end
1785
+ end
1706
1786
 
1707
1787
  it "responds to add_exception for backwards compatibility" do
1708
1788
  expect(transaction).to respond_to(:add_exception)
@@ -1716,7 +1796,6 @@ describe Appsignal::Transaction do
1716
1796
 
1717
1797
  context "for a http request" do
1718
1798
  it "sets an error on the transaction" do
1719
- allow(error).to receive(:backtrace).and_return(["line 1"])
1720
1799
  transaction.send(:_set_error, error)
1721
1800
 
1722
1801
  expect(transaction).to have_error(
@@ -1738,9 +1817,9 @@ describe Appsignal::Transaction do
1738
1817
  context "when the error has multiple causes" do
1739
1818
  let(:error) do
1740
1819
  e = ExampleStandardError.new("test message")
1820
+ e.set_backtrace(["line 1"])
1741
1821
  e2 = RuntimeError.new("cause message")
1742
1822
  e3 = StandardError.new("cause message 2")
1743
- allow(e).to receive(:backtrace).and_return(["line 1"])
1744
1823
  allow(e).to receive(:cause).and_return(e2)
1745
1824
  allow(e2).to receive(:cause).and_return(e3)
1746
1825
  e
@@ -1795,8 +1874,7 @@ describe Appsignal::Transaction do
1795
1874
  allow(next_e).to receive(:cause).and_return(e)
1796
1875
  e = next_e
1797
1876
  end
1798
-
1799
- allow(e).to receive(:backtrace).and_return(["line 1"])
1877
+ e.set_backtrace(["line 1"])
1800
1878
  e
1801
1879
  end
1802
1880
 
@@ -1831,7 +1909,7 @@ describe Appsignal::Transaction do
1831
1909
  let(:error) do
1832
1910
  e = ExampleStandardError.new
1833
1911
  allow(e).to receive(:message).and_return(nil)
1834
- allow(e).to receive(:backtrace).and_return(["line 1"])
1912
+ e.set_backtrace(["line 1"])
1835
1913
  e
1836
1914
  end
1837
1915
 
@@ -1985,80 +2063,6 @@ describe Appsignal::Transaction do
1985
2063
 
1986
2064
  # private
1987
2065
 
1988
- describe "#cleaned_backtrace" do
1989
- let(:transaction) { new_transaction }
1990
- subject { transaction.send(:cleaned_backtrace, ["line 1", "line 2"]) }
1991
-
1992
- it "returns the backtrace" do
1993
- expect(subject).to eq ["line 1", "line 2"]
1994
- end
1995
-
1996
- context "with Rails module but without backtrace_cleaner method" do
1997
- it "returns the backtrace uncleaned" do
1998
- stub_const("Rails", Module.new)
1999
- expect(subject).to eq ["line 1", "line 2"]
2000
- end
2001
- end
2002
-
2003
- if rails_present?
2004
- context "with rails" do
2005
- it "cleans the backtrace with the Rails backtrace cleaner" do
2006
- ::Rails.backtrace_cleaner.add_filter do |line|
2007
- line.tr("2", "?")
2008
- end
2009
- expect(subject).to eq ["line 1", "line ?"]
2010
- end
2011
- end
2012
- end
2013
- end
2014
-
2015
- describe "#cleaned_error_message" do
2016
- let(:transaction) { new_transaction }
2017
- let(:error) { StandardError.new("Error message") }
2018
- subject { transaction.send(:cleaned_error_message, error) }
2019
-
2020
- it "returns the error message" do
2021
- expect(subject).to eq "Error message"
2022
- end
2023
-
2024
- context "with a PG::UniqueViolation" do
2025
- before do
2026
- stub_const("PG::UniqueViolation", Class.new(StandardError))
2027
- end
2028
-
2029
- let(:error) do
2030
- PG::UniqueViolation.new(
2031
- "ERROR: duplicate key value violates unique constraint " \
2032
- "\"index_users_on_email\" DETAIL: Key (email)=(test@test.com) already exists."
2033
- )
2034
- end
2035
-
2036
- it "returns a sanizited error message" do
2037
- expect(subject).to eq "ERROR: duplicate key value violates unique constraint " \
2038
- "\"index_users_on_email\" DETAIL: Key (email)=(?) already exists."
2039
- end
2040
- end
2041
-
2042
- context "with a ActiveRecord::RecordNotUnique" do
2043
- before do
2044
- stub_const("ActiveRecord::RecordNotUnique", Class.new(StandardError))
2045
- end
2046
-
2047
- let(:error) do
2048
- ActiveRecord::RecordNotUnique.new(
2049
- "PG::UniqueViolation: ERROR: duplicate key value violates unique constraint " \
2050
- "\"example_constraint\"\nDETAIL: Key (email)=(foo@example.com) already exists."
2051
- )
2052
- end
2053
-
2054
- it "returns a sanizited error message" do
2055
- expect(subject).to eq \
2056
- "PG::UniqueViolation: ERROR: duplicate key value violates unique constraint " \
2057
- "\"example_constraint\"\nDETAIL: Key (email)=(?) already exists."
2058
- end
2059
- end
2060
- end
2061
-
2062
2066
  describe ".to_hash / .to_h" do
2063
2067
  let(:transaction) { new_transaction }
2064
2068
  subject { transaction.to_hash }
data/spec/spec_helper.rb CHANGED
@@ -85,6 +85,10 @@ RSpec.configure do |config|
85
85
  File.join(tmp_dir, "system-tmp")
86
86
  end
87
87
 
88
+ config.before :suite do
89
+ WebMock.disable_net_connect!
90
+ end
91
+
88
92
  config.before :context do
89
93
  FileUtils.rm_rf(tmp_dir)
90
94
  FileUtils.mkdir_p(spec_system_tmp_dir)
@@ -94,6 +98,8 @@ RSpec.configure do |config|
94
98
  Appsignal.clear!
95
99
  Appsignal::Testing.clear!
96
100
  Appsignal::Loaders.clear!
101
+ Appsignal::CheckIn.clear!
102
+
97
103
  clear_current_transaction!
98
104
  stop_minutely_probes
99
105
  ENV["RAILS_ENV"] ||= "test"
@@ -17,4 +17,44 @@ module ApiRequestHelper
17
17
  endpoint = config[:endpoint] || Appsignal::Config::DEFAULT_CONFIG[:endpoint]
18
18
  stub_request(:post, "#{endpoint}/1/#{path}").with(options)
19
19
  end
20
+
21
+ def stub_check_in_request(events:, response: { :status => 200 })
22
+ config = Appsignal.config
23
+ options = {
24
+ :query => {
25
+ :api_key => config[:push_api_key],
26
+ :name => config[:name],
27
+ :environment => config.respond_to?(:env) ? config.env : config[:environment],
28
+ :hostname => config[:hostname],
29
+ :gem_version => Appsignal::VERSION
30
+ },
31
+ :headers => { "Content-Type" => "application/x-ndjson; charset=UTF-8" }
32
+ }
33
+
34
+ request_stub =
35
+ stub_request(
36
+ :post,
37
+ "#{config[:logging_endpoint]}/check_ins/json"
38
+ ).with(options) do |request|
39
+ # Parse each line as JSON per the NDJSON format
40
+ payloads = request.body.split("\n").map { |line| JSON.parse(line) }
41
+ formatted_events =
42
+ events.map do |event|
43
+ {
44
+ "identifier" => nil,
45
+ "digest" => kind_of(String),
46
+ "kind" => "start",
47
+ "timestamp" => kind_of(Integer),
48
+ "check_in_type" => "cron"
49
+ }.merge(event)
50
+ end
51
+ expect(payloads).to include(*formatted_events)
52
+ end
53
+
54
+ if response.is_a?(Exception)
55
+ request_stub.to_raise(response)
56
+ else
57
+ request_stub.to_return(response)
58
+ end
59
+ end
20
60
  end
@@ -127,6 +127,11 @@ module DependencyHelper
127
127
  dependency_present? "que"
128
128
  end
129
129
 
130
+ def que2_present?
131
+ que_present? &&
132
+ Gem.loaded_specs["que"].version >= Gem::Version.new("2.0.0")
133
+ end
134
+
130
135
  def hanami_present?
131
136
  dependency_present? "hanami"
132
137
  end
@@ -47,6 +47,15 @@ module Appsignal
47
47
  end
48
48
  end
49
49
 
50
+ module CheckIn
51
+ class << self
52
+ def clear!
53
+ @transmitter = nil
54
+ @scheduler = nil
55
+ end
56
+ end
57
+ end
58
+
50
59
  # @api private
51
60
  module Testing
52
61
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.6
5
5
  platform: java
6
6
  authors:
7
7
  - Robert Beekman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-09-02 00:00:00.000000000 Z
13
+ date: 2024-09-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -184,7 +184,8 @@ files:
184
184
  - gemfiles/padrino.gemfile
185
185
  - gemfiles/psych-3.gemfile
186
186
  - gemfiles/psych-4.gemfile
187
- - gemfiles/que.gemfile
187
+ - gemfiles/que-1.gemfile
188
+ - gemfiles/que-2.gemfile
188
189
  - gemfiles/rails-6.0.gemfile
189
190
  - gemfiles/rails-6.1.gemfile
190
191
  - gemfiles/rails-7.0.gemfile
data/gemfiles/que.gemfile DELETED
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'que', "~> 1.0"
4
-
5
- gemspec :path => '../'