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

Add rubocop to adapters #179

Merged
merged 4 commits into from
Jan 28, 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
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ GEM_INFO = {
require './lib/opentelemetry/exporters/jaeger/version.rb'
OpenTelemetry::Exporters::Jaeger::VERSION
}
},
"opentelemetry-adapters-faraday" => {
version_getter: ->() {
require './lib/opentelemetry/adapters/faraday/version.rb'
OpenTelemetry::Adapters::Faraday::VERSION
}
},
"opentelemetry-adapters-sinatra" => {
version_getter: ->() {
require './lib/opentelemetry/adapters/sinatra/version.rb'
OpenTelemetry::Adapters::Sinatra::VERSION
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions adapters/faraday/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AllCops:
TargetRubyVersion: '2.4.0'

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Max: 18
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Exclude:
- "lib/opentelemetry-adapters-faraday.rb"
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Style/ModuleFunction:
Enabled: false
Style/StringLiterals:
Exclude:
- gemfiles/**/*
22 changes: 14 additions & 8 deletions adapters/faraday/Appraisals
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
appraise "faraday-1.0" do
gem "faraday", "~> 1.0.0"
# frozen_string_literal: true

# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

appraise 'faraday-1.0' do
gem 'faraday', '~> 1.0.0'
end

appraise "faraday-0.17" do
gem "faraday", "0.17.0"
appraise 'faraday-0.17' do
gem 'faraday', '0.17.0'
end

appraise "faraday-0.16" do
gem "faraday", "0.16.2"
appraise 'faraday-0.16' do
gem 'faraday', '0.16.2'
end

appraise "faraday-0.13" do
gem "faraday", "0.13.1"
appraise 'faraday-0.13' do
gem 'faraday', '0.13.1'
end
18 changes: 16 additions & 2 deletions adapters/faraday/Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# frozen_string_literal: true

# Copyright 2019 OpenTelemetry Authors
# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yard'
require 'rubocop/rake_task'

RuboCop::RakeTask.new

Rake::TestTask.new :test do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
end

YARD::Rake::YardocTask.new do |t|
t.stats_options = ['--list-undoc']
end

if RUBY_ENGINE == 'truffleruby'
task default: %i[test]
else
task default: %i[test rubocop yard]
end
2 changes: 1 addition & 1 deletion adapters/faraday/example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source 'https://rubygems.org'

gem 'faraday'
gem 'opentelemetry-adapters-faraday', path: '../../../adapters/faraday'
gem 'opentelemetry-api', path: '../../../api'
gem 'opentelemetry-sdk', path: '../../../sdk'
gem 'opentelemetry-adapters-faraday', path: '../../../adapters/faraday'
6 changes: 6 additions & 0 deletions adapters/faraday/example/faraday.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# frozen_string_literal: true

# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'rubygems'
require 'bundler/setup'

Expand Down
1 change: 1 addition & 0 deletions adapters/faraday/lib/opentelemetry/adapters/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

module OpenTelemetry
module Adapters
# Contains the OpenTelemetry adapter for the Faraday gem
module Faraday
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
module OpenTelemetry
module Adapters
module Faraday
# The Adapter class contains logic to detect and install the Faraday
# instrumentation adapter
class Adapter < OpenTelemetry::Instrumentation::Adapter
install do |config|
require_dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ module OpenTelemetry
module Adapters
module Faraday
module Middlewares
# TracerMiddleware propagates context and instruments Faraday requests
# by way of its middlware system
class TracerMiddleware < ::Faraday::Middleware
def call(env)
return app.call(env) if disable_span_reporting?(env)

tracer.in_span(env.url.to_s,
attributes: { 'component' => 'http',
'http.method' => env.method,
'http.url' => env.url.to_s },
kind: :client) do |span|
attributes: { 'component' => 'http',
'http.method' => env.method,
'http.url' => env.url.to_s },
kind: :client) do |span|
propagate_context(span, env)

app.call(env).on_complete { |resp| trace_response(span, resp) }
Expand Down
3 changes: 3 additions & 0 deletions adapters/faraday/opentelemetry-adapters-faraday.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'faraday', '~> 0.17.0'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'opentelemetry-sdk', '~> 0.0'
spec.add_development_dependency 'rubocop', '~> 0.73.0'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.7.6'
spec.add_development_dependency 'yard', '~> 0.9'
spec.add_development_dependency 'yard-doctest', '~> 0.1.6'
end
4 changes: 4 additions & 0 deletions adapters/faraday/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inherit_from: ../.rubocop.yml

Metrics/BlockLength:
Enabled: false
27 changes: 27 additions & 0 deletions adapters/sinatra/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AllCops:
TargetRubyVersion: '2.4.0'

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Max: 18
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Naming/FileName:
Exclude:
- "lib/opentelemetry-adapters-sinatra.rb"
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Style/ModuleFunction:
Enabled: false
Style/StringLiterals:
Exclude:
- gemfiles/**/*
14 changes: 10 additions & 4 deletions adapters/sinatra/Appraisals
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
appraise "sinatra-2.0" do
gem "sinatra", "2.0.7"
# frozen_string_literal: true

# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

appraise 'sinatra-2.0' do
gem 'sinatra', '2.0.7'
end

appraise "sinatra-1.4" do
gem "sinatra", "1.4.8"
appraise 'sinatra-1.4' do
gem 'sinatra', '1.4.8'
end
18 changes: 16 additions & 2 deletions adapters/sinatra/Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# frozen_string_literal: true

# Copyright 2019 OpenTelemetry Authors
# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yard'
require 'rubocop/rake_task'

RuboCop::RakeTask.new

Rake::TestTask.new :test do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
end

YARD::Rake::YardocTask.new do |t|
t.stats_options = ['--list-undoc']
end

if RUBY_ENGINE == 'truffleruby'
task default: %i[test]
else
task default: %i[test rubocop yard]
end
8 changes: 6 additions & 2 deletions adapters/sinatra/example/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# frozen_string_literal: true

# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

source 'https://rubygems.org'

gem 'sinatra'
gem 'opentelemetry-adapters-sinatra', path: '../../../adapters/sinatra'
gem 'opentelemetry-api', path: '../../../api'
gem 'opentelemetry-sdk', path: '../../../sdk'
gem 'opentelemetry-adapters-sinatra', path: '../../../adapters/sinatra'
gem 'sinatra'
10 changes: 9 additions & 1 deletion adapters/sinatra/example/server.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'rubygems'
require 'bundler/setup'

Expand All @@ -8,6 +15,7 @@
c.use 'OpenTelemetry::Adapters::Sinatra'
end

# Example application for the Sinatra instrumentation adapter
class App < Sinatra::Base
set :bind, '0.0.0.0'
set :show_exceptions, false
Expand All @@ -29,5 +37,5 @@ class App < Sinatra::Base
'Thing 1'
end

run! if app_file == $0
run! if app_file == $PROGRAM_NAME
end
6 changes: 6 additions & 0 deletions adapters/sinatra/example/sinatra.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# frozen_string_literal: true

# Copyright 2020 OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'net/http'

response = Net::HTTP.get('0.0.0.0', '/example', '4567')
Expand Down
1 change: 1 addition & 0 deletions adapters/sinatra/lib/opentelemetry/adapters/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

module OpenTelemetry
module Adapters
# Contains the OpenTelemetry instrumentation adapter for the Sinatra gem
module Sinatra
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
module OpenTelemetry
module Adapters
module Sinatra
# The Adapter class contains logic to detect and install the Sinatra
# instrumentation adapter
class Adapter < OpenTelemetry::Instrumentation::Adapter
install do |_|
::Sinatra::Base.register Extensions::TracerExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module OpenTelemetry
module Adapters
module Sinatra
module Extensions
# Sinatra extension that installs TracerMiddleware and provides
# tracing for template rendering
module TracerExtension
# Sinatra hook after extension is registered
def self.registered(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module OpenTelemetry
module Adapters
module Sinatra
module Middlewares
# Middleware to trace Sinatra requests
class TracerMiddleware
def initialize(app)
@app = app
Expand Down
4 changes: 4 additions & 0 deletions adapters/sinatra/opentelemetry-adapters-sinatra.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'opentelemetry-sdk', '~> 0.0'
spec.add_development_dependency 'rack-test', '~> 1.1.0'
spec.add_development_dependency 'rubocop', '~> 0.73.0'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'sinatra', '~> 2.0.7'
spec.add_development_dependency 'webmock', '~> 3.7.6'
spec.add_development_dependency 'yard', '~> 0.9'
spec.add_development_dependency 'yard-doctest', '~> 0.1.6'
end
4 changes: 4 additions & 0 deletions adapters/sinatra/test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inherit_from: ../.rubocop.yml

Metrics/BlockLength:
Enabled: false
Loading