module Tracing::Matchers

Constants

VERSION

Public Instance Methods

be_child_of(parent = :any) click to toggle source

The be_child_of matcher tests that the span/span context is a child of some other span/span context. @example

# Passes if span is a child of any span
expect(span).to have_parent

# Passes if span is a child of a specific span context
expect(span).to be_child_of("parent operation")
expect(span).to be_child_of(parent_span)
expect(span).to be_child_of(parent_span_context)

@param [String, Span, SpanContext] parent @return [HaveBaggage]

# File lib/tracing/matchers/span_matchers.rb, line 72
def be_child_of(parent = :any)
  Tracing::Matchers::Span::BeChildOf.new(parent)
end
Also aliased as: have_parent
follow_after(previous) click to toggle source

The follow_after matcher tests that the span follows after some other span. @example

# Passes if span follows after spcific span
expect(span).to be_child_of("previous operation")
expect(span).to be_child_of(previous_span)

@param [String, Span] previous expected span to follow after @return [FollowAfter]

# File lib/tracing/matchers/span_matchers.rb, line 86
def follow_after(previous)
  Tracing::Matchers::Span::FollowAfter.new(previous)
end
have_baggage(*args) click to toggle source

The have_baggage matcher tests that the span/span context includes baggage. @example

# Passes if span have any baggage item
expect(span).to have_baggage

# Passes if span includes a baggage item with "tag" key, and "value" value
expect(span).to have_baggage("key", "value")
expect(span).to have_baggage("key" => "value")
expect(span).to have_baggage("key", /value/)

@return [HaveBaggage]

# File lib/tracing/matchers/span_matchers.rb, line 54
def have_baggage(*args)
  Tracing::Matchers::Span::HaveBaggage.new(*args)
end
Also aliased as: have_baggage_item
have_baggage_item(*args)
Alias for: have_baggage
have_log(**fields) click to toggle source

The have_log matcher tests that the span includes a tag. @example

# Passes if span have any log
expect(span).to have_log

# Passes if span includes a log entry with event: "error"
expect(span).to have_log(event: "error")
expect(span).to have_log(message: /description/)

@return [HaveTag]

# File lib/tracing/matchers/span_matchers.rb, line 37
def have_log(**fields)
  Tracing::Matchers::Span::HaveLog.new(**fields)
end
Also aliased as: have_logs
have_logs(**fields)
Alias for: have_log
have_parent(parent = :any)
Alias for: be_child_of
have_span(operation_name = anything) click to toggle source

The have_span matcher tests that the tracer traced a span matching a criteria.

@example

# Behaves very similar to have_traces without any arguments.
expect(tracer).to have_span

# Passes if the tracer traced span with the operation name "User Load".
expect(tracer).to have_span("User Load")

# Passes if the tracer traced span with the operation name "User Load"
# which is still in progress.
expect(tracer).to have_span("User Load").in_progress

# Same as above
expect(tracer).to have_span("User Load").started

# Passes if the tracer traced span with the operation name "User Load"
# which has finished.
expect(tracer).to have_span("User Load").finished

# Passes if the tracer traced any span which has any tag
expect(tracer).to have_span.with_tags

# Passes if the tracer traced span with the operation name "User Load"
# and which has any tag
expect(tracer).to have_span("User Load").with_tags

# Passes if the tracer traced span with the operation name "User Load"
# and which has a tag 'component' => 'ActiveRecord'.
expect(tracer).to have_span("User Load").with_tags('component' => 'ActiveRecord')

# Passes if the tracer traced any span which has any log entry
expect(tracer).to have_span.with_logs

# Passes if the tracer traced span with the operation name "User Load"
# and which has a log entry with event 'error'.
expect(tracer).to have_span("User Load").with_logs(event: 'error')

# Passes if the tracer traced any span which has any entry in a baggage
expect(tracer).to have_span.with_baggae

# Passes if the tracer traced span with the operation name "User Load"
# and which has a baggage with 'account_id' => '1'
expect(tracer).to have_span("User Load").with_baggae('account_id' => '1')

# Passes if the tracer traced any span which has a parent
expect(tracer).to have_span.with_parent

# Passes if the tracer traced any span which has root_span as a parent
expect(tracer).to have_span.child_of(root_span)

# Passes if the tracer traced span with the operation name "User Load"
# and which has a parent span with operation name "Authentication".
expect(tracer).to have_span("User Load").child_of("Authentication")

# Passes if the tracer traced span with the operation name "User Load"
# which has a tag 'component' => 'ActiveRecord',
# has any log entry,
# has a baggage with 'account_id' => '1',
# and is child of a span with operation name "Authentication".
expect(tracer).to have_span("User Load")
                  .with_tags('component' => 'ActiveRecord')
                  .with_logs
                  .with_baggage('account_id' => '1')
                  .child_of("Authentication")

@param [String] operation_name operation name of a searched span @return [HaveSpan]

@see HaveSpan#in_progress @see HaveSpan#started @see HaveSpan#finished @see HaveSpan#with_tags @see HaveSpan#with_logs @see HaveSpan#with_baggage @see HaveSpan#with_parent @see HaveSpan#child_of

# File lib/tracing/matchers.rb, line 147
def have_span(operation_name = anything)
  Tracing::Matchers::HaveSpan.new(operation_name)
end
have_spans(n = anything) click to toggle source

The have_spans matcher tests that the tracer traced any or a specific number of spans.

@example

# Passes if either `tracer.spans`, or `tracer.finished_spans` includes any span
expect(tracer).to have_spans

# Passes if either `tracer.spans`, or `tracer.finished_spans` includes exactly 10 spans
expect(tracer).to have_spans(10)

# Passes if `tracer.spans` includes any span
expect(tracer).to have_spans.started

# Passes if `tracer.finished_spans` includes any span
expect(tracer).to have_spans.finished

@note It's possible to chain `started` and `finished` at the same time.

Expect that only the last method will be applied e.g. `have_spans.finished.started`
will result in application of `started`.

@param [Fixnum] n expected number of traced spans @return [HaveSpans]

@see HaveSpans#started @see HaveSpans#finished

# File lib/tracing/matchers.rb, line 65
def have_spans(n = anything)
  Tracing::Matchers::HaveSpans.new(n)
end
have_tag(*args) click to toggle source

The have_tag matcher tests that the span includes tags. @example

# Passes if span have any tag
expect(span).to have_tag

# Passes if span includes a tag with "tag" key, and "value" value
expect(span).to have_tag("key", "value")
expect(span).to have_tag("key" => "value")
expect(span).to have_tag("key", /value/)

@return [HaveTag]

# File lib/tracing/matchers/span_matchers.rb, line 21
def have_tag(*args)
  Tracing::Matchers::Span::HaveTag.new(*args)
end
Also aliased as: have_tags
have_tags(*args)
Alias for: have_tag
have_traces(n = anything) click to toggle source

The have_traces matcher tests that the tracer traced any or a specific number of traces.

@example

# Passes if tracer traced any trace
expect(tracer).to have_spans

# Passes if tracer traced exactly 10 distinct traces
expect(tracer).to have_spans(10)

# Passes if tracer started any trace
expect(tracer).to have_spans.started

# Passes if tracer has any finished traces
expect(tracer).to have_spans.finished

@note It's possible to chain `started` and `finished` at the same time.

Expect that only the last method will be applied e.g. `have_spans.finished.started`
will result in application of `started`.

@param [Fixnum] n expected number of distinct traces @return [HaveTraces]

@see HaveTraces#started @see HaveTraces#finished

# File lib/tracing/matchers.rb, line 35
def have_traces(n = anything)
  Tracing::Matchers::HaveTraces.new(n)
end