Skip to content

Commit 2dd7665

Browse files
gregawoodsestolfo
andauthored
Support ruby 3.4 (#1510)
* Update ruby regex to support ruby 3.4 #1509 * Add ruby version * Fix failing mongo spec * Fix detecting job name in sidekiq 8+ * Handle different whitespace in mongo specs * Add the mutex_m gem for certain ruby/rails combinations * Don't test ruby 3.4 with rails 4 * Dont test ruby 3.4 with rails 5 --------- Co-authored-by: Emily S <[email protected]>
1 parent 961f169 commit 2dd7665

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

.ci/.exclude.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ exclude:
2020

2121
# rails-4.2 exclusions
2222
# Only test on ruby 2.4
23+
- VERSION: ruby:3.4
24+
FRAMEWORK: rails-4.2
2325
- VERSION: ruby:3.1
2426
FRAMEWORK: rails-4.2
2527
- VERSION: ruby:2.7
@@ -120,6 +122,10 @@ exclude:
120122
FRAMEWORK: grape-1.6
121123

122124
# only test ruby >= 3.1 with rails 6.1 and rails 7.0
125+
- VERSION: ruby:3.4
126+
FRAMEWORK: rails-5.2
127+
- VERSION: ruby:3.4
128+
FRAMEWORK: rails-5.1
123129
- VERSION: ruby:3.1
124130
FRAMEWORK: rails-5.2
125131
- VERSION: ruby:3.1

.ci/.ruby.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
VERSION:
2+
- ruby:3.4
23
- ruby:3.1
34
- ruby:2.7
45
- ruby:2.6

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ frameworks_versions.each do |framework, version|
9191
gem 'net-smtp', require: false
9292
end
9393

94+
if framework =='rails' && RUBY_VERSION >= '3.4' && ['4.2', '5.2', '6.1'].include?(version)
95+
gem 'mutex_m'
96+
end
97+
9498
case version
9599
when 'master' # grape
96100
gem framework, github: GITHUB_REPOS.fetch(framework)

lib/elastic_apm/spies/sidekiq.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Spies
2424
class SidekiqSpy
2525
ACTIVE_JOB_WRAPPER =
2626
'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'
27+
ACTIVE_JOB_WRAPPER_V8 = 'Sidekiq::ActiveJob::Wrapper'
2728

2829
# @api private
2930
class Middleware
@@ -50,7 +51,7 @@ def self.name_for(job)
5051
klass = job['class']
5152

5253
case klass
53-
when ACTIVE_JOB_WRAPPER
54+
when ACTIVE_JOB_WRAPPER, ACTIVE_JOB_WRAPPER_V8
5455
job['wrapped']
5556
else
5657
klass

lib/elastic_apm/stacktrace_builder.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module ElasticAPM
2424
# @api private
2525
class StacktraceBuilder
2626
JAVA_FORMAT = /^(.+)\.([^.]+)\(([^:]+):(\d+)\)$/.freeze
27-
RUBY_FORMAT = /^(.+?):(\d+)(?::in `(.+?)')?$/.freeze
27+
RUBY_FORMAT = /^(.+?):(\d+)(?::in ['`](.+#)?(.+?)')?$/.freeze
2828

2929
RUBY_VERS_REGEX = %r{ruby(/gems)?[-/](\d+\.)+\d}.freeze
3030
JRUBY_ORG_REGEX = %r{org/jruby}.freeze
@@ -77,9 +77,9 @@ def parse_line(line)
7777
ruby_match = line.match(RUBY_FORMAT)
7878

7979
if ruby_match
80-
_, file, number, method = ruby_match.to_a
80+
_, file, number, module_name, method = ruby_match.to_a
8181
file.sub!(/\.class$/, '.rb')
82-
module_name = nil
82+
module_name&.sub!('#', '')
8383
else
8484
java_match = line.match(JAVA_FORMAT)
8585
_, module_name, method, file, number = java_match.to_a

spec/elastic_apm/spies/mongo_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module ElasticAPM
5252
expect(db.instance).to eq 'elastic-apm-test'
5353
expect(db.type).to eq 'mongodb'
5454
expect(db.statement).to eq('{"listCollections"=>1}')
55+
.or eq("{\"listCollections\" => 1}")
5556
expect(db.user).to be nil
5657

5758
destination = span.context.destination
@@ -102,6 +103,7 @@ module ElasticAPM
102103
expect(db.instance).to eq 'elastic-apm-test'
103104
expect(db.type).to eq 'mongodb'
104105
expect(db.statement).to eq('{"find"=>"testing", "filter"=>{"a"=>"bc"}}')
106+
.or eq("{\"find\" => \"testing\", \"filter\" => {\"a\" => \"bc\"}}")
105107
expect(db.user).to be nil
106108
end
107109
end

spec/integration/mongo_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ module ElasticAPM
5656
db = span.context.db
5757
expect(db.instance).to eq 'elastic-apm-test'
5858
expect(db.type).to eq 'mongodb'
59-
expect(db.statement).to include '{"listCollections"=>1, "cursor"=>{}, ' \
60-
'"nameOnly"=>true'
59+
expect(db.statement).to include('{"listCollections"=>1, "cursor"=>{}, ' \
60+
'"nameOnly"=>true')
61+
.or include('{"listCollections" => 1, "cursor" => {}, ' \
62+
'"nameOnly" => true')
6163
expect(db.user).to be nil
6264
end
6365

@@ -93,6 +95,7 @@ module ElasticAPM
9395
expect(db.instance).to eq 'elastic-apm-test'
9496
expect(db.type).to eq 'mongodb'
9597
expect(db.statement).to match('"delete"=>"testing"')
98+
.or match('"delete" => "testing"')
9699
expect(db.user).to be nil
97100
end
98101

@@ -124,7 +127,8 @@ module ElasticAPM
124127
db = span.context.db
125128
expect(db.instance).to eq 'elastic-apm-test'
126129
expect(db.type).to eq 'mongodb'
127-
expect(db.statement).to include '{"a"=>BSON::Decimal128(\'1\')}'
130+
expect(db.statement).to include('{"a"=>BSON::Decimal128(\'1\')}')
131+
.or include('{"a" => BSON::Decimal128(\'1\')}')
128132
expect(db.user).to be nil
129133
end
130134

@@ -157,7 +161,8 @@ module ElasticAPM
157161
db = find_span.context.db
158162
expect(db.instance).to eq 'elastic-apm-test'
159163
expect(db.type).to eq 'mongodb'
160-
expect(db.statement).to include '{"find"=>"testing"'
164+
expect(db.statement).to include('{"find"=>"testing"')
165+
.or include('{"find" => "testing"')
161166
expect(db.user).to be nil
162167

163168
expect(get_more_span.name).to eq 'elastic-apm-test.testing.getMore'
@@ -169,7 +174,8 @@ module ElasticAPM
169174
db = get_more_span.context.db
170175
expect(db.instance).to eq 'elastic-apm-test'
171176
expect(db.type).to eq 'mongodb'
172-
expect(db.statement).to include '{"getMore"=>#<BSON::Int64'
177+
expect(db.statement).to include('{"getMore"=>#<BSON::Int64')
178+
.or include('{"getMore" => #<BSON::Int64')
173179
expect(db.user).to be nil
174180
end
175181

0 commit comments

Comments
 (0)