I have a Rails app running in GKE and I'm trying to set up Google Cloud Error Reporting. I have installed the stackdriver
gem and required it on application startup. I can manually report errors from the Rails console without issue, but they don't appear in the GCP Error Reporting UI.
irb(main):021:0> Google::Cloud::ErrorReporting.report(Exception.new(msg: "from console")).result
=> [true, [], nil]
I also confirmed that it's configured with the correct project_id
and that I'm looking at the correct project in the GCP UI.
UPDATE
I used the code snippet found here and replaced $stderr
with $stdout
and changing the log level to DEBUG to get some insight into the RPC call. When I tried to report another exception in the console, I saw the following...
Failing with status #<struct Struct::Status code=7, details="User not authorized.", metadata={}, debug_error_string="UNKNOWN:Error received from peer ipv4:xxx.xxx.xxx.xx:443 {grpc_message:\"User not authorized.\", grpc_status:7, created_time:\"2024-05-23T17:54:30.826579798+00:00\"}">
Seeing this "User not authorized" error, I checked the service account's assigned roles and saw that it didn't have the necessary errorreporting.errorEvents.create
role. Once that was added, I was able to report and exception and see it appear in the Error Reporting UI.
There might be an issue with configuring the GCP Error Reporting, below steps may help you to resolve the issue:
Verify again that API for Error Reporting is enabled for appropriate Google Cloud Project.
Check whether the associated ServiceAccount with GKE cluster has all the required permissions, also service account must have the “roles/errorreporting.writer” role to write to Stackdriver Error Reporting.
Check if the correct Error Reporting Client Library has been installed with respect to Ruby, For Ruby google-cloud-error_reporting gem is required.
Once again ensure that the GKE cluster has all required permissions to access GCP services.
Refer to this official GCP Instrument Ruby app for Error Reporting for more insights.
Also check this Github document on google-cloud-error_reporting for more details.