appsignal 2.5.3.alpha.1 → 2.5.3.alpha.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18e46cb221b16ec43eb3b45158ae8849dfbe0728
4
- data.tar.gz: 63537221d5bbcec71aa6c9f096b732b8586d7033
3
+ metadata.gz: 8f00d44575997733185b772ca7194b3faf1b632b
4
+ data.tar.gz: f9047550c4e3a53d176136daf55c9648705dced0
5
5
  SHA512:
6
- metadata.gz: 9f5fa1663e8fbf61b7e4f91501ff54dff521d567d0264a23c53d535580f25c423a7552829dcfa51a823bce599b143661f5f9a52ade22a12419c2a628f3e7d8dc
7
- data.tar.gz: cfd6a663991702d6cade925af2f0b1d0ee7778bdd9e96511c68493ea44ba143a5e9f8e07fdac1186c748240f5877eb2fda37a60919429885ad25774525570ff0
6
+ metadata.gz: 7e9ac0366e2f2f7a1aec95ac17cf02c56a825abda1a28ad4783832b848ad13616caac9d6bb79561a3f0dbd9572824866b8f76107f26cec2aa3443f63fb2716c0
7
+ data.tar.gz: f21c211c3bd6ced23fe5941c66668b8103bb223d6e63b39825792c17605818389d6baef1353659e705cc332c004e0a3c736c0fe8b4d6de371ad8e198edc0c278
@@ -86,37 +86,95 @@ module Appsignal
86
86
 
87
87
  # Based on: https://github.com/mperham/sidekiq/blob/63ee43353bd3b753beb0233f64865e658abeb1c3/lib/sidekiq/api.rb#L316-L334
88
88
  def parse_action_name(job)
89
- args = job["args"]
90
- case job["class"]
89
+ args = job.fetch("args", [])
90
+ job_class = job["class"]
91
+ case job_class
91
92
  when "Sidekiq::Extensions::DelayedModel"
92
- safe_load(job["args"][0], job["class"]) do |target, method, _|
93
+ safe_load(args[0], job_class) do |target, method, _|
93
94
  "#{target.class}##{method}"
94
95
  end
95
96
  when /\ASidekiq::Extensions::Delayed/
96
- safe_load(job["args"][0], job["class"]) do |target, method, _|
97
+ safe_load(args[0], job_class) do |target, method, _|
97
98
  "#{target}.#{method}"
98
99
  end
99
100
  when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
100
- job_class = job["wrapped"] || args[0]
101
- case job_class
102
- when "ActionMailer::DeliveryJob"
103
- # MailerClass#mailer_method
104
- args[0]["arguments"][0..1].join("#")
105
- when String
106
- job_class
101
+ wrapped_job = job["wrapped"]
102
+ if wrapped_job
103
+ parse_active_job_action_name_from_wrapped job
107
104
  else
108
- Appsignal.logger.debug \
109
- "Unable to determine an action name from Sidekiq payload: #{job}"
110
- UNKNOWN_ACTION_NAME
105
+ parse_active_job_action_name_from_arguments job
111
106
  end
112
107
  else
113
- job["class"]
108
+ job_class
109
+ end
110
+ end
111
+
112
+ # Return the ActiveJob wrapped job name.
113
+ #
114
+ # Returns "unknown" if no acceptable job class name could be found.
115
+ #
116
+ # @example Payload with "wrapped" value
117
+ # {
118
+ # "class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
119
+ # "wrapped" => "MyWrappedJob",
120
+ # # ...
121
+ # }
122
+ def parse_active_job_action_name_from_wrapped(job)
123
+ job_class = job["wrapped"]
124
+ case job_class
125
+ when "ActionMailer::DeliveryJob"
126
+ extract_action_mailer_name job["args"]
127
+ when String
128
+ job_class
129
+ else
130
+ unknown_action_name_for job
114
131
  end
115
132
  end
116
133
 
134
+ # Return the ActiveJob job name based on the job's arguments.
135
+ #
136
+ # Returns "unknown" if no acceptable job class name could be found.
137
+ #
138
+ # @example Payload without "wrapped" value
139
+ # {
140
+ # "class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
141
+ # "args" => [{
142
+ # "job_class" => "MyWrappedJob",
143
+ # # ...
144
+ # }]
145
+ # # ...
146
+ # }
147
+ def parse_active_job_action_name_from_arguments(job)
148
+ args = job.fetch("args", [])
149
+ first_arg = args[0]
150
+ if first_arg == "ActionMailer::DeliveryJob"
151
+ extract_action_mailer_name args
152
+ elsif active_job_payload?(first_arg)
153
+ first_arg["job_class"]
154
+ else
155
+ unknown_action_name_for job
156
+ end
157
+ end
158
+
159
+ # Checks if the first argument in the job payload is an ActiveJob payload.
160
+ def active_job_payload?(arg)
161
+ arg.is_a?(Hash) && arg["job_class"].is_a?(String)
162
+ end
163
+
164
+ def unknown_action_name_for(job)
165
+ Appsignal.logger.debug \
166
+ "Unable to determine an action name from Sidekiq payload: #{job}"
167
+ UNKNOWN_ACTION_NAME
168
+ end
169
+
170
+ def extract_action_mailer_name(args)
171
+ # Returns in format: MailerClass#mailer_method
172
+ args[0]["arguments"][0..1].join("#")
173
+ end
174
+
117
175
  # Based on: https://github.com/mperham/sidekiq/blob/63ee43353bd3b753beb0233f64865e658abeb1c3/lib/sidekiq/api.rb#L336-L358
118
176
  def parse_arguments(job)
119
- args = job["args"]
177
+ args = job.fetch("args", [])
120
178
  case job["class"]
121
179
  when /\ASidekiq::Extensions::Delayed/
122
180
  safe_load(args[0], args) do |_, _, arg|
@@ -124,8 +182,14 @@ module Appsignal
124
182
  end
125
183
  when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
126
184
  is_wrapped = job["wrapped"]
127
- job_args = is_wrapped ? args[0]["arguments"] : []
128
- if (is_wrapped || args[0]) == "ActionMailer::DeliveryJob"
185
+ first_arg = args[0]
186
+ job_args =
187
+ if is_wrapped || active_job_payload?(first_arg)
188
+ first_arg["arguments"]
189
+ else
190
+ []
191
+ end
192
+ if (is_wrapped || first_arg) == "ActionMailer::DeliveryJob"
129
193
  # Remove MailerClass, mailer_method and "deliver_now"
130
194
  job_args.drop(3)
131
195
  else
@@ -1,3 +1,3 @@
1
1
  module Appsignal
2
- VERSION = "2.5.3.alpha.1".freeze
2
+ VERSION = "2.5.3.alpha.2".freeze
3
3
  end
@@ -323,59 +323,110 @@ describe Appsignal::Hooks::SidekiqPlugin, :with_yaml_parse_error => false do
323
323
  {
324
324
  "class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
325
325
  "queue" => "default",
326
- "args" => [{
327
- "job_class" => "ActiveMailerTestJob",
328
- "job_id" => "23e79d48-6966-40d0-b2d4-f7938463a263",
329
- "queue_name" => "default",
330
- "arguments" => [
331
- "MailerClass", "mailer_method", "deliver_now",
332
- "foo", { "foo" => "Foo", "bar" => "Bar", "baz" => { 1 => :bar } }
333
- ]
334
- }],
326
+ "args" => [first_argument],
335
327
  "retry" => true,
336
328
  "jid" => "efb140489485999d32b5504c",
337
329
  "created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
338
330
  "enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f
339
331
  }
340
332
  end
333
+ before { perform_job }
341
334
 
342
- it "sets the action name to unknown and without sample data" do
343
- perform_job
335
+ context "when the first argument is not a Hash object" do
336
+ let(:first_argument) { "foo" }
344
337
 
345
- transaction_hash = transaction.to_h
346
- expect(transaction_hash).to include(
347
- "id" => kind_of(String),
348
- "action" => "unknown",
349
- "error" => nil,
350
- "namespace" => namespace,
351
- "metadata" => {
352
- "queue" => "default"
353
- },
354
- "sample_data" => {
355
- "environment" => {},
356
- "params" => [],
357
- "tags" => {}
358
- }
359
- )
360
- # TODO: Not available in transaction.to_h yet.
361
- # https://github.com/appsignal/appsignal-agent/issues/293
362
- expect(transaction.request.env).to eq(
363
- :queue_start => Time.parse("2001-01-01 10:00:00UTC").to_f
364
- )
365
- expect_transaction_to_have_sidekiq_event(transaction_hash)
338
+ include_examples "unknown job action name"
366
339
  end
367
340
 
368
- it "logs a debug message" do
369
- perform_job
341
+ context "when the first argument is a Hash object not containing a job payload" do
342
+ let(:first_argument) { { "foo" => "bar" } }
370
343
 
371
- expect(log_contents(log)).to contains_log(
372
- :debug, "Unable to determine an action name from Sidekiq payload: #{item}"
373
- )
344
+ include_examples "unknown job action name"
345
+
346
+ context "when the argument contains an invalid job_class value" do
347
+ let(:first_argument) { { "job_class" => :foo } }
348
+
349
+ include_examples "unknown job action name"
350
+ end
351
+ end
352
+
353
+ context "when the first argument is a Hash object containing a job payload" do
354
+ let(:first_argument) do
355
+ {
356
+ "job_class" => "ActiveMailerTestJob",
357
+ "job_id" => "23e79d48-6966-40d0-b2d4-f7938463a263",
358
+ "queue_name" => "default",
359
+ "arguments" => [
360
+ "foo", { "foo" => "Foo", "bar" => "Bar", "baz" => { 1 => :bar } }
361
+ ]
362
+ }
363
+ end
364
+
365
+ it "sets the action name to the job class in the first argument" do
366
+ transaction_hash = transaction.to_h
367
+ expect(transaction_hash).to include(
368
+ "action" => "ActiveMailerTestJob#perform"
369
+ )
370
+ end
371
+
372
+ it "stores the job metadata on the transaction" do
373
+ transaction_hash = transaction.to_h
374
+ expect(transaction_hash).to include(
375
+ "id" => kind_of(String),
376
+ "error" => nil,
377
+ "namespace" => namespace,
378
+ "metadata" => {
379
+ "queue" => "default"
380
+ },
381
+ "sample_data" => {
382
+ "environment" => {},
383
+ "params" => [
384
+ "foo",
385
+ {
386
+ "foo" => "Foo",
387
+ "bar" => "Bar",
388
+ "baz" => { "1" => "bar" }
389
+ }
390
+ ],
391
+ "tags" => {}
392
+ }
393
+ )
394
+ end
395
+
396
+ it "does not log a debug message" do
397
+ expect(log_contents(log)).to_not contains_log(
398
+ :debug, "Unable to determine an action name from Sidekiq payload"
399
+ )
400
+ end
374
401
  end
375
402
  end
376
403
  end
377
404
  end
378
405
 
406
+ shared_examples "unknown job action name" do
407
+ it "sets the action name to unknown" do
408
+ transaction_hash = transaction.to_h
409
+ expect(transaction_hash).to include("action" => "unknown")
410
+ end
411
+
412
+ it "stores no sample data" do
413
+ transaction_hash = transaction.to_h
414
+ expect(transaction_hash).to include(
415
+ "sample_data" => {
416
+ "environment" => {},
417
+ "params" => [],
418
+ "tags" => {}
419
+ }
420
+ )
421
+ end
422
+
423
+ it "logs a debug message" do
424
+ expect(log_contents(log)).to contains_log(
425
+ :debug, "Unable to determine an action name from Sidekiq payload: #{item}"
426
+ )
427
+ end
428
+ end
429
+
379
430
  context "with an error" do
380
431
  let(:error) { ExampleException }
381
432
 
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: 2.5.3.alpha.1
4
+ version: 2.5.3.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-23 00:00:00.000000000 Z
12
+ date: 2018-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack