Module: Tracing::Matchers

Defined in:
lib/tracing/matchers.rb,
lib/tracing/matchers/version.rb,
lib/tracing/matchers/have_span.rb,
lib/tracing/matchers/have_spans.rb,
lib/tracing/matchers/have_traces.rb,
lib/tracing/matchers/span/have_log.rb,
lib/tracing/matchers/span/have_tag.rb,
lib/tracing/matchers/span_matchers.rb,
lib/tracing/matchers/span/be_child_of.rb,
lib/tracing/matchers/span/follow_after.rb,
lib/tracing/matchers/span/have_baggage.rb

Defined Under Namespace

Modules: Span Classes: HaveSpan, HaveSpans, HaveTraces

Constant Summary collapse

VERSION =
"1.3.0"

Instance Method Summary collapse

Instance Method Details

#be_child_of(parent = :any) ⇒ HaveBaggage Also known as: have_parent

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

Examples:


# 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)

Parameters:

  • parent (String, Span, SpanContext) (defaults to: :any)

Returns:

  • (HaveBaggage)


72
73
74
# File 'lib/tracing/matchers/span_matchers.rb', line 72

def be_child_of(parent = :any)
  Tracing::Matchers::Span::BeChildOf.new(parent)
end

#follow_after(previous) ⇒ FollowAfter

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

Examples:


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

Parameters:

  • previous (String, Span)

    expected span to follow after

Returns:

  • (FollowAfter)


86
87
88
# File 'lib/tracing/matchers/span_matchers.rb', line 86

def follow_after(previous)
  Tracing::Matchers::Span::FollowAfter.new(previous)
end

#have_baggage(*args) ⇒ HaveBaggage Also known as: have_baggage_item

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

Examples:


# 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/)

Returns:

  • (HaveBaggage)


54
55
56
# File 'lib/tracing/matchers/span_matchers.rb', line 54

def have_baggage(*args)
  Tracing::Matchers::Span::HaveBaggage.new(*args)
end

#have_log(**fields) ⇒ HaveTag Also known as: have_logs

The have_log matcher tests that the span includes a tag.

Examples:


# 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/)

Returns:

  • (HaveTag)


37
38
39
# File 'lib/tracing/matchers/span_matchers.rb', line 37

def have_log(**fields)
  Tracing::Matchers::Span::HaveLog.new(**fields)
end

#have_span(operation_name = anything) ⇒ HaveSpan

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

Examples:


# 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")

Parameters:

  • operation_name (String) (defaults to: anything)

    operation name of a searched span

Returns:

See Also:



147
148
149
# File 'lib/tracing/matchers.rb', line 147

def have_span(operation_name = anything)
  Tracing::Matchers::HaveSpan.new(operation_name)
end

#have_spans(n = anything) ⇒ HaveSpans

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`.

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

Examples:


# 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

Parameters:

  • n (Fixnum) (defaults to: anything)

    expected number of traced spans

Returns:

See Also:



65
66
67
# File 'lib/tracing/matchers.rb', line 65

def have_spans(n = anything)
  Tracing::Matchers::HaveSpans.new(n)
end

#have_tag(*args) ⇒ HaveTag Also known as: have_tags

The have_tag matcher tests that the span includes tags.

Examples:


# 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/)

Returns:

  • (HaveTag)


21
22
23
# File 'lib/tracing/matchers/span_matchers.rb', line 21

def have_tag(*args)
  Tracing::Matchers::Span::HaveTag.new(*args)
end

#have_traces(n = anything) ⇒ HaveTraces

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`.

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

Examples:


# 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

Parameters:

  • n (Fixnum) (defaults to: anything)

    expected number of distinct traces

Returns:

See Also:



35
36
37
# File 'lib/tracing/matchers.rb', line 35

def have_traces(n = anything)
  Tracing::Matchers::HaveTraces.new(n)
end