diff --git a/adapters/faraday/example/Gemfile b/adapters/faraday/example/Gemfile index 1c162edde..e88bd8671 100644 --- a/adapters/faraday/example/Gemfile +++ b/adapters/faraday/example/Gemfile @@ -5,3 +5,4 @@ source 'https://rubygems.org' gem 'faraday' gem 'opentelemetry-api', path: '../../../api' gem 'opentelemetry-sdk', path: '../../../sdk' +gem 'opentelemetry-adapters-faraday', path: '../../../adapters/faraday' diff --git a/adapters/faraday/example/faraday.rb b/adapters/faraday/example/faraday.rb index c278c65a5..a9da19b75 100644 --- a/adapters/faraday/example/faraday.rb +++ b/adapters/faraday/example/faraday.rb @@ -1,19 +1,11 @@ require 'rubygems' require 'bundler/setup' -require 'faraday' -require 'opentelemetry/sdk' -require_relative '../lib/opentelemetry/adapters/faraday' +Bundler.require -# Set preferred tracer implementation: -SDK = OpenTelemetry::SDK - -factory = OpenTelemetry.tracer_factory = SDK::Trace::TracerFactory.new -factory.add_span_processor( - SDK::Trace::Export::SimpleSpanProcessor.new( - SDK::Trace::Export::ConsoleSpanExporter.new - ) -) +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Adapters::Faraday' +end # Demonstrate disabling span reporting: # @@ -25,7 +17,5 @@ # end # OpenTelemetry::Adapters::Faraday.install(tracer_middleware: NoOp) -OpenTelemetry::Adapters::Faraday.install - conn = Faraday.new('http://example.com') conn.get '/' diff --git a/adapters/faraday/lib/opentelemetry/adapters/faraday/adapter.rb b/adapters/faraday/lib/opentelemetry/adapters/faraday/adapter.rb index 6a7643908..e8b2726ad 100644 --- a/adapters/faraday/lib/opentelemetry/adapters/faraday/adapter.rb +++ b/adapters/faraday/lib/opentelemetry/adapters/faraday/adapter.rb @@ -16,7 +16,7 @@ class Adapter < OpenTelemetry::Instrumentation::Adapter end present do - Gem.loaded_specs.include?('faraday') + defined?(::Faraday) end private diff --git a/adapters/faraday/test/test_helper.rb b/adapters/faraday/test/test_helper.rb index 347cc5d90..0dadb0644 100644 --- a/adapters/faraday/test/test_helper.rb +++ b/adapters/faraday/test/test_helper.rb @@ -12,11 +12,9 @@ require 'webmock/minitest' # global opentelemetry-sdk setup: -sdk = OpenTelemetry::SDK -exporter = sdk::Trace::Export::InMemorySpanExporter.new -span_processor = sdk::Trace::Export::SimpleSpanProcessor.new(exporter) -OpenTelemetry.tracer_factory = sdk::Trace::TracerFactory.new.tap do |factory| - factory.add_span_processor(span_processor) -end +EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new +span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER) -EXPORTER = exporter \ No newline at end of file +OpenTelemetry::SDK.configure do |c| + c.add_span_processor span_processor +end diff --git a/adapters/sinatra/example/Gemfile b/adapters/sinatra/example/Gemfile index 543be5a98..8d5dcc1dc 100644 --- a/adapters/sinatra/example/Gemfile +++ b/adapters/sinatra/example/Gemfile @@ -5,3 +5,4 @@ source 'https://rubygems.org' gem 'sinatra' gem 'opentelemetry-api', path: '../../../api' gem 'opentelemetry-sdk', path: '../../../sdk' +gem 'opentelemetry-adapters-sinatra', path: '../../../adapters/sinatra' diff --git a/adapters/sinatra/example/server.rb b/adapters/sinatra/example/server.rb index 11b0bcb60..cd3f95ec5 100755 --- a/adapters/sinatra/example/server.rb +++ b/adapters/sinatra/example/server.rb @@ -2,21 +2,11 @@ require 'rubygems' require 'bundler/setup' -require 'sinatra/base' -require 'opentelemetry/sdk' -require_relative '../lib/opentelemetry/adapters/sinatra' +Bundler.require -# Set preferred tracer implementation: -SDK = OpenTelemetry::SDK - -factory = OpenTelemetry.tracer_factory = SDK::Trace::TracerFactory.new -factory.add_span_processor( - SDK::Trace::Export::SimpleSpanProcessor.new( - SDK::Trace::Export::ConsoleSpanExporter.new - ) -) - -OpenTelemetry::Adapters::Sinatra.install +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Adapters::Sinatra' +end class App < Sinatra::Base set :bind, '0.0.0.0' diff --git a/adapters/sinatra/lib/opentelemetry/adapters/sinatra/adapter.rb b/adapters/sinatra/lib/opentelemetry/adapters/sinatra/adapter.rb index b17cfc413..f93e05606 100644 --- a/adapters/sinatra/lib/opentelemetry/adapters/sinatra/adapter.rb +++ b/adapters/sinatra/lib/opentelemetry/adapters/sinatra/adapter.rb @@ -15,7 +15,7 @@ class Adapter < OpenTelemetry::Instrumentation::Adapter end present do - Gem.loaded_specs.include?("sinatra") + defined?(::Sinatra) end end end diff --git a/adapters/sinatra/test/test_helper.rb b/adapters/sinatra/test/test_helper.rb index 80d365eb7..91208e52f 100644 --- a/adapters/sinatra/test/test_helper.rb +++ b/adapters/sinatra/test/test_helper.rb @@ -12,11 +12,9 @@ require 'rack/test' # global opentelemetry-sdk setup: -sdk = OpenTelemetry::SDK -exporter = sdk::Trace::Export::InMemorySpanExporter.new -span_processor = sdk::Trace::Export::SimpleSpanProcessor.new(exporter) -OpenTelemetry.tracer_factory = sdk::Trace::TracerFactory.new.tap do |factory| - factory.add_span_processor(span_processor) -end +EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new +span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(EXPORTER) -EXPORTER = exporter +OpenTelemetry::SDK.configure do |c| + c.add_span_processor span_processor +end diff --git a/api/lib/opentelemetry/instrumentation/adapter.rb b/api/lib/opentelemetry/instrumentation/adapter.rb index 584e9897d..a422e5cd4 100644 --- a/api/lib/opentelemetry/instrumentation/adapter.rb +++ b/api/lib/opentelemetry/instrumentation/adapter.rb @@ -27,7 +27,7 @@ module Instrumentation # # # determine if the target library is present # present do - # Gem.loaded_specs.key?('sinatra') + # defined?(::Sinatra) # end # # # if the target library is present, is it compatible?