From 2251856046c7609589d0be5c3b64727a5848a7e5 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Tue, 1 Aug 2023 11:20:32 -0700 Subject: [PATCH 1/4] Register the OpenSearch contrib integration Otherwise, attempting to use the integration gives the following error: `/Users/segiddins/.gem/ruby/3.2.2/gems/ddtrace-1.13.0/lib/datadog/tracing/contrib/extensions.rb:210:in `fetch_integration': 'opensearch' is not a valid integration. (Datadog::Tracing::Contrib::Extensions::Configuration::Settings::InvalidIntegrationError)` --- lib/datadog/tracing/contrib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/datadog/tracing/contrib.rb b/lib/datadog/tracing/contrib.rb index b03913c8abb..92ca64b5ea5 100644 --- a/lib/datadog/tracing/contrib.rb +++ b/lib/datadog/tracing/contrib.rb @@ -58,6 +58,7 @@ module Contrib require_relative 'contrib/lograge/integration' require_relative 'contrib/mongodb/integration' require_relative 'contrib/mysql2/integration' +require_relative 'contrib/opensearch/integration' require_relative 'contrib/pg/integration' require_relative 'contrib/presto/integration' require_relative 'contrib/qless/integration' From c13d5ab6f638c1ae8ddb331b58d4a28237afd93d Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 4 Aug 2023 16:59:32 +0200 Subject: [PATCH 2/4] Add spec for loading integration into memory --- spec/datadog/tracing/contrib_spec.rb | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 spec/datadog/tracing/contrib_spec.rb diff --git a/spec/datadog/tracing/contrib_spec.rb b/spec/datadog/tracing/contrib_spec.rb new file mode 100644 index 00000000000..a807f64c519 --- /dev/null +++ b/spec/datadog/tracing/contrib_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +RSpec.describe Datadog::Tracing::Contrib do + root = Gem::Specification.find_by_name('ddtrace').gem_dir + + # Our module names are camelized directory name with some exceptions + mapping = { + 'action_cable' => 'ActionCable', + 'action_mailer' => 'ActionMailer', + 'action_pack' => 'ActionPack', + 'action_view' => 'ActionView', + 'active_job' => 'ActiveJob', + 'active_model_serializers' => 'ActiveModelSerializers', + 'active_record' => 'ActiveRecord', + 'active_support' => 'ActiveSupport', + 'aws' => 'Aws', + 'concurrent_ruby' => 'ConcurrentRuby', + 'dalli' => 'Dalli', + 'delayed_job' => 'DelayedJob', + 'elasticsearch' => 'Elasticsearch', + 'ethon' => 'Ethon', + 'excon' => 'Excon', + 'faraday' => 'Faraday', + 'grape' => 'Grape', + 'graphql' => 'GraphQL', # exception + 'grpc' => 'GRPC', # exception + 'hanami' => 'Hanami', + 'http' => 'HTTP', # exception + 'httpclient' => 'Httpclient', + 'httprb' => 'Httprb', + 'kafka' => 'Kafka', + 'lograge' => 'Lograge', + 'mongodb' => 'MongoDB', # exception + 'mysql2' => 'Mysql2', + 'opensearch' => 'OpenSearch', # exception + 'pg' => 'Pg', + 'presto' => 'Presto', + 'qless' => 'Qless', + 'que' => 'Que', + 'racecar' => 'Racecar', + 'rack' => 'Rack', + 'rails' => 'Rails', + 'rake' => 'Rake', + 'redis' => 'Redis', + 'resque' => 'Resque', + 'rest_client' => 'RestClient', + 'roda' => 'Roda', + 'semantic_logger' => 'SemanticLogger', + 'sequel' => 'Sequel', + 'shoryuken' => 'Shoryuken', + 'sidekiq' => 'Sidekiq', + 'sinatra' => 'Sinatra', + 'sneakers' => 'Sneakers', + 'stripe' => 'Stripe', + 'sucker_punch' => 'SuckerPunch' + } + + Dir.chdir(root) do + Dir.glob("*/integration.rb", base: "lib/datadog/tracing/contrib").each do |path| + directory = File.dirname path + ruby_module = mapping.fetch(directory) + + it "ensures integration `#{ruby_module}` at #{path} is registered" do + expect { Object.const_get "::Datadog::Tracing::Contrib::#{ruby_module}" }.not_to raise_error + end + end + end +end From 5820f0b6667a95608bf2f70c36d0b7a037c1f14e Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 4 Aug 2023 21:28:17 +0200 Subject: [PATCH 3/4] Fix spec for old rubies which does not support `base:` --- spec/datadog/tracing/contrib_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/datadog/tracing/contrib_spec.rb b/spec/datadog/tracing/contrib_spec.rb index a807f64c519..c48557b3814 100644 --- a/spec/datadog/tracing/contrib_spec.rb +++ b/spec/datadog/tracing/contrib_spec.rb @@ -55,12 +55,12 @@ 'sucker_punch' => 'SuckerPunch' } - Dir.chdir(root) do - Dir.glob("*/integration.rb", base: "lib/datadog/tracing/contrib").each do |path| - directory = File.dirname path - ruby_module = mapping.fetch(directory) + Dir.chdir("#{root}/lib/datadog/tracing/contrib") do |pwd| + Dir.glob("*/integration.rb").each do |path| + it "ensures #{pwd}/#{path} is loaded" do + directory = File.dirname path + ruby_module = mapping.fetch(directory) # raise key error if not found - it "ensures integration `#{ruby_module}` at #{path} is registered" do expect { Object.const_get "::Datadog::Tracing::Contrib::#{ruby_module}" }.not_to raise_error end end From 1eba8d22d54f8cfbff4ec52c57307ca3007060a6 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Tue, 8 Aug 2023 13:38:15 +0200 Subject: [PATCH 4/4] Rubocop --- spec/datadog/tracing/contrib_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/datadog/tracing/contrib_spec.rb b/spec/datadog/tracing/contrib_spec.rb index c48557b3814..6cea00579e8 100644 --- a/spec/datadog/tracing/contrib_spec.rb +++ b/spec/datadog/tracing/contrib_spec.rb @@ -56,7 +56,7 @@ } Dir.chdir("#{root}/lib/datadog/tracing/contrib") do |pwd| - Dir.glob("*/integration.rb").each do |path| + Dir.glob('*/integration.rb').each do |path| it "ensures #{pwd}/#{path} is loaded" do directory = File.dirname path ruby_module = mapping.fetch(directory) # raise key error if not found