Skip to content

Commit db7da2e

Browse files
committed
Improve e2e spec
1 parent c2088a3 commit db7da2e

File tree

1 file changed

+74
-6
lines changed

1 file changed

+74
-6
lines changed

spec/features/tracing_spec.rb

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.describe "Tracing", type: :e2e do
44
def expect_valid_sample_rand(sample_rand)
55
expect(sample_rand).not_to be_nil
6-
expect(sample_rand).to match(/^\d+\.\d{1,6}$/)
6+
expect(sample_rand).to match(/^\d+\.\d+$/)
77
sample_rand_value = sample_rand.to_f
88
expect(sample_rand_value).to be >= 0.0
99
expect(sample_rand_value).to be < 1.0
@@ -45,6 +45,7 @@ def get_http_server_transactions_with_headers
4545

4646
transactions_with_headers
4747
end
48+
4849
it "validates basic tracing functionality" do
4950
visit "/error"
5051

@@ -105,8 +106,35 @@ def get_http_server_transactions_with_headers
105106
expect_valid_sample_rand(dsc["sample_rand"])
106107

107108
expect(dsc["sampled"]).to eq("true")
108-
expect(dsc["environment"]).to eq("development")
109-
expect(dsc["public_key"]).to eq("user")
109+
expect(dsc["environment"]).to eql("production")
110+
expect(dsc["public_key"]).to eql("user")
111+
end
112+
113+
transactions_with_headers = get_http_server_transactions_with_headers
114+
115+
transactions_with_headers.each do |transaction|
116+
headers = transaction.dig("request", "headers")
117+
118+
expect(headers).not_to be_nil
119+
120+
sentry_trace = headers["Sentry-Trace"] || headers["sentry-trace"]
121+
expect(sentry_trace).not_to be_nil
122+
expect(sentry_trace).to match(/^[a-f0-9]{32}-[a-f0-9]{16}(-[01])?$/)
123+
124+
baggage = headers["Baggage"] || headers["baggage"]
125+
expect(baggage).not_to be_nil
126+
expect(baggage).to include("sentry-sample_rand=")
127+
128+
sample_rand_match = baggage.match(/sentry-sample_rand=([0-9.]+)/)
129+
expect(sample_rand_match).not_to be_nil
130+
sample_rand_value = sample_rand_match[1]
131+
expect_valid_sample_rand(sample_rand_value)
132+
133+
trace_context = transaction.dig("contexts", "trace")
134+
expect(trace_context).not_to be_nil
135+
expect(trace_context["trace_id"]).to match(/^[a-f0-9]{32}$/)
136+
expect(trace_context["span_id"]).to match(/^[a-f0-9]{16}$/)
137+
expect(trace_context["op"]).to eq("http.server")
110138
end
111139
end
112140

@@ -123,17 +151,57 @@ def get_http_server_transactions_with_headers
123151
expect(page).to have_content("Error:")
124152

125153
dsc_envelopes = expect_dsc_in_envelope_headers
126-
expect(dsc_envelopes.length).to be >= 2
154+
expect(dsc_envelopes.length).to be >= 3
127155

128156
trace_ids = dsc_envelopes.map { |dsc| dsc["trace_id"] }.uniq
129157
sample_rands = dsc_envelopes.map { |dsc| dsc["sample_rand"] }.uniq
130158

131-
expect(trace_ids.length).to be >= 2
132-
expect(sample_rands.length).to be >= 2
159+
expect(trace_ids.length).to be(1)
160+
expect(sample_rands.length).to be(1)
133161

134162
sample_rands.each do |sample_rand|
135163
expect_valid_sample_rand(sample_rand)
136164
end
165+
166+
transactions_with_headers = get_http_server_transactions_with_headers
167+
168+
expect(transactions_with_headers.length).to eql(3)
169+
170+
transactions_with_headers.each do |transaction|
171+
headers = transaction.dig("request", "headers")
172+
expect(headers).not_to be_nil
173+
174+
sentry_trace = headers["Sentry-Trace"] || headers["sentry-trace"]
175+
expect(sentry_trace).not_to be_nil
176+
expect(sentry_trace).to match(/^[a-f0-9]{32}-[a-f0-9]{16}(-[01])?$/)
177+
178+
baggage = headers["Baggage"] || headers["baggage"]
179+
expect(baggage).not_to be_nil
180+
expect(baggage).to include("sentry-sample_rand=")
181+
182+
sample_rand_match = baggage.match(/sentry-sample_rand=([0-9.]+)/)
183+
expect(sample_rand_match).not_to be_nil
184+
sample_rand_value = sample_rand_match[1]
185+
expect_valid_sample_rand(sample_rand_value)
186+
187+
trace_context = transaction.dig("contexts", "trace")
188+
expect(trace_context).not_to be_nil
189+
expect(trace_context["trace_id"]).to match(/^[a-f0-9]{32}$/)
190+
expect(trace_context["span_id"]).to match(/^[a-f0-9]{16}$/)
191+
expect(trace_context["op"]).to eq("http.server")
192+
end
193+
194+
transaction_trace_ids = transactions_with_headers.map { |t| t.dig("contexts", "trace", "trace_id") }.uniq
195+
expect(transaction_trace_ids.length).to be(1)
196+
197+
transaction_sample_rands = transactions_with_headers.map do |transaction|
198+
headers = transaction.dig("request", "headers")
199+
baggage = headers["Baggage"] || headers["baggage"]
200+
sample_rand_match = baggage.match(/sentry-sample_rand=([0-9.]+)/)
201+
sample_rand_match[1] if sample_rand_match
202+
end.compact.uniq
203+
204+
expect(transaction_sample_rands.length).to be(1)
137205
end
138206
end
139207
end

0 commit comments

Comments
 (0)