|
21 | 21 | let(:string_io) { StringIO.new } |
22 | 22 | let(:sdk_logger) { Logger.new(string_io) } |
23 | 23 |
|
24 | | - describe ".from_sentry_trace" do |
25 | | - let(:sentry_trace) { subject.to_sentry_trace } |
26 | | - |
27 | | - let(:baggage) { |
28 | | - "other-vendor-value-1=foo;bar;baz, "\ |
29 | | - "sentry-trace_id=771a43a4192642f0b136d5159a501700, "\ |
30 | | - "sentry-public_key=49d0f7386ad645858ae85020e393bef3, "\ |
31 | | - "sentry-sample_rate=0.01337, "\ |
32 | | - "sentry-user_id=Am%C3%A9lie, "\ |
33 | | - "other-vendor-value-2=foo;bar;" |
34 | | - } |
35 | | - |
36 | | - let(:configuration) do |
37 | | - Sentry.configuration |
38 | | - end |
39 | | - |
40 | | - context "when tracing is enabled (> 0)" do |
41 | | - before do |
42 | | - configuration.traces_sample_rate = 1.0 |
43 | | - end |
44 | | - |
45 | | - it "returns correctly-formatted value" do |
46 | | - child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child") |
47 | | - |
48 | | - expect(child_transaction.trace_id).to eq(subject.trace_id) |
49 | | - expect(child_transaction.parent_span_id).to eq(subject.span_id) |
50 | | - expect(child_transaction.parent_sampled).to eq(true) |
51 | | - # doesn't set the sampled value |
52 | | - expect(child_transaction.sampled).to eq(nil) |
53 | | - expect(child_transaction.op).to eq("child") |
54 | | - end |
55 | | - |
56 | | - it "handles invalid values without crashing" do |
57 | | - child_transaction = described_class.from_sentry_trace("dummy", op: "child") |
58 | | - |
59 | | - expect(child_transaction).to be_nil |
60 | | - end |
61 | | - |
62 | | - it "stores frozen empty baggage on incoming traces from older SDKs" do |
63 | | - child_transaction = described_class.from_sentry_trace(sentry_trace, baggage: nil, op: "child") |
64 | | - expect(child_transaction.baggage).not_to be_nil |
65 | | - expect(child_transaction.baggage.mutable).to be(false) |
66 | | - expect(child_transaction.baggage.items).to eq({}) |
67 | | - end |
68 | | - |
69 | | - it "stores correct baggage on incoming baggage header" do |
70 | | - child_transaction = described_class.from_sentry_trace(sentry_trace, baggage: baggage, op: "child") |
71 | | - expect(child_transaction.baggage).not_to be_nil |
72 | | - expect(child_transaction.baggage.mutable).to be(false) |
73 | | - |
74 | | - expect(child_transaction.baggage.items).to eq({ |
75 | | - "sample_rate" => "0.01337", |
76 | | - "public_key" => "49d0f7386ad645858ae85020e393bef3", |
77 | | - "trace_id" => "771a43a4192642f0b136d5159a501700", |
78 | | - "user_id" => "Amélie" |
79 | | - }) |
80 | | - end |
81 | | - end |
82 | | - |
83 | | - context "when tracing is enabled (= 0)" do |
84 | | - before do |
85 | | - configuration.traces_sample_rate = 0.0 |
86 | | - end |
87 | | - |
88 | | - it "returns correctly-formatted value" do |
89 | | - child_transaction = described_class.from_sentry_trace(sentry_trace, op: "child") |
90 | | - |
91 | | - expect(child_transaction.trace_id).to eq(subject.trace_id) |
92 | | - expect(child_transaction.parent_span_id).to eq(subject.span_id) |
93 | | - expect(child_transaction.parent_sampled).to eq(true) |
94 | | - # doesn't set the sampled value |
95 | | - expect(child_transaction.sampled).to eq(nil) |
96 | | - expect(child_transaction.op).to eq("child") |
97 | | - end |
98 | | - end |
99 | | - |
100 | | - context "when tracing is disabled" do |
101 | | - before do |
102 | | - configuration.traces_sample_rate = nil |
103 | | - end |
104 | | - |
105 | | - it "returns nil" do |
106 | | - expect(described_class.from_sentry_trace(sentry_trace, op: "child")).to be_nil |
107 | | - end |
108 | | - end |
109 | | - end |
110 | | - |
111 | 24 | describe "#deep_dup" do |
112 | 25 | before do |
113 | 26 | subject.start_child(op: "first child") |
|
467 | 380 | end |
468 | 381 |
|
469 | 382 | describe "hub selection" do |
470 | | - it "prioritizes the optional hub argument and uses it to submit the transaction" do |
471 | | - expect(another_hub).to receive(:capture_event) |
472 | | - |
473 | | - subject.finish(hub: another_hub) |
474 | | - end |
475 | | - |
476 | 383 | it "submits the event with the transaction's hub by default" do |
477 | 384 | # Create transaction with the specific hub from the beginning |
478 | 385 | transaction = described_class.new( |
|
703 | 610 | end |
704 | 611 | end |
705 | 612 |
|
706 | | - describe ".extract_sample_rand_from_baggage" do |
707 | | - let(:trace_id) { "771a43a4192642f0b136d5159a501700" } |
708 | | - |
709 | | - it "returns trace_id generation when baggage is nil" do |
710 | | - result = described_class.extract_sample_rand_from_baggage(nil, trace_id, true) |
711 | | - |
712 | | - generator = Sentry::Utils::SampleRand.new(trace_id: trace_id) |
713 | | - expected = generator.generate_from_trace_id |
714 | | - |
715 | | - expect(result).to eq(expected) |
716 | | - end |
717 | | - |
718 | | - it "returns trace_id generation when baggage has no items" do |
719 | | - baggage = double("baggage", items: nil) |
720 | | - result = described_class.extract_sample_rand_from_baggage(baggage, trace_id, true) |
721 | | - |
722 | | - generator = Sentry::Utils::SampleRand.new(trace_id: trace_id) |
723 | | - expected = generator.generate_from_trace_id |
724 | | - |
725 | | - expect(result).to eq(expected) |
726 | | - end |
727 | | - |
728 | | - it "returns trace_id generation when sample_rand is invalid" do |
729 | | - baggage = double("baggage", items: { "sample_rand" => "1.5" }) |
730 | | - result = described_class.extract_sample_rand_from_baggage(baggage, trace_id, true) |
731 | | - |
732 | | - generator = Sentry::Utils::SampleRand.new(trace_id: trace_id) |
733 | | - expected = generator.generate_from_trace_id |
734 | | - |
735 | | - expect(result).to eq(expected) |
736 | | - end |
737 | | - |
738 | | - it "returns valid sample_rand from baggage when present" do |
739 | | - baggage = double("baggage", items: { "sample_rand" => "0.5" }) |
740 | | - result = described_class.extract_sample_rand_from_baggage(baggage, trace_id, true) |
741 | | - |
742 | | - expect(result).to eq(0.5) |
743 | | - end |
744 | | - end |
745 | | - |
746 | 613 | describe "#set_name" do |
747 | 614 | it "sets name and source directly" do |
748 | 615 | subject.set_name("bar", source: :url) |
|
0 commit comments