Skip to content

Commit

Permalink
switch to use gem declarations instead of hardcoded mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
quinna-h committed Dec 23, 2024
1 parent 514be2c commit 65aee38
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 39 deletions.
49 changes: 23 additions & 26 deletions .github/scripts/find_gem_version_bounds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,9 @@ def get_integration_names(directory = 'lib/datadog/tracing/contrib/')
Datadog::Tracing::Contrib::REGISTRY.map{ |i| i.name.to_s }
end

# TODO: The gem information should reside in the integration declaration instead of here.

mapping = {
"action_mailer" => "actionmailer",
"opensearch" => "opensearch-ruby",
"concurrent_ruby" => "concurrent-ruby",
"action_view" => "actionview",
"action_cable" => "actioncable",
"active_record" => "activerecord",
"mongodb" => "mongo",
"rest_client" => "rest-client",
"active_support" => "activesupport",
"action_pack" => "actionpack",
"active_job" => "activejob",
"httprb" => "http",
"kafka" => "ruby-kafka",
"presto" => "presto-client",
"aws" => "aws-sdk-core"
}
SPECIAL_CASES = {
"opensearch" => "OpenSearch" # special case because opensearch = OpenSearch not Opensearch
}.freeze

excluded = ["configuration", "propagation", "utils"]
min_gems_ruby, min_gems_jruby, max_gems_ruby, max_gems_jruby = parse_gemfiles("gemfiles/")
Expand All @@ -115,19 +99,32 @@ def get_integration_names(directory = 'lib/datadog/tracing/contrib/')
integration_json_mapping = {}

integrations.each do |integration|
if excluded.include?(integration)
next
next if excluded.include?(integration)

begin
mod_name = SPECIAL_CASES[integration] || integration.split('_').map(&:capitalize).join
module_name = "Datadog::Tracing::Contrib::#{mod_name}"
integration_module = Object.const_get(module_name)::Integration
integration_name = integration_module.respond_to?(:gem_name) ? integration_module.gem_name : integration
rescue NameError
puts "Integration module not found for #{integration}, falling back to integration name."
integration_name = integration
rescue NoMethodError
puts "gem_name method missing for #{integration}, falling back to integration name."
integration_name = integration
end
integration_name = mapping[integration] || integration

min_version_jruby = min_gems_jruby[integration_name]
min_version_ruby = min_gems_ruby[integration_name]
max_version_jruby = max_gems_jruby[integration_name]
max_version_ruby = max_gems_ruby[integration_name]

# mapping jruby, ruby
integration_json_mapping[integration] = [min_version_ruby, max_version_ruby, min_version_jruby, max_version_jruby]
integration_json_mapping.replace(integration_json_mapping.sort.to_h)
integration_json_mapping[integration] = [
min_version_ruby, max_version_ruby,
min_version_jruby, max_version_jruby
]
end

File.write("gem_output.json", JSON.pretty_generate(integration_json_mapping))
# Sort and output the mapping
integration_json_mapping = integration_json_mapping.sort.to_h
File.write("gem_output.json", JSON.pretty_generate(integration_json_mapping))
4 changes: 3 additions & 1 deletion lib/datadog/tracing/contrib/action_cable/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :action_cable, auto_patch: false

def self.gem_name
'actioncable'
end
def self.version
Gem.loaded_specs['actioncable'] && Gem.loaded_specs['actioncable'].version
end
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/tracing/contrib/action_mailer/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :action_mailer, auto_patch: false

def self.gem_name
'actionmailer'
end

def self.version
Gem.loaded_specs['actionmailer'] && Gem.loaded_specs['actionmailer'].version
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/tracing/contrib/action_pack/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :action_pack, auto_patch: false

def self.gem_name
'actionpack'
end
def self.version
Gem.loaded_specs['actionpack'] && Gem.loaded_specs['actionpack'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/action_view/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :action_view, auto_patch: false

def self.gem_name
'actionview'
end

def self.version
# ActionView is its own gem in Rails 4.1+
if Gem.loaded_specs['actionview']
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/active_job/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :active_job, auto_patch: false

def self.gem_name
'activejob'
end

def self.version
Gem.loaded_specs['activejob'] && Gem.loaded_specs['activejob'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/active_record/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :active_record, auto_patch: false

def self.gem_name
'activerecord'
end

def self.version
Gem.loaded_specs['activerecord'] && Gem.loaded_specs['activerecord'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/active_support/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :active_support, auto_patch: false

def self.gem_name
'activesupport'
end

def self.version
Gem.loaded_specs['activesupport'] && Gem.loaded_specs['activesupport'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/aws/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :aws, auto_patch: true

def self.gem_name
'aws-sdk-core'
end

def self.version
if Gem.loaded_specs['aws-sdk']
Gem.loaded_specs['aws-sdk'].version
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/concurrent_ruby/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :concurrent_ruby

def self.gem_name
'concurrent-ruby'
end

def self.version
Gem.loaded_specs['concurrent-ruby'] && Gem.loaded_specs['concurrent-ruby'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/httprb/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :httprb

def self.gem_name
'http'
end

def self.version
Gem.loaded_specs['http'] && Gem.loaded_specs['http'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/kafka/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :kafka, auto_patch: false

def self.gem_name
'ruby-kafka'
end

def self.version
Gem.loaded_specs['ruby-kafka'] && Gem.loaded_specs['ruby-kafka'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/mongodb/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :mongo, auto_patch: true

def self.gem_name
'mongo'
end

def self.version
Gem.loaded_specs['mongo'] && Gem.loaded_specs['mongo'].version
end
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/tracing/contrib/opensearch/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :opensearch, auto_patch: true
def self.gem_name
'opensearch-ruby'
end

def self.version
Gem.loaded_specs['opensearch-ruby'] \
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/presto/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :presto

def self.gem_name
'presto-client'
end

def self.version
Gem.loaded_specs['presto-client'] && Gem.loaded_specs['presto-client'].version
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/tracing/contrib/rest_client/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Integration

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :rest_client

def self.gem_name
'rest-client'
end

def self.version
Gem.loaded_specs['rest-client'] && Gem.loaded_specs['rest-client'].version
end
Expand Down

0 comments on commit 65aee38

Please sign in to comment.