diff --git a/instrumentation/faraday/.github-ci.yml b/instrumentation/faraday/.github-ci.yml deleted file mode 100644 index df25962cb9..0000000000 --- a/instrumentation/faraday/.github-ci.yml +++ /dev/null @@ -1,2 +0,0 @@ -env: - minimum_coverage: 65 diff --git a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware_test.rb b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware_test.rb index a8afa068b4..97aed86bc7 100644 --- a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware_test.rb +++ b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware_test.rb @@ -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| diff --git a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware_test.rb b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware_test.rb index c4855ae917..ffca5ea07f 100644 --- a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware_test.rb +++ b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware_test.rb @@ -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 diff --git a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware_test.rb b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware_test.rb index a240a60fb4..78df48e441 100644 --- a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware_test.rb +++ b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware_test.rb @@ -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| diff --git a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday_test.rb b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday_test.rb index f6b4dda003..cc1270c5a1 100644 --- a/instrumentation/faraday/test/opentelemetry/instrumentation/faraday_test.rb +++ b/instrumentation/faraday/test/opentelemetry/instrumentation/faraday_test.rb @@ -11,20 +11,57 @@ 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 + assert instrumentation.present? + end + + it 'when Faraday is not defined' do + hide_const('Faraday') + refute instrumentation.present? + 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 @@ -32,7 +69,7 @@ end it 'after request' do - Faraday.new('http://example.com').get('/') + client.get('/') _(exporter.finished_spans.size).must_equal 1 end