|
12 | 12 | status: "ok", |
13 | 13 | sampled: true, |
14 | 14 | parent_sampled: true, |
15 | | - name: "foo" |
| 15 | + name: "foo", |
| 16 | + hub: Sentry.get_current_hub |
16 | 17 | ) |
17 | 18 | end |
18 | 19 |
|
19 | | - describe "#initialize" do |
20 | | - it "raises exception if there's no given hub and the SDK is not initialized" do |
21 | | - allow(Sentry).to receive(:get_current_hub) |
22 | | - |
23 | | - expect do |
24 | | - described_class.new |
25 | | - end.to raise_error(Sentry::Error) |
26 | | - end |
27 | | - end |
28 | | - |
29 | 20 | describe ".from_sentry_trace" do |
30 | 21 | let(:sentry_trace) { subject.to_sentry_trace } |
31 | 22 |
|
|
152 | 143 | it "sets @sampled to false and return" do |
153 | 144 | allow(Sentry.configuration).to receive(:tracing_enabled?).and_return(false) |
154 | 145 |
|
155 | | - transaction = described_class.new(sampled: true) |
| 146 | + transaction = described_class.new(sampled: true, hub: Sentry.get_current_hub) |
156 | 147 | transaction.set_initial_sample_decision(sampling_context: {}) |
157 | 148 | expect(transaction.sampled).to eq(false) |
158 | 149 | end |
159 | 150 | end |
160 | 151 |
|
161 | 152 | context "when tracing is enabled" do |
162 | | - let(:subject) { described_class.new(op: "rack.request") } |
| 153 | + let(:subject) { described_class.new(op: "rack.request", hub: Sentry.get_current_hub) } |
163 | 154 |
|
164 | 155 | before do |
165 | 156 | allow(Sentry.configuration).to receive(:tracing_enabled?).and_return(true) |
166 | 157 | end |
167 | 158 |
|
168 | 159 | context "when the transaction already has a decision" do |
169 | 160 | it "doesn't change it" do |
170 | | - transaction = described_class.new(sampled: true) |
| 161 | + transaction = described_class.new(sampled: true, hub: Sentry.get_current_hub) |
171 | 162 | transaction.set_initial_sample_decision(sampling_context: {}) |
172 | 163 | expect(transaction.sampled).to eq(true) |
173 | 164 |
|
174 | | - transaction = described_class.new(sampled: false) |
| 165 | + transaction = described_class.new(sampled: false, hub: Sentry.get_current_hub) |
175 | 166 | transaction.set_initial_sample_decision(sampling_context: {}) |
176 | 167 | expect(transaction.sampled).to eq(false) |
177 | 168 | end |
|
255 | 246 | it "uses the genereted rate for sampling (positive)" do |
256 | 247 | expect(Sentry.configuration.logger).to receive(:debug).exactly(3).and_call_original |
257 | 248 |
|
258 | | - subject = described_class.new |
| 249 | + subject = described_class.new(hub: Sentry.get_current_hub) |
259 | 250 | Sentry.configuration.traces_sampler = -> (_) { true } |
260 | 251 | subject.set_initial_sample_decision(sampling_context: {}) |
261 | 252 | expect(subject.sampled).to eq(true) |
262 | 253 |
|
263 | | - subject = described_class.new |
| 254 | + subject = described_class.new(hub: Sentry.get_current_hub) |
264 | 255 | Sentry.configuration.traces_sampler = -> (_) { 1.0 } |
265 | 256 | subject.set_initial_sample_decision(sampling_context: {}) |
266 | 257 | expect(subject.sampled).to eq(true) |
267 | 258 |
|
268 | | - subject = described_class.new |
| 259 | + subject = described_class.new(hub: Sentry.get_current_hub) |
269 | 260 | Sentry.configuration.traces_sampler = -> (_) { 1 } |
270 | 261 | subject.set_initial_sample_decision(sampling_context: {}) |
271 | 262 | expect(subject.sampled).to eq(true) |
|
278 | 269 | it "uses the genereted rate for sampling (negative)" do |
279 | 270 | expect(Sentry.configuration.logger).to receive(:debug).exactly(2).and_call_original |
280 | 271 |
|
281 | | - subject = described_class.new |
| 272 | + subject = described_class.new(hub: Sentry.get_current_hub) |
282 | 273 | Sentry.configuration.traces_sampler = -> (_) { false } |
283 | 274 | subject.set_initial_sample_decision(sampling_context: {}) |
284 | 275 | expect(subject.sampled).to eq(false) |
285 | 276 |
|
286 | | - subject = described_class.new |
| 277 | + subject = described_class.new(hub: Sentry.get_current_hub) |
287 | 278 | Sentry.configuration.traces_sampler = -> (_) { 0.0 } |
288 | 279 | subject.set_initial_sample_decision(sampling_context: {}) |
289 | 280 | expect(subject.sampled).to eq(false) |
|
347 | 338 | end |
348 | 339 |
|
349 | 340 | context "if the transaction is not sampled" do |
350 | | - subject { described_class.new(sampled: false) } |
| 341 | + subject { described_class.new(sampled: false, hub: Sentry.get_current_hub) } |
351 | 342 |
|
352 | 343 | it "doesn't send it" do |
353 | 344 | subject.finish |
|
357 | 348 | end |
358 | 349 |
|
359 | 350 | context "if the transaction doesn't have a name" do |
360 | | - subject { described_class.new(sampled: true) } |
| 351 | + subject { described_class.new(sampled: true, hub: Sentry.get_current_hub) } |
361 | 352 |
|
362 | 353 | it "adds a default name" do |
363 | 354 | subject.finish |
|
0 commit comments