110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/rspec/buildkite/analytics/uploader.rb', line 110
def self.configure
RSpec::Buildkite::Analytics.uploader = self
RSpec.configure do |config|
config.before(:suite) do
config.add_formatter RSpec::Buildkite::Analytics::Reporter
if RSpec::Buildkite::Analytics.api_token
contact_uri = URI.parse(RSpec::Buildkite::Analytics.url)
http = Net::HTTP.new(contact_uri.host, contact_uri.port)
http.use_ssl = contact_uri.scheme == "https"
= "Token token=\"#{RSpec::Buildkite::Analytics.api_token}\""
contact = Net::HTTP::Post.new(contact_uri.path, {
"Authorization" => ,
"Content-Type" => "application/json",
})
contact.body = {
run_env: CI.env,
format: "websocket"
}.to_json
response = begin
http.request(contact)
rescue *REQUEST_EXCEPTIONS => e
puts "Buildkite Test Analytics: Error communicating with the server: #{e.message}"
end
return unless response
case response.code
when "401"
puts "Buildkite Test Analytics: Invalid Suite API key. Please double check your Suite API key."
when "200"
json = JSON.parse(response.body)
if (socket_url = json["cable"]) && (channel = json["channel"])
RSpec::Buildkite::Analytics.session = Session.new(socket_url, , channel)
end
else
request_id = response.to_hash["x-request-id"]
puts "rspec-buildkite-analytics could not establish an initial connection with Buildkite. You may be missing some data for this test suite, please contact support."
end
else
if !!ENV["BUILDKITE_BUILD_ID"]
puts "Buildkite Test Analytics: No Suite API key provided. You can get the API key from your Suite settings page."
end
end
end
config.around(:each) do |example|
tracer = RSpec::Buildkite::Analytics::Tracer.new
Thread.current[:_buildkite_tracer] = tracer
example.run
Thread.current[:_buildkite_tracer] = nil
tracer.finalize
trace = RSpec::Buildkite::Analytics::Uploader::Trace.new(example, tracer.history)
RSpec::Buildkite::Analytics.uploader.traces << trace
end
end
RSpec::Buildkite::Analytics::Network.configure
RSpec::Buildkite::Analytics::Object.configure
ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload|
tracer&.backfill(:sql, finish - start, **{ query: payload[:sql] })
end
end
|