appsignal 2.5.3.alpha.1-java → 2.5.3.alpha.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea3a27e8ba696561f20b761ac6f98e28aaebf384
4
- data.tar.gz: a2676271086288a7e4c6de3e3be6b4b45acc8a7d
3
+ metadata.gz: b24977f12b9c51a05d8c065ba0a14c3df06a138e
4
+ data.tar.gz: 0ca74fa7afb8fcc13be6a412b6bfe8acfefc6b12
5
5
  SHA512:
6
- metadata.gz: 811444b7be89ff7e4da044fac781acb0666122e594a08543dafa76966804152910f196396c8e7681845b1f9d4e045702fbc1f68be7f00bddf2a356556b435e75
7
- data.tar.gz: f6b75547626577f17e143b1fb801182a5d77be7494ba3d6e43d0d7c8a8b59d9a51501d3bfabc5725f577fe814bdc1bb7e92811cb7938350ac54d6da1bb94610a
6
+ metadata.gz: 9f4db48641f56f8443d52911952e1c4dcb946093fc5bf8f412bf713f1a9fb9fc7e77b13c2b3e82e3fd086a68d5226dde34a0ab181ea5df512a90f025cda71ce5
7
+ data.tar.gz: 1212bc837886852b3b522d16007363ed144c7e7810378e718b2bfb093d1337a4ef7793c77cb76d7641b98e23c5b1bb4cf8bb190ed8ddcdbc2ff25dbbb39db5ff
@@ -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: java
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