Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adapter examples and simplify setup #177

Merged
merged 4 commits into from
Jan 27, 2020
Merged
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
1 change: 1 addition & 0 deletions adapters/faraday/example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
18 changes: 4 additions & 14 deletions adapters/faraday/example/faraday.rb
Original file line number Diff line number Diff line change
@@ -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:
#
Expand All @@ -25,7 +17,5 @@
# end
# OpenTelemetry::Adapters::Faraday.install(tracer_middleware: NoOp)

OpenTelemetry::Adapters::Faraday.install

conn = Faraday.new('http://example.com')
conn.get '/'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Adapter < OpenTelemetry::Instrumentation::Adapter
end

present do
Gem.loaded_specs.include?('faraday')
defined?(::Faraday)
end

private
Expand Down
12 changes: 5 additions & 7 deletions adapters/faraday/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
OpenTelemetry::SDK.configure do |c|
c.add_span_processor span_processor
end
1 change: 1 addition & 0 deletions adapters/sinatra/example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
18 changes: 4 additions & 14 deletions adapters/sinatra/example/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Adapter < OpenTelemetry::Instrumentation::Adapter
end

present do
Gem.loaded_specs.include?("sinatra")
defined?(::Sinatra)
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions adapters/sinatra/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion api/lib/opentelemetry/instrumentation/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down