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 Nov 1, 2021
1 parent a87b99d commit f13f198
Show file tree
Hide file tree
Showing 3 changed files with 19 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, TagsWorker)
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
8 changes: 8 additions & 0 deletions sentry-sidekiq/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def perform
end
end

class TagsWorker
include Sidekiq::Worker

sidekiq_options tags: ["marvel", "dc"]

def perform; end
end

def execute_worker(processor, klass, **options)
klass_options = klass.sidekiq_options_hash || {}

Expand Down

0 comments on commit f13f198

Please sign in to comment.