如何让 Google Stackdriver 与 Rails 7.1+ 配合使用

问题描述 投票:0回答:1

我刚刚花了几个小时在互联网上查找如何解决该问题。但是,对于我的生活,我不知道该怎么办......

我遵循了 Google 提供的文档 github.com/googleapis/google-cloud-ruby

# Gemfile
gem 'stackdriver', '~> 0.21.1'
# development.rb
config.google_cloud.project_id  = ENV.fetch('GOOGLE_CLOUD_PROJECT_ID')
config.google_cloud.keyfile     = ENV.fetch('GOOGLE_CLOUD_KEYFILE')
config.google_cloud.use_logging = true # Explicitly enable or disable Logging middleware. Default: Rails.env.production?

当我使用

bin/dev
运行我的 Rails 应用程序时,以下是我得到的结果。

4/02/24 5:17:16   Linked git:(main)  bin/dev
17:17:18 web.1  | started with pid 94783
17:17:18 css.1  | started with pid 94784
17:17:20 web.1  | DEBUGGER: Debugger can attach via UNIX domain socket (/var/folders/dp/z539166d4s505qs2tpt4dhdc0000gn/T/ruby-debug-sock-501/ruby-debug-username-94783)
17:17:21 web.1  | => Booting Puma
17:17:21 web.1  | => Rails 7.1.1 application starting in development 
17:17:21 web.1  | => Run `bin/rails server --help` for more startup options
17:17:22 web.1  | Exiting
17:17:22 web.1  | /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/commands/server/server_command.rb:83:in `log_to_stdout': undefined method `broadcast_to' for #<Google::Cloud::Logging::Logger:0x0000000107d3e020 @writer=#<Google::Cloud::Logging::AsyncWriter:0x0000000107d3e3e0 @mon_data=#<Monitor:0x0000000107d3e278>, @mon_data_owner_object_id=1480, @logging=#<Google::Cloud::Logging::Project:0x0000000107d3f790 @service=Google::Cloud::Logging::Service(project-id), @shared_async_writer=#<Google::Cloud::Logging::AsyncWriter:0x0000000107d3e3e0 ...>>, @max_count=10000, @max_bytes=10000000, @max_queue=100, @interval=5, @threads=10, @partial_success=false, @error_callbacks=[], @cond=#<MonitorMixin::ConditionVariable:0x0000000107d3e160 @monitor=#<Monitor:0x0000000107d3e278>, @cond=#<Thread::ConditionVariable:0x0000000107d3e110>>, @stopped=true>, @log_name="ruby_app_log", @resource=#<Google::Cloud::Logging::Resource:0x0000000107d3e610 @labels={}, @type="global">, @labels={}, @level=0, @request_info_var=#<Concurrent::ThreadLocalVar:0x0000000107d3df58 @default_block=nil, @default=nil, @index=31>, @closed=false, @formatter=#<Logger::Formatter:0x0000000107d3ddf0 @datetime_format=nil>, @datetime_format="", @silencer=true, @project="project-id"> (NoMethodError)
17:17:22 web.1  | 
17:17:22 web.1  |           Rails.logger.broadcast_to(console)
17:17:22 web.1  |                       ^^^^^^^^^^^^^
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/commands/server/server_command.rb:36:in `start'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/commands/server/server_command.rb:145:in `block in perform'
17:17:22 web.1  |       from <internal:kernel>:90:in `tap'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/commands/server/server_command.rb:136:in `perform'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/command/base.rb:178:in `invoke_command'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/command/base.rb:73:in `perform'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/command.rb:71:in `block in invoke'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/command.rb:149:in `with_argv'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/command.rb:69:in `invoke'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.1/lib/rails/commands.rb:18:in `<main>'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
17:17:22 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
17:17:22 web.1  |       from bin/rails:4:in `<main>'
17:17:22 web.1  | exited with code 1
17:17:22 system | sending SIGTERM to all processes
17:17:22 css.1  | bin/rails aborted!
17:17:22 css.1  | SignalException: SIGTERM
17:17:22 css.1  | 
17:17:22 css.1  | Tasks: TOP => tailwindcss:watch
17:17:22 css.1  | (See full trace by running task with --trace)
17:17:22 css.1  | exited with code 1
4/02/24 5:17:22   Linked git:(main) 

我更新了我的依赖项,但结果是否相同:

4/02/24 5:34:19   Linked git:(main)  bin/dev      
17:34:25 web.1  | started with pid 96200
17:34:25 css.1  | started with pid 96201
17:34:31 web.1  | DEBUGGER: Debugger can attach via UNIX domain socket (/var/folders/dp/z539166d4s505qs2tpt4dhdc0000gn/T/rdbg-501/rdbg-96200)
17:34:35 web.1  | => Booting Puma
17:34:35 web.1  | => Rails 7.1.3 application starting in development 
17:34:35 web.1  | => Run `bin/rails server --help` for more startup options
17:34:37 web.1  | Exiting
17:34:37 web.1  | /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/commands/server/server_command.rb:83:in `log_to_stdout': undefined method `broadcast_to' for #<Google::Cloud::Logging::Logger:0x000000011564d4b0 @writer=#<Google::Cloud::Logging::AsyncWriter:0x000000011564d870 @mon_data=#<Monitor:0x000000011564d708>, @mon_data_owner_object_id=1480, @logging=#<Google::Cloud::Logging::Project:0x000000011564ec20 @service=Google::Cloud::Logging::Service(project-id), @shared_async_writer=#<Google::Cloud::Logging::AsyncWriter:0x000000011564d870 ...>>, @max_count=10000, @max_bytes=10000000, @max_queue=100, @interval=5, @threads=10, @partial_success=false, @error_callbacks=[], @cond=#<MonitorMixin::ConditionVariable:0x000000011564d5f0 @monitor=#<Monitor:0x000000011564d708>, @cond=#<Thread::ConditionVariable:0x000000011564d5a0>>, @stopped=true>, @log_name="ruby_app_log", @resource=#<Google::Cloud::Logging::Resource:0x000000011564daa0 @labels={}, @type="global">, @labels={}, @level=0, @request_info_var=#<Concurrent::ThreadLocalVar:0x000000011564d3e8 @default_block=nil, @default=nil, @index=31>, @closed=false, @formatter=#<Logger::Formatter:0x000000011564d280 @datetime_format=nil>, @datetime_format="", @silencer=true, @project="project-id"> (NoMethodError)
17:34:37 web.1  | 
17:34:37 web.1  |           Rails.logger.broadcast_to(console)
17:34:37 web.1  |                       ^^^^^^^^^^^^^
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/commands/server/server_command.rb:36:in `start'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/commands/server/server_command.rb:145:in `block in perform'
17:34:37 web.1  |       from <internal:kernel>:90:in `tap'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/commands/server/server_command.rb:136:in `perform'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/command/base.rb:178:in `invoke_command'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/command/base.rb:73:in `perform'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/command.rb:71:in `block in invoke'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/command.rb:149:in `with_argv'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/command.rb:69:in `invoke'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/railties-7.1.3/lib/rails/commands.rb:18:in `<main>'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
17:34:37 web.1  |       from /Users/username/.rvm/rubies/ruby-3.1.4/bin/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
17:34:37 web.1  |       from bin/rails:4:in `<main>'
17:34:37 web.1  | exited with code 1
17:34:37 system | sending SIGTERM to all processes
17:34:37 css.1  | bin/rails aborted!
17:34:37 css.1  | SignalException: SIGTERM
17:34:37 css.1  | 
17:34:37 css.1  | Tasks: TOP => tailwindcss:watch
17:34:37 css.1  | (See full trace by running task with --trace)
17:34:38 css.1  | exited with code 1
4/02/24 5:34:38   Linked git:(main) 

我应该怎么做才能让它发挥作用?

ruby-on-rails ruby stackdriver google-cloud-logging
1个回答
0
投票

你有没有设法解决这个问题?我也遇到同样的错误,网上找不到任何东西

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.