Tracing::Matchers

The gem exposes RSpec-compatible convenient one-liners, matchers, which you can use to test OpenTracing instrumentations, without having to use production OpenTracing Tracer e.g. Jaeger. It's expected that the gem will be used together with test-tracer - an OpenTracing compatible test Tracer implementation.

Usage

High-level test examples.

describe"traced code"docontext"when we expect no traces"doit"does not have any traces"doexpect(tracer).not_tohave_tracesendendcontext"when we expect traces to be present"doit"does have some traces started"doexpect(tracer).tohave_tracesendendcontext"when we expect exactly N traces"doit"has N traces recorded"doexpect(tracer).tohave_traces(N)endendend

describe"traced code"docontext"when we expect no spans"doit"does not have any spans"doexpect(tracer).not_tohave_spansendendcontext"when we expect spans to be present"doit"does have some spans started"doexpect(tracer).tohave_spansendendcontext"when we expect exactly N spans"doit"has N spans recorded"doexpect(tracer).tohave_spans(N)endendend

Span-level test examples.

describe"traced code"docontext"when a new span was started"doit"is in progress"doexpect(tracer).tohave_span.in_progressendit"does have the proper name"doexpect(tracer).tohave_span("operation name")endit"does include standard OT tags"doexpect(tracer).tohave_span.with_tags('component'=>'ActiveRecord')expect(span).tohave_tag('component','ActiveRecord')endit"does include a baggage item"doexpect(tracer).tohave_span.with_baggage('user_id','1')expect(span).tohave_baggage('user_id','1')endit"does not have any log entries"doexpect(tracer).not_tohave_span.with_logsendendcontext"when an event was logged"doit"does have some log entries recorded"doexpect(tracer).tohave_span.with_logsexpect(span).tohave_logendit"includes all the event attributes"doexpect(tracer).tohave_span.with_log(event:"exceptional message",severity:Logger::ERROR)expect(span).tohave_log(event:"exceptional message",severity:Logger::ERROR)endendcontext"when a span was finished"doit"is not in progress"doexpect(tracer).tohave_span.finishedendendend

Span context-level test examples.

describe"traced code"docontext"when a new span was started as child"doit"has a prent"doexpect(tracer).tohave_span("child span").child_of("root span")expect(span).tobe_child_of("root span")endendend

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.