[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable on_error when using with rails #4830

Open
vascoosx opened this issue Feb 17, 2020 · 3 comments
Open

Enable on_error when using with rails #4830

vascoosx opened this issue Feb 17, 2020 · 3 comments
Labels
api: logging Issues related to the Cloud Logging API. type: question Request for information or clarification. Not an issue.

Comments

@vascoosx
Copy link

Is your feature request related to a problem? Please describe.
I would like to know whenever logging fails. It seems that there is a way to do it when using it without the rails setup but it's unclear if it is possible to use it otherwise.

Describe the solution you'd like
I would like to be able to set it like the following:

 config.google_cloud.logging.on_error = ->(err) {
    Google::Cloud::ErrorReporting.report err
  }

Describe alternatives you've considered
just use it as it is used for non-rails apps

Additional context

# async.on_error do |error|
# # error can be a AsyncWriterError or AsyncWriteEntriesError
# Google::Cloud::ErrorReporting.report error
# end

@quartzmo quartzmo added api: logging Issues related to the Cloud Logging API. type: question Request for information or clarification. Not an issue. labels Feb 17, 2020
@thagomizer
Copy link
Contributor

Are you getting an error when you try this or does it just appear unsupported from the docs? What specific google gems are you using so I can try to reproduce the issue here.

@vascoosx
Copy link
Author
vascoosx commented Feb 20, 2020

@thagomizer I am using the stackdriver gem (version 0.16.1). It just appears unsupported. I have no problem logging, though some logs seem to be missing. I thought maybe it's supported but was not sure because I didn't know how to test it.

@quartzmo quartzmo assigned quartzmo and thagomizer and unassigned quartzmo Mar 4, 2020
@naingtk
Copy link
naingtk commented Apr 14, 2022

Observed in latest stackdriver gem.

If on_error is used in Google::Cloud.configure, it can catch the exceptions raised in the application.

Google::Cloud.configure do |config|
  config.project_id 	  = "<PROJECT_ID>"
  config.credentials    = "key.json"
  config.on_error        = lambda do |error| puts(error) end
end

But if it is used inside Rails config as follows, it is not catching exceptions.
Rails’s environment/*.rb

Rails.application.configure do |config|
  config.google_cloud.project_id    = "<PROJECT_ID>"
  config.google_cloud.credentials  = "key.json"
  config.google_cloud.on_error      = lambda do |error| puts(error) end
  end
end

I have noticed the source codes here [1] and found that on_error is not copied in ErrorReporting (Cloud Trace and Cloud Logging also) for Rails. on_error is then added to the default callback [2] but it is not copied for Rails.

If this behavior is intended and on_error cannot be used in Rails config, please kindly add a note or warning to the READEME [3] as some developers are having trouble with which configuration can be used for Rails config.

[1]


[2]
error_cb = Google::Cloud::ErrorReporting.configure.on_error

[3] https://github.com/googleapis/google-cloud-ruby/blob/main/google-cloud-trace/README.md#authentication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants