Module: Buildkite::TestCollector
- Defined in:
- lib/buildkite/test_collector.rb,
lib/buildkite/test_collector.rb,
lib/buildkite/test_collector/error.rb,
lib/buildkite/test_collector/object.rb,
lib/buildkite/test_collector/tracer.rb,
lib/buildkite/test_collector/network.rb,
lib/buildkite/test_collector/session.rb,
lib/buildkite/test_collector/version.rb,
lib/buildkite/test_collector/uploader.rb,
lib/buildkite/test_collector/http_client.rb
Defined Under Namespace
Modules: MinitestPlugin, RSpecPlugin Classes: CI, Error, HTTPClient, MinDurationSpanFilter, Network, Object, Session, TimeoutError, Tracer, UUID, Uploader
Constant Summary collapse
- DEFAULT_URL =
"https://analytics-api.buildkite.com/v1/uploads"
- DEFAULT_UPLOAD_BATCH_SIZE =
500
- VERSION =
"2.7.2"
- NAME =
"buildkite-test_collector"
Class Attribute Summary collapse
-
.api_token ⇒ Object
Returns the value of attribute api_token.
-
.artifact_path ⇒ Object
Returns the value of attribute artifact_path.
-
.batch_size ⇒ Object
Returns the value of attribute batch_size.
-
.env ⇒ Object
Returns the value of attribute env.
-
.session ⇒ Object
Returns the value of attribute session.
-
.span_filters ⇒ Object
Returns the value of attribute span_filters.
-
.trace_min_duration ⇒ Object
Returns the value of attribute trace_min_duration.
-
.tracing_enabled ⇒ Object
Returns the value of attribute tracing_enabled.
-
.uploader ⇒ Object
Returns the value of attribute uploader.
-
.url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .annotate(content) ⇒ Object
- .configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {}) ⇒ Object
- .enable_tracing! ⇒ Object
- .hook_into(hook) ⇒ Object
Class Attribute Details
.api_token ⇒ Object
Returns the value of attribute api_token.
32 33 34 |
# File 'lib/buildkite/test_collector.rb', line 32 def api_token @api_token end |
.artifact_path ⇒ Object
Returns the value of attribute artifact_path.
37 38 39 |
# File 'lib/buildkite/test_collector.rb', line 37 def artifact_path @artifact_path end |
.batch_size ⇒ Object
Returns the value of attribute batch_size.
39 40 41 |
# File 'lib/buildkite/test_collector.rb', line 39 def batch_size @batch_size end |
.env ⇒ Object
Returns the value of attribute env.
38 39 40 |
# File 'lib/buildkite/test_collector.rb', line 38 def env @env end |
.session ⇒ Object
Returns the value of attribute session.
35 36 37 |
# File 'lib/buildkite/test_collector.rb', line 35 def session @session end |
.span_filters ⇒ Object
Returns the value of attribute span_filters.
41 42 43 |
# File 'lib/buildkite/test_collector.rb', line 41 def span_filters @span_filters end |
.trace_min_duration ⇒ Object
Returns the value of attribute trace_min_duration.
40 41 42 |
# File 'lib/buildkite/test_collector.rb', line 40 def trace_min_duration @trace_min_duration end |
.tracing_enabled ⇒ Object
Returns the value of attribute tracing_enabled.
36 37 38 |
# File 'lib/buildkite/test_collector.rb', line 36 def tracing_enabled @tracing_enabled end |
.uploader ⇒ Object
Returns the value of attribute uploader.
34 35 36 |
# File 'lib/buildkite/test_collector.rb', line 34 def uploader @uploader end |
.url ⇒ Object
Returns the value of attribute url.
33 34 35 |
# File 'lib/buildkite/test_collector.rb', line 33 def url @url end |
Class Method Details
.annotate(content) ⇒ Object
72 73 74 75 76 |
# File 'lib/buildkite/test_collector.rb', line 72 def self.annotate(content) tracer = Buildkite::TestCollector::Uploader.tracer tracer&.enter("annotation", **{ content: content }) tracer&.leave end |
.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/buildkite/test_collector.rb', line 44 def self.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {}) self.api_token = (token || ENV["BUILDKITE_ANALYTICS_TOKEN"])&.strip self.url = url || DEFAULT_URL self.tracing_enabled = tracing_enabled self.artifact_path = artifact_path self.env = env self.batch_size = ENV.fetch("BUILDKITE_ANALYTICS_UPLOAD_BATCH_SIZE") { DEFAULT_UPLOAD_BATCH_SIZE }.to_i trace_min_ms_string = ENV["BUILDKITE_ANALYTICS_TRACE_MIN_MS"] self.trace_min_duration = if trace_min_ms_string && !trace_min_ms_string.empty? Float(trace_min_ms_string) / 1000 end self.span_filters = [] unless self.trace_min_duration.nil? self.span_filters << MinDurationSpanFilter.new(self.trace_min_duration) end self.hook_into(hook) end |
.enable_tracing! ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/buildkite/test_collector.rb', line 78 def self.enable_tracing! return unless self.tracing_enabled Buildkite::TestCollector::Network.configure Buildkite::TestCollector::Object.configure return unless defined?(ActiveSupport) require "active_support/notifications" ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload| Buildkite::TestCollector::Uploader.tracer&.backfill(:sql, finish - start, **{ query: payload[:sql] }) end end |
.hook_into(hook) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/buildkite/test_collector.rb', line 65 def self.hook_into(hook) file = "test_collector/library_hooks/#{hook}" require_relative file rescue LoadError raise ArgumentError.new("#{hook.inspect} is not a supported Buildkite Analytics Test library hook.") end |