Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCE] Support Sidekiq Tags in Sentry #1596

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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