3
3
RSpec . describe "Tracing" , type : :e2e do
4
4
def expect_valid_sample_rand ( sample_rand )
5
5
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 + $/ )
7
7
sample_rand_value = sample_rand . to_f
8
8
expect ( sample_rand_value ) . to be >= 0.0
9
9
expect ( sample_rand_value ) . to be < 1.0
@@ -45,6 +45,7 @@ def get_http_server_transactions_with_headers
45
45
46
46
transactions_with_headers
47
47
end
48
+
48
49
it "validates basic tracing functionality" do
49
50
visit "/error"
50
51
@@ -105,8 +106,35 @@ def get_http_server_transactions_with_headers
105
106
expect_valid_sample_rand ( dsc [ "sample_rand" ] )
106
107
107
108
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" )
110
138
end
111
139
end
112
140
@@ -123,17 +151,57 @@ def get_http_server_transactions_with_headers
123
151
expect ( page ) . to have_content ( "Error:" )
124
152
125
153
dsc_envelopes = expect_dsc_in_envelope_headers
126
- expect ( dsc_envelopes . length ) . to be >= 2
154
+ expect ( dsc_envelopes . length ) . to be >= 3
127
155
128
156
trace_ids = dsc_envelopes . map { |dsc | dsc [ "trace_id" ] } . uniq
129
157
sample_rands = dsc_envelopes . map { |dsc | dsc [ "sample_rand" ] } . uniq
130
158
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 )
133
161
134
162
sample_rands . each do |sample_rand |
135
163
expect_valid_sample_rand ( sample_rand )
136
164
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 )
137
205
end
138
206
end
139
207
end
0 commit comments