Class: SpanSupport
- Inherits:
-
Object
- Object
- SpanSupport
- Defined in:
- lib/features/support/span_support.rb
Class Method Summary collapse
- .assert_received_minimum_span_count(minimum) ⇒ Object
- .assert_received_named_span(span_name) ⇒ Object
- .assert_received_ranged_span_count(minimum, maximum) ⇒ Object
- .assert_received_span_count(count) ⇒ Object
- .assert_received_spans(min_received, max_received = nil) ⇒ Object
- .get_named_spans(span_name) ⇒ Object
- .named_span_exists?(span_name) ⇒ Boolean
- .received_spans_names ⇒ Object
- .spans_from_request_list(list) ⇒ Object
- .store_named_span_field(span_name, field, store_key) ⇒ Object
Class Method Details
.assert_received_minimum_span_count(minimum) ⇒ Object
28 29 30 |
# File 'lib/features/support/span_support.rb', line 28 def assert_received_minimum_span_count(minimum) assert_received_spans(minimum) end |
.assert_received_named_span(span_name) ⇒ Object
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 |
# File 'lib/features/support/span_support.rb', line 42 def assert_received_named_span(span_name) timeout = Maze.config.receive_requests_wait wait = Maze::Wait.new(timeout: timeout) received = wait.until { SpanSupport.named_span_exists?(span_name) } spans = Maze::Api::Model::SpanSet.new list = Maze::Server.traces list.remaining.each { |t| spans.add_from_trace_hash(t[:body]) } names = spans.size == 0 ? '.' : ", with names:\n#{spans.names.sort.join("\n")}" unless received raise Test::Unit::AssertionFailedError.new <<-MESSAGE Expected span with name #{span_name} not received within the #{timeout}s timeout. #{spans.size} spans were received#{names} This could indicate that: - Bugsnag crashed with a fatal error. - Bugsnag did not make the requests that it should have done. - The requests were made, but not deemed to be valid (e.g. missing integrity header). - The requests made were prevented from being received due to a network or other infrastructure issue. Please check the Maze Runner and device logs to confirm.) MESSAGE end Maze::Schemas::Validator.validate_payload_elements(list, 'trace') end |
.assert_received_ranged_span_count(minimum, maximum) ⇒ Object
32 33 34 |
# File 'lib/features/support/span_support.rb', line 32 def assert_received_ranged_span_count(minimum, maximum) assert_received_spans(minimum, maximum) end |
.assert_received_span_count(count) ⇒ Object
24 25 26 |
# File 'lib/features/support/span_support.rb', line 24 def assert_received_span_count(count) assert_received_spans(count, count) end |
.assert_received_spans(min_received, max_received = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/features/support/span_support.rb', line 68 def assert_received_spans(min_received, max_received = nil) timeout = Maze.config.receive_requests_wait wait = Maze::Wait.new(timeout: timeout) list = Maze::Server.traces received = wait.until { SpanSupport.spans_from_request_list(list).size >= min_received } received_count = SpanSupport.spans_from_request_list(list).size unless received raise Test::Unit::AssertionFailedError.new <<-MESSAGE Expected #{min_received} spans but received #{received_count} within the #{timeout}s timeout. This could indicate that: - Bugsnag crashed with a fatal error. - Bugsnag did not make the requests that it should have done. - The requests were made, but not deemed to be valid (e.g. missing integrity header). - The requests made were prevented from being received due to a network or other infrastructure issue. Please check the Maze Runner and device logs to confirm.) MESSAGE end Maze.check.operator(max_received, :>=, received_count, "#{received_count} spans received") if max_received Maze::Schemas::Validator.validate_payload_elements(list, 'trace') end |
.get_named_spans(span_name) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/features/support/span_support.rb', line 11 def get_named_spans(span_name) spans = spans_from_request_list(Maze::Server.traces) named_spans = spans.find_all { |span| span['name'].eql?(span_name) } raise Test::Unit::AssertionFailedError.new "No spans were found with the name #{span_name}" if named_spans.empty? named_spans end |
.named_span_exists?(span_name) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/features/support/span_support.rb', line 18 def named_span_exists?(span_name) spans = spans_from_request_list(Maze::Server.traces) named_spans = spans.find_all { |span| span['name'].eql?(span_name) } !named_spans.empty? end |
.received_spans_names ⇒ Object
36 37 38 39 40 |
# File 'lib/features/support/span_support.rb', line 36 def received_spans_names spans = spans_from_request_list(Maze::Server.traces) names spans.map { |span| span['name'] } end |
.spans_from_request_list(list) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/features/support/span_support.rb', line 3 def spans_from_request_list(list) list.remaining .flat_map { |req| req[:body]['resourceSpans'] } .flat_map { |r| r['scopeSpans'] } .flat_map { |s| s['spans'] } .select { |s| !s.nil? } end |
.store_named_span_field(span_name, field, store_key) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/features/support/span_support.rb', line 92 def store_named_span_field(span_name, field, store_key) spans = SpanSupport.get_named_spans(span_name) values = spans.map { |span| span[field] }.compact raise Test::Unit::AssertionFailedError.new "Expected 1 span named #{span_name}, found #{values.size}" unless values.size == 1 value = Maze::Helper.read_key_path(spans[0], field) Maze::Store.values[store_key] = value.dup end |