Class: RspecOtel::Matchers::EmitSpan
- Inherits:
-
Object
- Object
- RspecOtel::Matchers::EmitSpan
- Defined in:
- lib/rspec_otel/matchers/emit_span.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #as_child ⇒ Object
- #as_root ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(name = nil) ⇒ EmitSpan
constructor
A new instance of EmitSpan.
- #matches?(block) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
- #with_attributes(attributes) ⇒ Object
- #with_event(name, attributes = {}) ⇒ Object
- #with_exception(exception = nil) ⇒ Object
- #with_link(attributes = {}) ⇒ Object
- #with_status(code, description) ⇒ Object
- #without_attributes(attributes) ⇒ Object
- #without_event(name, attributes = {}) ⇒ Object
- #without_exception(exception = nil) ⇒ Object
- #without_link(attributes = {}) ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ EmitSpan
Returns a new instance of EmitSpan.
8 9 10 11 12 13 14 15 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 8 def initialize(name = nil) @name = name @filters = [] @before_spans = [] @closest_span = nil @filters << name_filter end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 6 def name @name end |
Instance Method Details
#as_child ⇒ Object
22 23 24 25 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 22 def as_child @filters << ->(span) { span.parent_span_id && span.parent_span_id != OpenTelemetry::Trace::INVALID_SPAN_ID } self end |
#as_root ⇒ Object
27 28 29 30 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 27 def as_root @filters << ->(span) { span.parent_span_id == OpenTelemetry::Trace::INVALID_SPAN_ID } self end |
#failure_message ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 77 def closest = closest_span prefix = "expected span #{failure_match_description} #{printable_name} to have been emitted" case closest when nil then "#{prefix}, but there were no spans emitted at all" when OpenTelemetry::SDK::Trace::SpanData then (prefix, closest) else raise "I don't know what to do with a #{closest.class} span" end end |
#failure_message_when_negated ⇒ Object
88 89 90 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 88 def "expected span #{failure_match_description} #{printable_name} to not have been emitted" end |
#matches?(block) ⇒ Boolean
17 18 19 20 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 17 def matches?(block) capture_before_spans(block) matching_span? end |
#supports_block_expectations? ⇒ Boolean
92 93 94 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 92 def supports_block_expectations? true end |
#with_attributes(attributes) ⇒ Object
32 33 34 35 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 32 def with_attributes(attributes) @filters << ->(span) { attributes_match?(span.attributes, attributes) } self end |
#with_event(name, attributes = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 52 def with_event(name, attributes = {}) event = OpenTelemetry::SDK::Trace::Event.new(name, attributes) @filters << ->(span) { span.events && event_match?(span.events, event) } self end |
#with_exception(exception = nil) ⇒ Object
69 70 71 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 69 def with_exception(exception = nil) with_event('exception', exception_attributes(exception)) end |
#with_link(attributes = {}) ⇒ Object
42 43 44 45 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 42 def with_link(attributes = {}) @filters << ->(span) { span.links && link_match?(span.links, attributes) } self end |
#with_status(code, description) ⇒ Object
64 65 66 67 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 64 def with_status(code, description) @filters << ->(span) { status_match?(span.status, code, description) } self end |
#without_attributes(attributes) ⇒ Object
37 38 39 40 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 37 def without_attributes(attributes) @filters << ->(span) { !attributes_match?(span.attributes, attributes) } self end |
#without_event(name, attributes = {}) ⇒ Object
58 59 60 61 62 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 58 def without_event(name, attributes = {}) event = OpenTelemetry::SDK::Trace::Event.new(name, attributes) @filters << ->(span) { span.events.nil? || !event_match?(span.events, event) } self end |
#without_exception(exception = nil) ⇒ Object
73 74 75 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 73 def without_exception(exception = nil) without_event('exception', exception_attributes(exception)) end |
#without_link(attributes = {}) ⇒ Object
47 48 49 50 |
# File 'lib/rspec_otel/matchers/emit_span.rb', line 47 def without_link(attributes = {}) @filters << ->(span) { span.links.nil? || !link_match?(span.links, attributes) } self end |