/
active_support_breadcrumbs_spec.rb
109 lines (88 loc) · 3.37 KB
/
active_support_breadcrumbs_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require "spec_helper"
RSpec.describe "Sentry::Breadcrumbs::ActiveSupportLogger", type: :request do
before do
make_basic_app do |sentry_config|
sentry_config.breadcrumbs_logger = [:active_support_logger]
sentry_config.traces_sample_rate = 1.0
end
end
after do
require 'sentry/rails/breadcrumb/active_support_logger'
Sentry::Rails::Breadcrumb::ActiveSupportLogger.detach
# even though we cleanup breadcrumbs in the rack middleware
# Breadcrumbs::ActiveSupportLogger subscribes to "every" instrumentation
# so it'll create other instrumentations "after" the request is finished
# and we should clear those as well
Sentry.get_current_scope.clear_breadcrumbs
end
let(:transport) do
Sentry.get_current_client.transport
end
let(:breadcrumb_buffer) do
Sentry.get_current_scope.breadcrumbs
end
let(:event) do
transport.events.first.to_json_compatible
end
after do
transport.events = []
end
it "captures correct data of exception requests" do
get "/exception"
expect(response.status).to eq(500)
breadcrumbs = event.dig("breadcrumbs", "values")
expect(breadcrumbs.count).to eq(2)
breadcrumb = breadcrumbs.detect { |b| b["category"] == "process_action.action_controller" }
expect(breadcrumb["data"]).to include(
{
"controller" => "HelloController",
"action" => "exception",
"params" => { "controller" => "hello", "action" => "exception" },
"format" => "html",
"method" => "GET", "path" => "/exception",
}
)
expect(breadcrumb["data"].keys).not_to include("headers")
expect(breadcrumb["data"].keys).not_to include("request")
expect(breadcrumb["data"].keys).not_to include("response")
end
it "captures correct request data of normal requests" do
p = Post.create!
get "/posts/#{p.id}"
breadcrumbs = event.dig("breadcrumbs", "values")
breadcrumb = breadcrumbs.detect { |b| b["category"] == "process_action.action_controller" }
expect(breadcrumb["data"]).to include(
{
"controller" => "PostsController",
"action" => "show",
"params" => { "controller" => "posts", "action" => "show", "id" => p.id.to_s },
"format" => "html",
"method" => "GET", "path" => "/posts/#{p.id}",
}
)
expect(breadcrumb["data"].keys).not_to include("headers")
expect(breadcrumb["data"].keys).not_to include("request")
expect(breadcrumb["data"].keys).not_to include("response")
end
it "ignores exception data" do
get "/view_exception"
expect(event.dig("breadcrumbs", "values", -1, "data").keys).not_to include("exception")
expect(event.dig("breadcrumbs", "values", -1, "data").keys).not_to include("exception_object")
end
it "ignores events that doesn't have a started timestamp" do
expect do
ActiveSupport::Notifications.publish "foo", Object.new
end.not_to raise_error
expect(breadcrumb_buffer.count).to be_zero
end
context "when used with tracing" do
it "doesn't add internal start timestamp payload to breadcrumbs data" do
p = Post.create!
get "/posts/#{p.id}"
expect(transport.events.count).to eq(1)
transaction = transport.events.last.to_hash
breadcrumbs = transaction[:breadcrumbs][:values]
expect(breadcrumbs.last[:data].has_key?(Sentry::Rails::Tracing::START_TIMESTAMP_NAME)).to eq(false)
end
end
end