Skip to content

Commit 0aee3ef

Browse files
authored
Merge pull request #1503 from appsignal/fix-http-6
Fix http.rb integration for version 6
2 parents 427ae9f + 37a2ac9 commit 0aee3ef

File tree

8 files changed

+166
-8
lines changed

8 files changed

+166
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: patch
3+
type: fix
4+
---
5+
6+
Fix compatibility with `http` (http.rb) gem version 6.0.0 and higher.

.github/workflows/ci.yml

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This is a generated file by the `rake build_matrix:github:generate` task.
33
# See `build_matrix.yml` for the build matrix.
44
# Generate this file with `rake build_matrix:github:generate`.
5-
# Generated job count: 191
5+
# Generated job count: 195
66
---
77
name: Ruby gem CI
88
'on':
@@ -265,6 +265,33 @@ jobs:
265265
JRUBY_OPTS: ''
266266
COV: '1'
267267
BUNDLE_GEMFILE: gemfiles/http5.gemfile
268+
ruby_4-0-0__http6_ubuntu-latest:
269+
name: Ruby 4.0.0 - http6
270+
needs: ruby_4-0-0_ubuntu-latest
271+
runs-on: ubuntu-latest
272+
steps:
273+
- name: Check out repository
274+
uses: actions/checkout@v4
275+
- name: Install Ruby
276+
uses: ruby/setup-ruby@v1
277+
with:
278+
ruby-version: 4.0.0
279+
bundler-cache: true
280+
- name: Install gem extension
281+
run: "./script/bundler_wrapper exec rake extension:install"
282+
- name: Print extension install report
283+
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
284+
file found'"
285+
- name: Print Makefile log file
286+
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
287+
found'"
288+
- name: Run tests
289+
run: "./script/bundler_wrapper exec rake test"
290+
env:
291+
RAILS_ENV: test
292+
JRUBY_OPTS: ''
293+
COV: '1'
294+
BUNDLE_GEMFILE: gemfiles/http6.gemfile
268295
ruby_4-0-0__ownership_ubuntu-latest:
269296
name: Ruby 4.0.0 - ownership
270297
needs: ruby_4-0-0_ubuntu-latest
@@ -998,6 +1025,33 @@ jobs:
9981025
JRUBY_OPTS: ''
9991026
COV: '1'
10001027
BUNDLE_GEMFILE: gemfiles/http5.gemfile
1028+
ruby_3-4-1__http6_ubuntu-latest:
1029+
name: Ruby 3.4.1 - http6
1030+
needs: ruby_3-4-1_ubuntu-latest
1031+
runs-on: ubuntu-latest
1032+
steps:
1033+
- name: Check out repository
1034+
uses: actions/checkout@v4
1035+
- name: Install Ruby
1036+
uses: ruby/setup-ruby@v1
1037+
with:
1038+
ruby-version: 3.4.1
1039+
bundler-cache: true
1040+
- name: Install gem extension
1041+
run: "./script/bundler_wrapper exec rake extension:install"
1042+
- name: Print extension install report
1043+
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
1044+
file found'"
1045+
- name: Print Makefile log file
1046+
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
1047+
found'"
1048+
- name: Run tests
1049+
run: "./script/bundler_wrapper exec rake test"
1050+
env:
1051+
RAILS_ENV: test
1052+
JRUBY_OPTS: ''
1053+
COV: '1'
1054+
BUNDLE_GEMFILE: gemfiles/http6.gemfile
10011055
ruby_3-4-1__ownership_ubuntu-latest:
10021056
name: Ruby 3.4.1 - ownership
10031057
needs: ruby_3-4-1_ubuntu-latest
@@ -1758,6 +1812,33 @@ jobs:
17581812
JRUBY_OPTS: ''
17591813
COV: '1'
17601814
BUNDLE_GEMFILE: gemfiles/http5.gemfile
1815+
ruby_3-3-4__http6_ubuntu-latest:
1816+
name: Ruby 3.3.4 - http6
1817+
needs: ruby_3-3-4_ubuntu-latest
1818+
runs-on: ubuntu-latest
1819+
steps:
1820+
- name: Check out repository
1821+
uses: actions/checkout@v4
1822+
- name: Install Ruby
1823+
uses: ruby/setup-ruby@v1
1824+
with:
1825+
ruby-version: 3.3.4
1826+
bundler-cache: true
1827+
- name: Install gem extension
1828+
run: "./script/bundler_wrapper exec rake extension:install"
1829+
- name: Print extension install report
1830+
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
1831+
file found'"
1832+
- name: Print Makefile log file
1833+
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
1834+
found'"
1835+
- name: Run tests
1836+
run: "./script/bundler_wrapper exec rake test"
1837+
env:
1838+
RAILS_ENV: test
1839+
JRUBY_OPTS: ''
1840+
COV: '1'
1841+
BUNDLE_GEMFILE: gemfiles/http6.gemfile
17611842
ruby_3-3-4__ownership_ubuntu-latest:
17621843
name: Ruby 3.3.4 - ownership
17631844
needs: ruby_3-3-4_ubuntu-latest
@@ -2518,6 +2599,33 @@ jobs:
25182599
JRUBY_OPTS: ''
25192600
COV: '1'
25202601
BUNDLE_GEMFILE: gemfiles/http5.gemfile
2602+
ruby_3-2-5__http6_ubuntu-latest:
2603+
name: Ruby 3.2.5 - http6
2604+
needs: ruby_3-2-5_ubuntu-latest
2605+
runs-on: ubuntu-latest
2606+
steps:
2607+
- name: Check out repository
2608+
uses: actions/checkout@v4
2609+
- name: Install Ruby
2610+
uses: ruby/setup-ruby@v1
2611+
with:
2612+
ruby-version: 3.2.5
2613+
bundler-cache: true
2614+
- name: Install gem extension
2615+
run: "./script/bundler_wrapper exec rake extension:install"
2616+
- name: Print extension install report
2617+
run: "[ -e ext/install.report ] && cat ext/install.report || echo 'No ext/install.report
2618+
file found'"
2619+
- name: Print Makefile log file
2620+
run: "[ -f ext/mkmf.log ] && cat ext/mkmf.log || echo 'No ext/mkmf.log file
2621+
found'"
2622+
- name: Run tests
2623+
run: "./script/bundler_wrapper exec rake test"
2624+
env:
2625+
RAILS_ENV: test
2626+
JRUBY_OPTS: ''
2627+
COV: '1'
2628+
BUNDLE_GEMFILE: gemfiles/http6.gemfile
25212629
ruby_3-2-5__ownership_ubuntu-latest:
25222630
name: Ruby 3.2.5 - ownership
25232631
needs: ruby_3-2-5_ubuntu-latest

build_matrix.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ matrix:
175175
- "3.2.5"
176176
- "3.1.6"
177177
- gem: "http5"
178+
- gem: "http6"
179+
only:
180+
ruby:
181+
- "4.0.0"
182+
- "3.4.1"
183+
- "3.3.4"
184+
- "3.2.5"
178185
- gem: "ownership"
179186
- gem: "padrino"
180187
exclude:

gemfiles/http6.gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "https://rubygems.org"
2+
3+
gem "http", "~> 6.0"
4+
gem "ostruct"
5+
6+
gemspec :path => "../"

lib/appsignal/hooks/http.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@ class Hooks
66
class HttpHook < Appsignal::Hooks::Hook
77
register :http_rb
88

9+
def self.http6_or_higher?
10+
Gem::Version.new(HTTP::VERSION) >= Gem::Version.new("6.0.0")
11+
end
12+
913
def dependencies_present?
1014
defined?(HTTP::Client) && Appsignal.config && Appsignal.config[:instrument_http_rb]
1115
end
1216

1317
def install
1418
require "appsignal/integrations/http"
15-
HTTP::Client.prepend Appsignal::Integrations::HttpIntegration
19+
integration =
20+
if self.class.http6_or_higher?
21+
Appsignal::Integrations::HttpIntegration::KeywordOptions
22+
else
23+
Appsignal::Integrations::HttpIntegration::HashOptions
24+
end
25+
HTTP::Client.prepend integration
1626

1727
Appsignal::Environment.report_enabled("http_rb")
1828
end

lib/appsignal/integrations/http.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ module Appsignal
44
module Integrations
55
# @!visibility private
66
module HttpIntegration
7-
def request(verb, uri, opts = {})
7+
def self.instrument(verb, uri, &block)
88
uri_module = defined?(HTTP::URI) ? HTTP::URI : URI
99
parsed_request_uri = uri.is_a?(URI) ? uri : uri_module.parse(uri.to_s)
1010
request_uri = "#{parsed_request_uri.scheme}://#{parsed_request_uri.host}"
1111

12-
Appsignal.instrument("request.http_rb", "#{verb.upcase} #{request_uri}") do
13-
super
12+
Appsignal.instrument("request.http_rb", "#{verb.upcase} #{request_uri}", &block)
13+
end
14+
15+
module HashOptions
16+
def request(verb, uri, opts = {})
17+
HttpIntegration.instrument(verb, uri) { super }
18+
end
19+
end
20+
21+
module KeywordOptions
22+
def request(verb, uri, **opts)
23+
HttpIntegration.instrument(verb, uri) { super }
1424
end
1525
end
1626
end

spec/lib/appsignal/hooks/http_spec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
it { is_expected.to be_truthy }
1313
end
1414

15-
it "installs the HTTP plugin" do
16-
expect(HTTP::Client.included_modules)
17-
.to include(Appsignal::Integrations::HttpIntegration)
15+
if DependencyHelper.http6_present?
16+
it "installs the HTTP plugin with keyword options" do
17+
expect(HTTP::Client.included_modules)
18+
.to include(Appsignal::Integrations::HttpIntegration::KeywordOptions)
19+
end
20+
else
21+
it "installs the HTTP plugin with hash options" do
22+
expect(HTTP::Client.included_modules)
23+
.to include(Appsignal::Integrations::HttpIntegration::HashOptions)
24+
end
1825
end
1926
end
2027

spec/support/helpers/dependency_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ def http_present?
131131
dependency_present? "http"
132132
end
133133

134+
def http6_present?
135+
http_present? && Gem.loaded_specs["http"].version >= Gem::Version.new("6.0.0")
136+
end
137+
134138
def que_present?
135139
dependency_present? "que"
136140
end

0 commit comments

Comments
 (0)