Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,27 @@
end
end

describe 'when enable_internal_instrumentation is true' do
let(:client) do
Faraday.new('http://example.com') do |builder|
builder.adapter(:test) do |stub|
stub.get('/success') { |_| [200, {}, 'OK'] }
end
end
end

it 'traces the request without untraced wrapper' do
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(enable_internal_instrumentation: true)

client.get('/success')

_(span.name).must_equal 'GET'
_(span.attributes['http.request.method']).must_equal 'GET'
_(span.attributes['http.response.status_code']).must_equal 200
end
end

describe 'url.template in span name' do
let(:client) do
Faraday.new('http://example.com') do |builder|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,26 @@
_(tracers).must_equal 1
end
end

describe 'when enable_internal_instrumentation is true' do
let(:client) do
Faraday.new('http://example.com') do |builder|
builder.adapter(:test) do |stub|
stub.get('/success') { |_| [200, {}, 'OK'] }
end
end
end

it 'traces the request without untraced wrapper' do
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(enable_internal_instrumentation: true)

client.get('/success')

_(span.name).must_equal 'HTTP GET'
_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.status_code']).must_equal 200
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@
end
end

describe 'when enable_internal_instrumentation is true' do
let(:client) do
Faraday.new('http://example.com') do |builder|
builder.adapter(:test) do |stub|
stub.get('/success') { |_| [200, {}, 'OK'] }
end
end
end

it 'traces the request without untraced wrapper' do
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(enable_internal_instrumentation: true)

client.get('/success')

_(span.name).must_equal 'GET'
_(span.attributes['http.request.method']).must_equal 'GET'
_(span.attributes['http.response.status_code']).must_equal 200
end
end

describe 'url.template in span name' do
let(:client) do
Faraday.new('http://example.com') do |builder|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,65 @@
let(:exporter) { EXPORTER }

before do
skip unless ENV['BUNDLE_GEMFILE'].include?('old')
skip unless ENV['BUNDLE_GEMFILE'].include?('stable')

ENV['OTEL_SEMCONV_STABILITY_OPT_IN'] = 'old'
instrumentation.install
exporter.reset
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install
end

after do
ENV.delete('OTEL_SEMCONV_STABILITY_OPT_IN')
instrumentation.instance_variable_set(:@installed, false)
end

it 'has #name' do
_(instrumentation.name).must_equal 'OpenTelemetry::Instrumentation::Faraday'
end

it 'has #version' do
_(instrumentation.version).wont_be_nil
_(instrumentation.version).wont_be_empty
end

describe 'present' do
it 'when faraday gem is installed' do
_(instrumentation.present?).must_equal true
end

it 'when Faraday is not defined' do
hide_const('Faraday')
_(instrumentation.present?).must_equal false
end
end

describe 'compatible' do
it 'when faraday version meets minimum' do
_(instrumentation.compatible?).must_equal true
end
end

describe '#install' do
it 'accepts empty arguments' do
instrumentation.instance_variable_set(:@installed, false)
_(instrumentation.install({})).must_equal true
end
end

describe 'tracing' do
before do
stub_request(:any, 'example.com')
let(:client) do
Faraday.new('http://example.com') do |builder|
builder.adapter(:test) do |stub|
stub.get('/') { [200, {}, 'OK'] }
end
end
end

it 'before request' do
_(exporter.finished_spans.size).must_equal 0
end

it 'after request' do
Faraday.new('http://example.com').get('/')
client.get('/')

_(exporter.finished_spans.size).must_equal 1
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
end
end

it 'returns "old" when OTEL_SEMCONV_STABILITY_OPT_IN is old' do
OpenTelemetry::TestHelpers.with_env('OTEL_SEMCONV_STABILITY_OPT_IN' => 'old') do
_(instrumentation.determine_semconv).must_equal('old')
end
end

it 'returns "stable" when OTEL_SEMCONV_STABILITY_OPT_IN is http' do
OpenTelemetry::TestHelpers.with_env('OTEL_SEMCONV_STABILITY_OPT_IN' => 'http') do
_(instrumentation.determine_semconv).must_equal('stable')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['http.url']).must_equal 'http://example.com'
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
Expand All @@ -72,6 +73,7 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.target']).must_equal '/failure'
_(span.attributes['http.url']).must_equal 'http://example.com'
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
Expand All @@ -92,6 +94,7 @@
_(span.attributes['http.scheme']).must_equal 'https'
_(span.attributes['http.status_code']).must_be_nil
_(span.attributes['http.target']).must_equal '/timeout'
_(span.attributes['http.url']).must_equal 'https://example.com'
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 443
_(span.status.code).must_equal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
before do
skip unless ENV['BUNDLE_GEMFILE'].include?('old')

ENV['OTEL_SEMCONV_STABILITY_OPT_IN'] = 'old'
exporter.reset
instrumentation.install({})
end

# Force re-install of instrumentation
after { instrumentation.instance_variable_set(:@installed, false) }
after do
ENV.delete('OTEL_SEMCONV_STABILITY_OPT_IN')
instrumentation.instance_variable_set(:@installed, false)
end

describe '#connect' do
it 'emits span on connect' do
Expand Down