Skip to content

Commit b1cf340

Browse files
committed
Skip the Que enqueue event when suppressed
When enqueuing through Active Job, the enqueue is already recorded as an `enqueue.active_job` event. The Que enqueue wrappers now skip recording their own `enqueue.que` (or `bulk_enqueue.que`) event while enqueue events are suppressed, so the enqueue is recorded once. Depends on the suppression flag added in the Active Job pull request.
1 parent 4cfba4f commit b1cf340

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/appsignal/integrations/que.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def enqueue(*_args, **_rest)
4949
# avoid recording an event per job.
5050
return super if bulk_insert_in_progress?
5151

52+
# Under Active Job the enqueue is already recorded as an
53+
# `enqueue.active_job` event, so skip recording it again here.
54+
return super if Appsignal::Transaction.current? &&
55+
Appsignal::Transaction.current.job_enqueue_events_suppressed?
56+
5257
Appsignal.instrument("enqueue.que") { super }
5358
end
5459

@@ -67,6 +72,11 @@ def bulk_insert_in_progress?
6772
# single `bulk_enqueue.que` event; the inner enqueues are pass-throughs.
6873
module QueBulkClientPlugin
6974
def bulk_enqueue(*_args, **_rest)
75+
# Under Active Job the enqueue is already recorded as an
76+
# `enqueue.active_job` event, so skip recording it again here.
77+
return super if Appsignal::Transaction.current? &&
78+
Appsignal::Transaction.current.job_enqueue_events_suppressed?
79+
7080
Appsignal.instrument("bulk_enqueue.que") { super }
7181
end
7282
end

spec/lib/appsignal/integrations/que_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ def enqueue(tags: ["user:42"])
239239
end
240240
end
241241

242+
context "when job enqueue events are suppressed" do
243+
# As happens under Active Job, which records the enqueue itself.
244+
it "passes through without recording the enqueue" do
245+
transaction = http_request_transaction
246+
set_current_transaction(transaction)
247+
248+
transaction.suppress_job_enqueue_events { enqueue }
249+
250+
# The outer integration records the enqueue, so this one doesn't.
251+
event_names = transaction.to_h["events"].map { |event| event["name"] }
252+
expect(event_names).to_not include("enqueue.que")
253+
end
254+
end
255+
242256
# `bulk_enqueue` is Que 2 only. The whole batch records a single
243257
# `bulk_enqueue.que` event; the inner enqueues are pass-throughs.
244258
describe "#bulk_enqueue", :if => DependencyHelper.que2_present? do
@@ -272,6 +286,20 @@ def bulk_enqueue(tags: ["user:42"])
272286
expect(event_names).to_not include("enqueue.que")
273287
expect(enqueued_tags).to eq(["user:42"])
274288
end
289+
290+
context "when job enqueue events are suppressed" do
291+
# As happens under Active Job, which records the enqueue itself.
292+
it "passes through without recording the enqueue" do
293+
transaction = http_request_transaction
294+
set_current_transaction(transaction)
295+
296+
transaction.suppress_job_enqueue_events { bulk_enqueue }
297+
298+
# The outer integration records the enqueue, so this one doesn't.
299+
event_names = transaction.to_h["events"].map { |event| event["name"] }
300+
expect(event_names).to_not include("bulk_enqueue.que")
301+
end
302+
end
275303
end
276304
end
277305
end

0 commit comments

Comments
 (0)