scoutapp / scout_apm_ruby

ScoutAPM Ruby Agent. Supports Rails, Sinatra, Grape, Rack, and many other frameworks

Home Page:https://scoutapm.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Barfs on valid ruby syntax

wilg opened this issue · comments

Found this out the hard way, in production.

2021-04-20T23:44:08.152651+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.0.1/lib/scout_apm/auto_instrument/instruction_sequence.rb:11:in `compile': /app/app/controllers/quests_controller.rb:4: syntax error, unexpected '{', expecting `end' (SyntaxError)
2021-04-20T23:44:08.152668+00:00 app[rpush.1]: ...:4:in `index'"]){quests.each} { ::ScoutApm::AutoInstrument("...
2021-04-20T23:44:08.152669+00:00 app[rpush.1]: ...                              ^
2021-04-20T23:44:08.152669+00:00 app[rpush.1]: /app/app/controllers/quests_controller.rb:4: syntax error, unexpected '}', expecting `end'
2021-04-20T23:44:08.152670+00:00 app[rpush.1]: ....current_user = current_user} }
2021-04-20T23:44:08.152670+00:00 app[rpush.1]: ...                              ^
2021-04-20T23:44:08.152671+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.0.1/lib/scout_apm/auto_instrument/instruction_sequence.rb:11:in `load_iseq'
2021-04-20T23:44:08.152682+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
2021-04-20T23:44:08.152683+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
2021-04-20T23:44:08.152683+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2021-04-20T23:44:08.152684+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
2021-04-20T23:44:08.152689+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
2021-04-20T23:44:08.152689+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
2021-04-20T23:44:08.152690+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:409:in `const_get'
2021-04-20T23:44:08.152690+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:409:in `block (2 levels) in eager_load'
2021-04-20T23:44:08.152691+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:733:in `block in ls'
2021-04-20T23:44:08.152691+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:725:in `foreach'
2021-04-20T23:44:08.152691+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:725:in `ls'
2021-04-20T23:44:08.152692+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:404:in `block in eager_load'
2021-04-20T23:44:08.152693+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:393:in `synchronize'
2021-04-20T23:44:08.152693+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:393:in `eager_load'
2021-04-20T23:44:08.152693+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:508:in `each'
2021-04-20T23:44:08.152694+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/loader.rb:508:in `eager_load_all'
2021-04-20T23:44:08.152694+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.1/lib/rails/application/finisher.rb:133:in `block in <module:Finisher>'
2021-04-20T23:44:08.152694+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:32:in `instance_exec'
2021-04-20T23:44:08.152695+00:00 app[rpush.1]: 	from /app/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:32:in `run'

Here is the line in question:

  def index
    quests = policy_scope(Quest.open)
    quests.each { _1.current_user = current_user }
    respond_with_proto quests
  end

I am on an old version of the gem because of #391

gem "scout_apm", "4.0.1" 

I unfortunately have to remove Scout because it has been so unreliable.

I'm sorry you ran into issues getting setup. I'm working on several issues, and this one appears to be working in the currently released version of the agent. I added an explicit test as well.

I don't think I can use the latest version of the agent because of #391

I'm having this same issue with scout_apm "5.2.0"

Code:

    @stations = current_user.stations.filter_scope(params[:station_ids])
    @stations.each { authorize _1, :read? } # <= This line has the issue.
    @equipments = Equipment.joins(:station).where(station_id: @stations.pluck(:id))

and the error:

   Failure/Error: @stations.each { authorize _1, :read? }
     
     SyntaxError:
       /app/app/controllers/v2/equipments_controller.rb:9: syntax error, unexpected '{', expecting `end'
       ...in `index'"]){@stations.each} { ::ScoutApm::AutoInstrument("...
       ...                              ^
(service: site) (step: code-quality_rspec)        /app/app/controllers/v2/equipments_controller.rb:9: syntax error, unexpected '}', expecting `end'
       ...dex'"]){authorize _1, :read?} }
       ...                              ^
     Shared Example Group: "Rswag: Filters permission specific results" called from ./spec/requests/v2/equipment_spec.rb:36
(service: site) (step: code-quality_rspec)      # ./app/controllers/v2/equipments_controller.rb:9: syntax error, unexpected '{', expecting `end'
     # ...in `index'"]){@stations.each} { ::ScoutApm::AutoInstrument("...
     # ...                              ^
     # ./app/controllers/v2/equipments_controller.rb:9: syntax error, unexpected '}', expecting `end'
     # ...dex'"]){authorize _1, :read?} }
     # ...                              ^
     # /usr/local/bundle/bundler/gems/scout_apm_ruby-b818da2b0343/lib/scout_apm/auto_instrument/instruction_sequence.rb:11:in `compile'
     # /usr/local/bundle/bundler/gems/scout_apm_ruby-b818da2b0343/lib/scout_apm/auto_instrument/instruction_sequence.rb:11:in `load_iseq'
     # /usr/local/bundle/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
     # /usr/local/bundle/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
     # /usr/local/bundle/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:27:in `require'
     # /usr/local/bundle/bundler/gems/scout_apm_ruby-b818da2b0343/lib/scout_apm/middleware.rb:17:in `call'
     # /usr/local/bundle/gems/flipper-0.25.0/lib/flipper/middleware/memoizer.rb:72:in `memoized_call'
     # /usr/local/bundle/gems/flipper-0.25.0/lib/flipper/middleware/memoizer.rb:37:in `call'
     # /usr/local/bundle/gems/olive_branch-4.0.1/lib/olive_branch/middleware.rb:64:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:266:in `context'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:260:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/method_override.rb:24:in `call'
(service: site) (step: code-quality_rspec)      # /usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
     # /usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
     # /usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/tempfile_reaper.rb:15:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/etag.rb:27:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/conditional_get.rb:27:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/head.rb:12:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:266:in `context'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:260:in `call'
     # /usr/local/bundle/gems/railties-7.0.2.3/lib/rails/rack/logger.rb:36:in `call_app'
     # /usr/local/bundle/gems/railties-7.0.2.3/lib/rails/rack/logger.rb:25:in `block in call'
     # /usr/local/bundle/gems/railties-7.0.2.3/lib/rails/rack/logger.rb:25:in `call'
(service: site) (step: code-quality_rspec)      # /usr/local/bundle/gems/request_store-1.5.1/lib/request_store/middleware.rb:19:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/method_override.rb:24:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/runtime.rb:22:in `call'
     # ./config/initializers/compressed_requests.rb:25:in `call'
     # /usr/local/bundle/gems/rack-2.2.3.1/lib/rack/sendfile.rb:110:in `call'
     # /usr/local/bundle/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
     # /usr/local/bundle/gems/honeybadger-4.12.1/lib/honeybadger/rack/error_notifier.rb:33:in `block in call'
     # /usr/local/bundle/gems/honeybadger-4.12.1/lib/honeybadger/agent.rb:426:in `with_rack_env'
     # /usr/local/bundle/gems/honeybadger-4.12.1/lib/honeybadger/rack/error_notifier.rb:30:in `call'
     # /usr/local/bundle/gems/honeybadger-4.12.1/lib/honeybadger/rack/user_feedback.rb:31:in `call'
     # /usr/local/bundle/gems/honeybadger-4.12.1/lib/honeybadger/rack/user_informer.rb:21:in `call'
     # /usr/local/bundle/gems/railties-7.0.2.3/lib/rails/engine.rb:530:in `call'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/test.rb:119:in `request'
     # /usr/local/bundle/gems/rails-controller-testing-1.0.5/lib/rails/controller/testing/integration.rb:16:in `block (2 levels) in <module:Integration>'
     # /usr/local/bundle/gems/rswag-specs-2.5.1/lib/rswag/specs/example_helpers.rb:20:in `submit_request'
     # ./spec/requests/v2/equipment_spec.rb:43:in `block (6 levels) in <main>'
     # /usr/local/bundle/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>'
     # /usr/local/bundle/gems/parallel_split_test-0.10.0/lib/parallel_split_test/command_line.rb:29:in `block in run'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:587:in `call_with_index'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:557:in `process_incoming_jobs'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:537:in `block in worker'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:528:in `fork'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:528:in `worker'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:519:in `block in create_workers'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:518:in `each'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:518:in `each_with_index'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:518:in `create_workers'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:457:in `work_in_processes'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:294:in `map'
     # /usr/local/bundle/gems/parallel-1.22.1/lib/parallel.rb:234:in `in_processes'
     # /usr/local/bundle/gems/parallel_split_test-0.10.0/lib/parallel_split_test/command_line.rb:23:in `run'
     # /usr/local/bundle/gems/parallel_split_test-0.10.0/lib/parallel_split_test/runner.rb:13:in `block in run'
     # /usr/local/bundle/gems/parallel_split_test-0.10.0/lib/parallel_split_test/runner.rb:23:in `report_execution_time'
     # /usr/local/bundle/gems/parallel_split_test-0.10.0/lib/parallel_split_test/runner.rb:12:in `run'