UnavailableError in Google Cloud Logging

304 Views Asked by At

I want to create a specific log inside my ruby script with google-cloud-logging gem installed.

It works when I run it on my windows client but i get the following error when I run it on my linux server:

/usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/service.rb:327:in `rescue in execute': 14:Connect Failed (Google::Cloud::UnavailableError)
    from /usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/service.rb:324:in `execute'
    from /usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/service.rb:124:in `write_entries'
    from /usr/lib64/ruby/gems/2.1.0/gems/google-cloud-logging-1.2.1/lib/google/cloud/logging/project.rb:277:in `write_entries'
    from ./test.rb:26:in `<main>'

I've installed Google Cloud SDK an I'm authorized via ginit on both machines. I also added the keyfile which is an logging-admin service account but nothing works. I'm able to upload files to a bucket via googl-cloud-storage on the same machine

Here is my Ruby script sample:

require "google/cloud/logging"

puts "in script"
logging = Google::Cloud::Logging.new(project: "projectname", 
                                 keyfile: ###path###)
puts "after logging"
filename = "test from server"

entry = logging.entry
entry.payload = filename
entry.log_name = "1"
entry.resource.type = "gae_app"
entry.resource.labels[:module_id] = "upload"
entry.resource.labels[:version_id] = "1.0.0.0"
puts "after setup"
logging.write_entries entry
puts "after writing"
1

There are 1 best solutions below

0
On

Looks like you are using ruby 2.1 in the documentation says that ruby 2.2 or greater is needed link

So install ruby 2.3 and install the gems

gem "google-cloud-logging"
gem "stackdriver"