OpenTelemetry RSpec Instrumentation
The RSpec instrumentation is a community-maintained instrumentation for the RSpec BDD testing framework.
How do I get started?
Install the gem using:
gem install opentelemetry-instrumentation-rspec
Or, if you use bundler, include opentelemetry-instrumentation-rspec
in your Gemfile
.
Usage
To use the instrumentation, call use
with the name of the instrumentation:
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::RSpec'
end
Alternatively, you can add it directly to RSpec as a customer formatter:
RSpec.configure do |config|
config.formatter = OpenTelemetry::Instrumentation::RSpec::Formatter
end
Using multiple tracer providers
By default the instrumentation will use the global tracer provider.
If you want the instrumentation to use something other than the global tracer provider you can configure the instrumentation with a custom tracer provider using the OpenTelemetry::Instrumentation::RSpec::Formatter
constructor:
exporter = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(exporter)
tracer_provider = OpenTelemetry::SDK::Trace::TracerProvider.new
tracer_provider.add_span_processor(span_processor)
RSpec.configure do |config|
config.formatter = OpenTelemetry::Instrumentation::RSpec::Formatter.new(config.output_stream, tracer_provider)
end
If you need to test trace behaviour in your specs then you should be able to use a custom tracer provider and the instrumentation's output should not interfere with your specs.
Sampling
To avoid spans from being dropped, which will mean you lose insight into your specs, you may want to set sampling to 'ALWAYS_ON'. The easiest way to do this is by setting the OTEL_TRACES_SAMPLER
environment variable to always_on
.
Examples
Example usage can be seen in the /example
directory here
How can I get involved?
The opentelemetry-instrumentation-rspec
gem source is on github, along with related gems including opentelemetry-api
and opentelemetry-sdk
.
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our GitHub Discussions, Slack Channel or attending our weekly meeting. See the meeting calendar for dates and times. For more information on this and other language SIGs, see the OpenTelemetry community page.
License
The opentelemetry-instrumentation-rspec
gem is distributed under the Apache 2.0 license. See LICENSE for more information.