googleapis / google-cloud-ruby

Google Cloud Client Library for Ruby
https://googleapis.github.io/google-cloud-ruby/
Apache License 2.0
1.35k stars 546 forks source link

google-cloud-logging: Read env variables when loading rails #6895

Open erikaxel opened 4 years ago

erikaxel commented 4 years ago

Is your feature request related to a problem? Please describe. google-cloud-logging supports config from the environment keys GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_KEYFILE_JSON. If these are set the simple example

logging = Google::Cloud::Logging.new # note, not setting project id or credentials here
entry = logging.entry
entry.payload = "Hello, world!"
entry.log_name = "my-log"
entry.resource.type = "global"
logging.write_entries entry

works perfectly. However, the Rails-part (in google/cloud/logging/rails.rb) does not support this. We use these ENV variables, and in particular there we have no .json file with the credentials, they are stored in the ENV variable GOOGLE_CLOUD_KEYFILE_JSON.

Describe the solution you'd like That the Rails autoloading supports GOOGLE_CLOUD_KEYFILE_JSON and GOOGLE_CLOUD_PROJECT if set.

Describe alternatives you've considered I could lift the code out and make my own code that sets the default logger, or I could write the contents of GOOGLE_CLOUD_KEYFILE_JSON to a file and pass in that as param. Both seem hackish and it is strange that the library both supports and does not support using GOOGLE_CLOUD_KEYFILE_JSON.

erikaxel commented 4 years ago

Hi, I see that this question has been added the type question. I don't really think this is a question, it is a feature request. (Some would even call it a bug given that you would expect the same result if you run pure Ruby or with the Rails autoloader)