Skip to content

Commit

Permalink
Add sidekiq tags to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
berniechiu committed Oct 24, 2021
1 parent a87b99d commit 7e6a287
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def call(_worker, job, queue)
scope.set_user(user)
end
scope.set_tags(queue: queue, jid: job["jid"])
scope.set_tags(build_tags(job["tags"]))
scope.set_contexts(sidekiq: job.merge("queue" => queue))
scope.set_transaction_name(context_filter.transaction_name)
transaction = start_transaction(scope.transaction_name, job["sentry_trace"])
Expand All @@ -32,6 +33,10 @@ def call(_worker, job, queue)
scope.clear
end

def build_tags(tags)
Array(tags).each_with_object({}) { |name, tags_hash| tags_hash[:"sidekiq.#{name}"] = true }
end

def start_transaction(transaction_name, sentry_trace)
options = { name: transaction_name, op: "sidekiq" }
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
expect(event.user).to eq(user)
end

it "sets sidekiq tags to the event" do
execute_worker(processor, HappyWorker, tags: ["marvel", "dc"])
event = transport.events.last
expect(event.tags.keys).to include(:"sidekiq.marvel", :"sidekiq.dc")
end

context "with sentry_trace" do
let(:parent_transaction) { Sentry.start_transaction(op: "sidekiq") }

Expand Down

0 comments on commit 7e6a287

Please sign in to comment.