From 9b40fae3c1efc72c82415891d2d3649a8f29366d Mon Sep 17 00:00:00 2001 From: James Behr Date: Tue, 25 May 2021 12:55:02 +0200 Subject: [PATCH 1/3] Refactor modules into their own gems --- Gemfile | 6 +++++- dog_collar-circuitry.gemspec | 39 ++++++++++++++++++++++++++++++++++++ dog_collar-core.gemspec | 39 ++++++++++++++++++++++++++++++++++++ dog_collar-ethon.gemspec | 39 ++++++++++++++++++++++++++++++++++++ dog_collar-rails.gemspec | 39 ++++++++++++++++++++++++++++++++++++ dog_collar-sidekiq.gemspec | 39 ++++++++++++++++++++++++++++++++++++ dog_collar.gemspec | 24 ++++++++++++---------- lib/dog_collar.rb | 17 +++++----------- lib/dog_collar/circuitry.rb | 3 +++ lib/dog_collar/core.rb | 9 +++++++++ lib/dog_collar/ethon.rb | 3 +++ lib/dog_collar/rails.rb | 3 +++ lib/dog_collar/sidekiq.rb | 3 +++ 13 files changed, 239 insertions(+), 24 deletions(-) create mode 100644 dog_collar-circuitry.gemspec create mode 100644 dog_collar-core.gemspec create mode 100644 dog_collar-ethon.gemspec create mode 100644 dog_collar-rails.gemspec create mode 100644 dog_collar-sidekiq.gemspec create mode 100644 lib/dog_collar/circuitry.rb create mode 100644 lib/dog_collar/core.rb create mode 100644 lib/dog_collar/ethon.rb create mode 100644 lib/dog_collar/rails.rb create mode 100644 lib/dog_collar/sidekiq.rb diff --git a/Gemfile b/Gemfile index 562c607..cedce44 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,11 @@ source 'https://rubygems.org' -gemspec +gemspec name: 'dog_collar' + +Dir['dog_collar-*.gemspec'].each do |gemspec| + gemspec name: File.basename(gemspec, '.gemspec') +end group :development, :test do gem 'getsmarter-rubocop-style', git: 'https://github.com/getsmarter/getsmarter-rubocop-style' diff --git a/dog_collar-circuitry.gemspec b/dog_collar-circuitry.gemspec new file mode 100644 index 0000000..0f2b6b0 --- /dev/null +++ b/dog_collar-circuitry.gemspec @@ -0,0 +1,39 @@ +# coding: utf-8 +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'dog_collar/version' + +extension_files = [] +Dir['dog_collar-*.gemspec'].each do |gemspec| + next if gemspec == __FILE__ + + name = File.basename(gemspec, '.gemspec').delete_prefix('dog_collar-') + extension_files << "lib/dog_collar/#{name}.rb" + + Dir["lib/dog_collar/contrib/#{name}/**/*.rb"].each do |file| + extension_files << file + end +end + +Gem::Specification.new do |spec| + spec.name = 'dog_collar-circuitry' + spec.version = DogCollar::VERSION::STRING + spec.required_ruby_version = ">= #{DogCollar::VERSION::MINIMUM_RUBY_VERSION}" + spec.required_rubygems_version = '>= 2.0.0' + spec.authors = ['James Behr'] + spec.email = ['jbehr@2u.com'] + spec.summary = 'DogCollar Circuitry instrumentation' + spec.homepage = 'https://github.com/get-smarter/dog_collar' + + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + + spec.files = `git ls-files -- lib/dog_collar`.split("\n") + spec.files -= extension_files + spec.test_files = `git ls-files -- spec`.split("\n") + spec.require_paths = ['lib'] + + spec.add_dependency 'amazing_print' + spec.add_dependency 'ddtrace', '~> 0.37.0' +end diff --git a/dog_collar-core.gemspec b/dog_collar-core.gemspec new file mode 100644 index 0000000..fc95970 --- /dev/null +++ b/dog_collar-core.gemspec @@ -0,0 +1,39 @@ +# coding: utf-8 +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'dog_collar/version' + +extension_files = [] +Dir['dog_collar-*.gemspec'].each do |gemspec| + next if gemspec == __FILE__ + + name = File.basename(gemspec, '.gemspec').delete_prefix('dog_collar-') + extension_files << "lib/dog_collar/#{name}.rb" + + Dir["lib/dog_collar/contrib/#{name}/**/*.rb"].each do |file| + extension_files << file + end +end + +Gem::Specification.new do |spec| + spec.name = 'dog_collar-core' + spec.version = DogCollar::VERSION::STRING + spec.required_ruby_version = ">= #{DogCollar::VERSION::MINIMUM_RUBY_VERSION}" + spec.required_rubygems_version = '>= 2.0.0' + spec.authors = ['James Behr'] + spec.email = ['jbehr@2u.com'] + spec.summary = 'DogCollar core logging functionality' + spec.homepage = 'https://github.com/get-smarter/dog_collar' + + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + + spec.files = `git ls-files -- lib/dog_collar`.split("\n") + spec.files -= extension_files + spec.test_files = `git ls-files -- spec`.split("\n") + spec.require_paths = ['lib'] + + spec.add_dependency 'amazing_print' + spec.add_dependency 'ddtrace', '~> 0.37.0' +end diff --git a/dog_collar-ethon.gemspec b/dog_collar-ethon.gemspec new file mode 100644 index 0000000..39a83ed --- /dev/null +++ b/dog_collar-ethon.gemspec @@ -0,0 +1,39 @@ +# coding: utf-8 +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'dog_collar/version' + +extension_files = [] +Dir['dog_collar-*.gemspec'].each do |gemspec| + next if gemspec == __FILE__ + + name = File.basename(gemspec, '.gemspec').delete_prefix('dog_collar-') + extension_files << "lib/dog_collar/#{name}.rb" + + Dir["lib/dog_collar/contrib/#{name}/**/*.rb"].each do |file| + extension_files << file + end +end + +Gem::Specification.new do |spec| + spec.name = 'dog_collar-ethon' + spec.version = DogCollar::VERSION::STRING + spec.required_ruby_version = ">= #{DogCollar::VERSION::MINIMUM_RUBY_VERSION}" + spec.required_rubygems_version = '>= 2.0.0' + spec.authors = ['James Behr'] + spec.email = ['jbehr@2u.com'] + spec.summary = 'DogCollar Ethon instrumentation' + spec.homepage = 'https://github.com/get-smarter/dog_collar' + + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + + spec.files = `git ls-files -- lib/dog_collar`.split("\n") + spec.files -= extension_files + spec.test_files = `git ls-files -- spec`.split("\n") + spec.require_paths = ['lib'] + + spec.add_dependency 'amazing_print' + spec.add_dependency 'ddtrace', '~> 0.37.0' +end diff --git a/dog_collar-rails.gemspec b/dog_collar-rails.gemspec new file mode 100644 index 0000000..dcdffce --- /dev/null +++ b/dog_collar-rails.gemspec @@ -0,0 +1,39 @@ +# coding: utf-8 +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'dog_collar/version' + +extension_files = [] +Dir['dog_collar-*.gemspec'].each do |gemspec| + next if gemspec == __FILE__ + + name = File.basename(gemspec, '.gemspec').delete_prefix('dog_collar-') + extension_files << "lib/dog_collar/#{name}.rb" + + Dir["lib/dog_collar/contrib/#{name}/**/*.rb"].each do |file| + extension_files << file + end +end + +Gem::Specification.new do |spec| + spec.name = 'dog_collar-rails' + spec.version = DogCollar::VERSION::STRING + spec.required_ruby_version = ">= #{DogCollar::VERSION::MINIMUM_RUBY_VERSION}" + spec.required_rubygems_version = '>= 2.0.0' + spec.authors = ['James Behr'] + spec.email = ['jbehr@2u.com'] + spec.summary = 'DogCollar Rails instrumentation' + spec.homepage = 'https://github.com/get-smarter/dog_collar' + + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + + spec.files = `git ls-files -- lib/dog_collar/contrib/rails`.split("\n") + spec.files -= extension_files + spec.test_files = `git ls-files -- spec`.split("\n") + spec.require_paths = ['lib'] + + spec.add_dependency 'dog_collar-core', DogCollar::VERSION::STRING + spec.add_dependency 'lograge' +end diff --git a/dog_collar-sidekiq.gemspec b/dog_collar-sidekiq.gemspec new file mode 100644 index 0000000..39f3840 --- /dev/null +++ b/dog_collar-sidekiq.gemspec @@ -0,0 +1,39 @@ +# coding: utf-8 +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'dog_collar/version' + +extension_files = [] +Dir['dog_collar-*.gemspec'].each do |gemspec| + next if gemspec == __FILE__ + + name = File.basename(gemspec, '.gemspec').delete_prefix('dog_collar-') + extension_files << "lib/dog_collar/#{name}.rb" + + Dir["lib/dog_collar/contrib/#{name}/**/*.rb"].each do |file| + extension_files << file + end +end + +Gem::Specification.new do |spec| + spec.name = 'dog_collar-sidekiq' + spec.version = DogCollar::VERSION::STRING + spec.required_ruby_version = ">= #{DogCollar::VERSION::MINIMUM_RUBY_VERSION}" + spec.required_rubygems_version = '>= 2.0.0' + spec.authors = ['James Behr'] + spec.email = ['jbehr@2u.com'] + spec.summary = 'DogCollar Sidekiq instrumentation' + spec.homepage = 'https://github.com/get-smarter/dog_collar' + + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + + spec.files = `git ls-files -- lib/dog_collar`.split("\n") + spec.files -= extension_files + spec.test_files = `git ls-files -- spec`.split("\n") + spec.require_paths = ['lib'] + + spec.add_dependency 'amazing_print' + spec.add_dependency 'ddtrace', '~> 0.37.0' +end diff --git a/dog_collar.gemspec b/dog_collar.gemspec index 70850a4..8ba12ef 100644 --- a/dog_collar.gemspec +++ b/dog_collar.gemspec @@ -6,16 +6,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'dog_collar/version' Gem::Specification.new do |spec| - spec.name = 'dog_collar' - spec.version = DogCollar::VERSION::STRING + spec.name = 'dog_collar' + spec.version = DogCollar::VERSION::STRING spec.required_ruby_version = ">= #{DogCollar::VERSION::MINIMUM_RUBY_VERSION}" spec.required_rubygems_version = '>= 2.0.0' - spec.authors = ['James Behr'] - spec.email = ['jbehr@2u.com'] + spec.authors = ['James Behr'] + spec.email = ['jbehr@2u.com'] - spec.summary = 'Datadog wrapper' + spec.summary = 'Zero-configuration structured logging and instrumentation' spec.description = <<-DESCRIPTION.gsub(/^[\s]+/, '') - Wrapper around ddtrace + DogCollar wraps ddtrace-rb with sensible defaults for instrumentation, as + well as including a structured logger that automatically relates logs to + the active trace. DESCRIPTION spec.homepage = 'https://github.com/get-smarter/dog_collar' @@ -24,13 +26,13 @@ Gem::Specification.new do |spec| spec.metadata['allowed_push_host'] = 'https://rubygems.org' - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = ['lib/dog_collar.rb'] spec.require_paths = ['lib'] - # Optional extensions - spec.add_dependency 'amazing_print' - spec.add_dependency 'ddtrace', '~> 0.37.0' - spec.add_dependency 'lograge' + Dir['dog_collar-*.gemspec'].each do |gemspec| + extension = File.basename(gemspec, '.gemspec') + spec.add_dependency extension, DogCollar::VERSION::STRING + end # Development dependencies spec.add_development_dependency 'appraisal' diff --git a/lib/dog_collar.rb b/lib/dog_collar.rb index 044f5ca..f477121 100644 --- a/lib/dog_collar.rb +++ b/lib/dog_collar.rb @@ -1,14 +1,7 @@ # frozen_string_literal: true -require 'dog_collar/configuration' -require 'dog_collar/logging/logger' -require 'dog_collar/logging/instrumented_logger' - -module DogCollar - extend Configuration -end - -require 'dog_collar/contrib/sidekiq/integration' -require 'dog_collar/contrib/rails/integration' -require 'dog_collar/contrib/circuitry/integration' -require 'dog_collar/contrib/ethon/integration' +require 'dog_collar/core' +require 'dog_collar/circuitry' +require 'dog_collar/ethon' +require 'dog_collar/rails' +require 'dog_collar/sidekiq' diff --git a/lib/dog_collar/circuitry.rb b/lib/dog_collar/circuitry.rb new file mode 100644 index 0000000..cc02a54 --- /dev/null +++ b/lib/dog_collar/circuitry.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'dog_collar/contrib/circuitry/integration' diff --git a/lib/dog_collar/core.rb b/lib/dog_collar/core.rb new file mode 100644 index 0000000..5bdd879 --- /dev/null +++ b/lib/dog_collar/core.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'dog_collar/configuration' +require 'dog_collar/logging/logger' +require 'dog_collar/logging/instrumented_logger' + +module DogCollar + extend Configuration +end diff --git a/lib/dog_collar/ethon.rb b/lib/dog_collar/ethon.rb new file mode 100644 index 0000000..a86a0a5 --- /dev/null +++ b/lib/dog_collar/ethon.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'dog_collar/contrib/ethon/integration' diff --git a/lib/dog_collar/rails.rb b/lib/dog_collar/rails.rb new file mode 100644 index 0000000..dff064f --- /dev/null +++ b/lib/dog_collar/rails.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'dog_collar/contrib/rails/integration' diff --git a/lib/dog_collar/sidekiq.rb b/lib/dog_collar/sidekiq.rb new file mode 100644 index 0000000..e63d500 --- /dev/null +++ b/lib/dog_collar/sidekiq.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'dog_collar/contrib/sidekiq/integration' From e3e626ea035891de66e730f2e162a121c8046662 Mon Sep 17 00:00:00 2001 From: James Behr Date: Tue, 25 May 2021 13:03:41 +0200 Subject: [PATCH 2/3] Require ddtrace --- lib/dog_collar/core.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dog_collar/core.rb b/lib/dog_collar/core.rb index 5bdd879..f74b208 100644 --- a/lib/dog_collar/core.rb +++ b/lib/dog_collar/core.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'ddtrace' require 'dog_collar/configuration' require 'dog_collar/logging/logger' require 'dog_collar/logging/instrumented_logger' From 18700aa46efb71934565cd3c298424a9ae02d3e0 Mon Sep 17 00:00:00 2001 From: James Behr Date: Tue, 25 May 2021 13:06:45 +0200 Subject: [PATCH 3/3] Check integration exists --- lib/dog_collar/settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dog_collar/settings.rb b/lib/dog_collar/settings.rb index fa77945..63a81a8 100644 --- a/lib/dog_collar/settings.rb +++ b/lib/dog_collar/settings.rb @@ -25,7 +25,7 @@ def logger def autoload! AUTOLOADS.each do |name| integration = registry[name] - use(name) if integration.class.patchable? + use(name) if !integration.nil? && integration.class.patchable? end end