diff --git a/.ci/.exclude.yml b/.ci/.exclude.yml index 8a5a5036f..cfabf9da3 100644 --- a/.ci/.exclude.yml +++ b/.ci/.exclude.yml @@ -2,19 +2,15 @@ exclude: # Ruby 2.4 # Only test on rails-4.2, sinatra-1.4 - VERSION: ruby:2.4 - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 - VERSION: ruby:2.4 FRAMEWORK: rails-6.1 - - VERSION: ruby:2.4 - FRAMEWORK: rails-6.0 - VERSION: ruby:2.4 FRAMEWORK: rails-5.2 - VERSION: ruby:2.4 FRAMEWORK: sinatra-2.2 - VERSION: ruby:2.4 FRAMEWORK: grape-1.6 - - VERSION: ruby:2.4 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.0 - VERSION: ruby:2.4 FRAMEWORK: rails-main - VERSION: ruby:2.4 @@ -26,8 +22,6 @@ exclude: # Only test on ruby 2.4 - VERSION: ruby:3.1 FRAMEWORK: rails-4.2 - - VERSION: ruby:3.0 - FRAMEWORK: rails-4.2 - VERSION: ruby:2.7 FRAMEWORK: rails-4.2 - VERSION: ruby:2.6 @@ -43,8 +37,6 @@ exclude: # sinatra-1.4 exclusions - VERSION: ruby:3.1 FRAMEWORK: sinatra-1.4 - - VERSION: ruby:3.0 - FRAMEWORK: sinatra-1.4 - VERSION: ruby:2.7 FRAMEWORK: sinatra-1.4 - VERSION: jruby:9.2 @@ -56,22 +48,18 @@ exclude: - VERSION: elasticobservability/jruby:9.2-8-jdk FRAMEWORK: sinatra-1.4 - # rails-6.0 and rails-6.1 exclusions + # rails-6.1 and rails 7.0 exclusions # Don't test on ruby 2.4 - VERSION: ruby:2.4 FRAMEWORK: rails-6.1 - VERSION: ruby:2.4 - FRAMEWORK: rails-6.0 + FRAMEWORK: rails-7.2 # Only test rails main on ruby 3.1 - - VERSION: ruby:3.0 - FRAMEWORK: rails-main - VERSION: ruby:2.7 FRAMEWORK: rails-main - VERSION: ruby:2.6 FRAMEWORK: rails-main - - VERSION: ruby:2.5 - FRAMEWORK: rails-main - VERSION: ruby:2.4 FRAMEWORK: rails-main - VERSION: jruby:9.2 @@ -83,29 +71,25 @@ exclude: - VERSION: elasticobservability/jruby:9.2-8-jdk FRAMEWORK: rails-main - # Only test rails 7.0 on ruby >= 2.7 + # Only test rails 7.2 on ruby >= 3.1 + - VERSION: ruby:2.7 + FRAMEWORK: rails-7.2 - VERSION: ruby:2.6 - FRAMEWORK: rails-7.0 - - VERSION: ruby:2.5 - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 - VERSION: ruby:2.4 - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 - VERSION: jruby:9.2 - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 - VERSION: elasticobservability/jruby:9.2-13-jdk - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 - VERSION: elasticobservability/jruby:9.2-11-jdk - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 - VERSION: elasticobservability/jruby:9.2-8-jdk - FRAMEWORK: rails-7.0 + FRAMEWORK: rails-7.2 # Only test sinatra main on ruby 2.7 and ruby 3.1 - - VERSION: ruby:3.0 - FRAMEWORK: sinatra-main - VERSION: ruby:2.6 FRAMEWORK: sinatra-main - - VERSION: ruby:2.5 - FRAMEWORK: sinatra-main - VERSION: ruby:2.4 FRAMEWORK: sinatra-main - VERSION: jruby:9.2 @@ -117,11 +101,9 @@ exclude: - VERSION: elasticobservability/jruby:9.2-8-jdk FRAMEWORK: sinatra-main - # Only test grape master on ruby 2.7 and ruby 3.0 + # Only test grape master on ruby 2.7 and ruby 3.1 - VERSION: ruby:2.6 FRAMEWORK: grape-master - - VERSION: ruby:2.5 - FRAMEWORK: grape-master - VERSION: ruby:2.4 FRAMEWORK: grape-master - VERSION: jruby:9.2 @@ -133,61 +115,12 @@ exclude: - VERSION: elasticobservability/jruby:9.2-8-jdk FRAMEWORK: grape-master - # grape 1.5 doesn't support ruby 3.0 + # grape 1.5 doesn't support ruby 3.1 - VERSION: ruby:3.1 FRAMEWORK: grape-1.6 - - VERSION: ruby:3.1 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - - VERSION: ruby:3.1 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: ruby:3.0 - FRAMEWORK: grape-1.6 - - VERSION: ruby:3.0 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - # only test ruby >= 3.0 with rails 6.0 and rails 6.1 + # only test ruby >= 3.1 with rails 6.1 and rails 7.0 - VERSION: ruby:3.1 FRAMEWORK: rails-5.2 - VERSION: ruby:3.1 FRAMEWORK: rails-5.1 - - VERSION: ruby:3.0 - FRAMEWORK: rails-5.2 - - VERSION: ruby:3.0 - FRAMEWORK: rails-5.1 - - # Unsupported - # Ruby 2.6 - - VERSION: ruby:2.6 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: ruby:2.6 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - # Ruby 2.5 - - VERSION: ruby:2.5 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: ruby:2.5 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - # Ruby 2.4 - - VERSION: ruby:2.4 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: ruby:2.4 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - # JRuby 9.2 - - VERSION: jruby:9.2 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: jruby:9.2 - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - # JRuby 9.2-13-jdk - - VERSION: elasticobservability/jruby:9.2-13-jdk - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: elasticobservability/jruby:9.2-13-jdk - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - # JRuby 9.2-11-jdk - - VERSION: elasticobservability/jruby:9.2-11-jdk - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: elasticobservability/jruby:9.2-11-jdk - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 - # JRuby 9.2-8-jdk - - VERSION: elasticobservability/jruby:9.2-8-jdk - FRAMEWORK: grape-1.6,sinatra-2.2,rails-6.1 - - VERSION: elasticobservability/jruby:9.2-8-jdk - FRAMEWORK: grape-1.6,sinatra-2.2,rails-7.0 diff --git a/.ci/.framework.yml b/.ci/.framework.yml index a63649aeb..5fde31acf 100644 --- a/.ci/.framework.yml +++ b/.ci/.framework.yml @@ -1,7 +1,6 @@ FRAMEWORK: - - rails-7.0 + - rails-7.2 - rails-6.1 - - rails-6.0 - rails-5.2 - rails-4.2 @@ -9,5 +8,3 @@ FRAMEWORK: - sinatra-1.4 - grape-1.6 - - - grape-1.6,sinatra-2.2,rails-6.1 diff --git a/.ci/.ruby.yml b/.ci/.ruby.yml index e66d453ea..321ee3027 100644 --- a/.ci/.ruby.yml +++ b/.ci/.ruby.yml @@ -1,6 +1,5 @@ VERSION: - ruby:3.1 - - ruby:3.0 - ruby:2.7 - ruby:2.6 - ruby:2.4 diff --git a/Gemfile b/Gemfile index 19f70996a..967f60054 100644 --- a/Gemfile +++ b/Gemfile @@ -103,6 +103,11 @@ frameworks_versions.each do |framework, version| end end +# Handle Rack::Auth::Digest being removed in rack 3.1, grape requires it +if frameworks_versions.key?('grape') + gem 'rack', '~> 3.0.0' +end + if frameworks_versions.key?('rails') unless /^(main|6)/.match?(frameworks_versions['rails']) gem 'delayed_job', require: nil @@ -125,8 +130,12 @@ if RUBY_PLATFORM == 'java' end elsif frameworks_versions['rails'] =~ /^(4|5)/ gem 'sqlite3', '~> 1.3.6' +elsif frameworks_versions['rails'] =~ /^(6|7)/ + gem 'sqlite3', '~> 1.4' elsif RUBY_VERSION < '2.7' gem 'sqlite3', '~> 1.4.4' +elsif RUBY_VERSION < '3.0' + gem 'sqlite3', '~> 1.3.6' else gem 'sqlite3' end diff --git a/lib/elastic_apm/context_builder.rb b/lib/elastic_apm/context_builder.rb index 534e46000..759b31f62 100644 --- a/lib/elastic_apm/context_builder.rb +++ b/lib/elastic_apm/context_builder.rb @@ -79,8 +79,11 @@ def get_body(req) when 'application/x-www-form-urlencoded', 'multipart/form-data' req.POST.dup else - body = req.body.read - req.body.rewind + io = req.body + return '' unless io + + body = io.read + io.rewind body.byteslice(0, MAX_BODY_LENGTH).force_encoding('utf-8').scrub end end diff --git a/spec/elastic_apm/grpc_spec.rb b/spec/elastic_apm/grpc_spec.rb index 9bedbfc75..bf12f7726 100644 --- a/spec/elastic_apm/grpc_spec.rb +++ b/spec/elastic_apm/grpc_spec.rb @@ -19,7 +19,7 @@ require 'spec_helper' -# if !defined?(JRUBY_VERSION) && RUBY_VERSION < '3.0' +# if !defined?(JRUBY_VERSION) && RUBY_VERSION >= '3.0' # require 'grpc' # # module ElasticAPM diff --git a/spec/integration/rails_spec.rb b/spec/integration/rails_spec.rb index 7c0d08a56..9bf6d843e 100644 --- a/spec/integration/rails_spec.rb +++ b/spec/integration/rails_spec.rb @@ -105,6 +105,10 @@ def create render_ok end + def test_body + render_ok + end + def raise_error raise FancyError, "Help! I'm trapped in a specfile!" end @@ -151,6 +155,7 @@ def ping(recipient, subject) root to: 'application#index' get '/tags_and_context', to: 'application#context' post '/', to: 'application#create' + post '/test_body', to: 'application#test_body' get '/error', to: 'application#raise_error' get '/report_message', to: 'application#report_message' get '/send_notification', to: 'application#send_notification' @@ -207,7 +212,7 @@ def ping(recipient, subject) end describe 'transactions' do - context 'when a simple request is made' do + context 'when a simple get request is made' do it 'spans action and posts it' do get '/' @@ -218,6 +223,20 @@ def ping(recipient, subject) end end + context 'when a simple post request is made with a body' do + it 'spans action and posts it' do + post '/test_body', '{"data":{"a":"1","b":"five"}}', + 'CONTENT_TYPE' => 'application/json' + + wait_for transactions: 1, spans: 2 + + name = @mock_intake.transactions.fetch(0)['name'] + expect(name).to eq 'ApplicationController#test_body' + body = @mock_intake.transactions.fetch(0).dig('context', 'request', 'body') + expect(body).to eq '{"data":{"a":"1","b":"five"}}' + end + end + context 'when tags and context are set' do it 'sets the values' do get '/tags_and_context' diff --git a/spec/support/helloworld_pb.rb b/spec/support/helloworld_pb.rb index 105ea260d..ad19edb46 100644 --- a/spec/support/helloworld_pb.rb +++ b/spec/support/helloworld_pb.rb @@ -34,22 +34,22 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: helloworld.proto -if !defined?(JRUBY_VERSION) && RUBY_VERSION < '3.0' - require 'google/protobuf' - - Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "helloworld.HelloRequest" do - optional :name, :string, 1 - end - add_message "helloworld.HelloReply" do - optional :message, :string, 1 - end - end - - module Helloworld - HelloRequest = Google::Protobuf::DescriptorPool - .generated_pool.lookup('helloworld.HelloRequest').msgclass - HelloReply = Google::Protobuf::DescriptorPool - .generated_pool.lookup('helloworld.HelloReply').msgclass - end -end +# if !defined?(JRUBY_VERSION) && RUBY_VERSION < '3.0' +# require 'google/protobuf' +# +# Google::Protobuf::DescriptorPool.generated_pool.build do +# add_message "helloworld.HelloRequest" do +# optional :name, :string, 1 +# end +# add_message "helloworld.HelloReply" do +# optional :message, :string, 1 +# end +# end +# +# module Helloworld +# HelloRequest = Google::Protobuf::DescriptorPool +# .generated_pool.lookup('helloworld.HelloRequest').msgclass +# HelloReply = Google::Protobuf::DescriptorPool +# .generated_pool.lookup('helloworld.HelloReply').msgclass +# end +# end diff --git a/spec/support/helloworld_services_pb.rb b/spec/support/helloworld_services_pb.rb index 8211357de..81a6c342a 100644 --- a/spec/support/helloworld_services_pb.rb +++ b/spec/support/helloworld_services_pb.rb @@ -31,24 +31,24 @@ # frozen_string_literal: true -if !defined?(JRUBY_VERSION) && RUBY_VERSION < '3.0' - require_relative 'helloworld_pb' - - module Helloworld - module Greeter - # The greeting service definition. - class Service - include GRPC::GenericService - - self.marshal_class_method = :encode - self.unmarshal_class_method = :decode - self.service_name = 'helloworld.Greeter' - - # Sends a greeting - rpc :SayHello, HelloRequest, HelloReply - end - - Stub = Service.rpc_stub_class - end - end -end +# if !defined?(JRUBY_VERSION) && RUBY_VERSION < '3.0' +# require_relative 'helloworld_pb' +# +# module Helloworld +# module Greeter +# # The greeting service definition. +# class Service +# include GRPC::GenericService +# +# self.marshal_class_method = :encode +# self.unmarshal_class_method = :decode +# self.service_name = 'helloworld.Greeter' +# +# # Sends a greeting +# rpc :SayHello, HelloRequest, HelloReply +# end +# +# Stub = Service.rpc_stub_class +# end +# end +# end diff --git a/spec/support/mock_intake.rb b/spec/support/mock_intake.rb index 486a85a84..8caf14ceb 100644 --- a/spec/support/mock_intake.rb +++ b/spec/support/mock_intake.rb @@ -19,7 +19,13 @@ require 'json' require 'timeout' -require 'rack/chunked' +begin + if ::Rack.release >= '3.1' + require 'rack' + end +rescue NoMethodError + require 'rack/chunked' +end class MockIntake def initialize