Skip to content

Commit

Permalink
Add basic specs
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikspang committed Oct 17, 2024
1 parent 4e505f6 commit 04750fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@
expect(transaction.contexts.dig(:trace, :origin)).to eq('auto.queue.sidekiq')
end

it "adds a queue.process spans" do
execute_worker(processor, HappyWorker)
execute_worker(processor, HappyWorker, jid: '123456')

expect(transport.events.count).to eq(2)

transaction = transport.events[0]
expect(transaction).not_to be_nil
expect(transaction.spans.count).to eq(1)
expect(transaction.spans[0][:data]['messaging.message.id']).to eq('123123') # Default defined in #execute_worker
expect(transaction.spans[0][:data]['messaging.destination.name']).to eq('default')
expect(transaction.spans[0][:data]['messaging.message.retry.count']).to eq(0)

transaction = transport.events[1]
expect(transaction).not_to be_nil
expect(transaction.spans.count).to eq(1)
expect(transaction.spans[0][:data]['messaging.message.id']).to eq('123456') # Explicitly set above.
expect(transaction.spans[0][:data]['messaging.destination.name']).to eq('default')
expect(transaction.spans[0][:data]['messaging.message.retry.count']).to eq(0)
end

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

Expand Down Expand Up @@ -155,5 +176,18 @@
expect(second_headers["sentry-trace"]).to eq(transaction.to_sentry_trace)
expect(second_headers["baggage"]).to eq(transaction.to_baggage)
end

it "has a queue.publish span" do
message_id = client.push('queue' => 'default', 'class' => HappyWorker, 'args' => [])

transaction.finish

expect(transport.events.count).to eq(1)
event = transport.events.last
expect(event.spans.count).to eq(1)
expect(event.spans[0][:op]).to eq("queue.publish")
expect(event.spans[0][:data]['messaging.message.id']).to eq(message_id)
expect(event.spans[0][:data]['messaging.destination.name']).to eq('default')
end
end
end
4 changes: 3 additions & 1 deletion sentry-sidekiq/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ def execute_worker(processor, klass, **options)
options[k.to_sym] = v
end

msg = Sidekiq.dump_json(created_at: Time.now.to_f, jid: "123123", class: klass, args: [], **options)
jid = options.delete(:jid) || "123123"

msg = Sidekiq.dump_json(created_at: Time.now.to_f, enqueued_at: Time.now.to_f, jid: jid, class: klass, args: [], **options)
work = Sidekiq::BasicFetch::UnitOfWork.new('queue:default', msg)
process_work(processor, work)
end
Expand Down

0 comments on commit 04750fa

Please sign in to comment.