Skip to content

Commit

Permalink
rails tracing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Sep 13, 2022
1 parent 39627ff commit 38c1603
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 28 additions & 0 deletions sentry-rails/spec/sentry/rails/tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,34 @@
expect(transaction.contexts.dig(:trace, :span_id)).not_to eq(external_transaction.span_id)
end
end

context "with baggage header" do
let(:baggage_string) do
"other-vendor-value-1=foo;bar;baz, "\
"sentry-trace_id=771a43a4192642f0b136d5159a501700, "\
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, "\
"sentry-sample_rate=0.01337, "\
"sentry-user_id=Am%C3%A9lie, "\
"other-vendor-value-2=foo;bar;"
end

it "has the dynamic_sampling_context on the TransactionEvent" do
expect(Sentry::Transaction).to receive(:new).
with(hash_including(baggage: baggage_string)).
and_call_original

p = Post.create!
get "/posts/#{p.id}", headers: { "baggage" => baggage_string }

transaction_event = transport.events.last
expect(transaction_event.dynamic_sampling_context).to eq({
"sample_rate" => "0.01337",
"public_key" => "49d0f7386ad645858ae85020e393bef3",
"trace_id" => "771a43a4192642f0b136d5159a501700",
"user_id" => "Amélie"
})
end
end
end

context "without traces_sample_rate set" do
Expand Down
6 changes: 1 addition & 5 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,24 +409,20 @@ def will_be_sampled_by_sdk

let(:transaction_event) { last_sentry_event }

it "passes in baggage header to transaction" do
it "has the dynamic_sampling_context on the TransactionEvent" do
expect(Sentry::Transaction).to receive(:new).
with(hash_including(baggage: baggage_string)).
and_call_original

stack.call(env)
end

it "has the dynamic_sampling_context on the TransactionEvent" do
stack.call(env)
expect(transaction_event.dynamic_sampling_context).to eq({
"sample_rate" => "0.01337",
"public_key" => "49d0f7386ad645858ae85020e393bef3",
"trace_id" => "771a43a4192642f0b136d5159a501700",
"user_id" => "Amélie"
})
end

end

context "when the transaction is sampled" do
Expand Down

0 comments on commit 38c1603

Please sign in to comment.