|
1 | 1 | require "spec_helper" |
2 | 2 |
|
3 | | - |
4 | | -RSpec.describe "Sentry::Breadcrumbs::MonotonicActiveSupportLogger", type: :request do |
5 | | - before do |
6 | | - make_basic_app do |sentry_config| |
7 | | - sentry_config.breadcrumbs_logger = [:monotonic_active_support_logger] |
8 | | - sentry_config.traces_sample_rate = 1.0 |
9 | | - end |
10 | | - end |
11 | | - |
| 3 | +RSpec.describe "Sentry::Breadcrumbs::ActiveSupportLogger", type: :request do |
12 | 4 | after do |
13 | | - require 'sentry/rails/breadcrumb/monotonic_active_support_logger' |
14 | | - Sentry::Rails::Breadcrumb::MonotonicActiveSupportLogger.detach |
| 5 | + require 'sentry/rails/breadcrumb/active_support_logger' |
| 6 | + Sentry::Rails::Breadcrumb::ActiveSupportLogger.detach |
15 | 7 | # even though we cleanup breadcrumbs in the rack middleware |
16 | | - # Breadcrumbs::MonotonicActiveSupportLogger subscribes to "every" instrumentation |
| 8 | + # Breadcrumbs::ActiveSupportLogger subscribes to "every" instrumentation |
17 | 9 | # so it'll create other instrumentations "after" the request is finished |
18 | 10 | # and we should clear those as well |
19 | 11 | Sentry.get_current_scope.clear_breadcrumbs |
| 12 | + transport.events = [] |
20 | 13 | end |
21 | 14 |
|
22 | 15 | let(:transport) do |
|
31 | 24 | transport.events.first.to_json_compatible |
32 | 25 | end |
33 | 26 |
|
34 | | - after do |
35 | | - transport.events = [] |
36 | | - end |
37 | | - |
38 | | - context "given a Rails version < 6.1", skip: Rails.version.to_f >= 6.1 do |
39 | | - it "does not run instrumentation" do |
40 | | - get "/exception" |
41 | | - |
42 | | - breadcrumbs = event.dig("breadcrumbs", "values") |
43 | | - expect(breadcrumbs.count).to be_zero |
| 27 | + context "without tracing" do |
| 28 | + before do |
| 29 | + make_basic_app do |sentry_config| |
| 30 | + sentry_config.breadcrumbs_logger = [:active_support_logger] |
| 31 | + end |
44 | 32 | end |
45 | | - end |
46 | 33 |
|
47 | | - context "given a Rails version >= 6.1", skip: Rails.version.to_f <= 6.1 do |
48 | 34 | it "captures correct data of exception requests" do |
49 | 35 | get "/exception" |
50 | 36 |
|
|
67 | 53 | expect(breadcrumb["data"].keys).not_to include("response") |
68 | 54 | end |
69 | 55 |
|
| 56 | + it "ignores exception data" do |
| 57 | + get "/view_exception" |
| 58 | + |
| 59 | + expect(event.dig("breadcrumbs", "values", -1, "data").keys).not_to include("exception") |
| 60 | + expect(event.dig("breadcrumbs", "values", -1, "data").keys).not_to include("exception_object") |
| 61 | + end |
| 62 | + |
| 63 | + it "ignores events that doesn't have a started timestamp" do |
| 64 | + expect do |
| 65 | + ActiveSupport::Notifications.publish "foo", Object.new |
| 66 | + end.not_to raise_error |
| 67 | + |
| 68 | + expect(breadcrumb_buffer.count).to be_zero |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context "with tracing" do |
| 73 | + before do |
| 74 | + make_basic_app do |sentry_config| |
| 75 | + sentry_config.breadcrumbs_logger = [:active_support_logger] |
| 76 | + sentry_config.traces_sample_rate = 1.0 |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + after do |
| 81 | + Sentry::Rails::Tracing.unsubscribe_tracing_events |
| 82 | + Sentry::Rails::Tracing.remove_active_support_notifications_patch |
| 83 | + end |
| 84 | + |
70 | 85 | it "captures correct request data of normal requests" do |
71 | 86 | p = Post.create! |
72 | 87 |
|
|
89 | 104 | expect(breadcrumb["data"].keys).not_to include("response") |
90 | 105 | end |
91 | 106 |
|
92 | | - it "ignores exception data" do |
93 | | - get "/view_exception" |
| 107 | + it "doesn't add internal start timestamp payload to breadcrumbs data" do |
| 108 | + p = Post.create! |
94 | 109 |
|
95 | | - expect(event.dig("breadcrumbs", "values", -1, "data").keys).not_to include("exception") |
96 | | - expect(event.dig("breadcrumbs", "values", -1, "data").keys).not_to include("exception_object") |
97 | | - end |
| 110 | + get "/posts/#{p.id}" |
98 | 111 |
|
99 | | - it "ignores events that doesn't have a float as started attributes" do |
100 | | - expect do |
101 | | - ActiveSupport::Notifications.publish "foo", Time.now |
102 | | - end.not_to raise_error |
| 112 | + expect(transport.events.count).to eq(1) |
103 | 113 |
|
104 | | - expect(breadcrumb_buffer.count).to be_zero |
| 114 | + transaction = transport.events.last.to_hash |
| 115 | + breadcrumbs = transaction[:breadcrumbs][:values] |
| 116 | + process_action_crumb = breadcrumbs.last |
| 117 | + expect(process_action_crumb[:category]).to eq("process_action.action_controller") |
| 118 | + expect(process_action_crumb[:data].has_key?(Sentry::Rails::Tracing::START_TIMESTAMP_NAME)).to eq(false) |
105 | 119 | end |
106 | 120 | end |
107 | 121 | end |
0 commit comments