0

In our multitenant environment, I would like to setup an alert notification(e.g. email) when our user's code has an exception. I was thinking of using the stackdriver error reporting api to send an error notification. Something like

from google.cloud import error_reporting

client = error_reporting.Client()
try:
    raise NameError
except Exception:
    client.report_exception()

How can I set this up (using a python api)

  • create an alert for a tenant id/service id to send notifications to. I could input user's contact email in this step.
  • Report an exception for a tenant id/service id using something like client.report_exception() and notify the alert mechanism

Other solutions: This post suggests that I use logging and log errors, create a filter and create an alert policy. That would be an option but I feel it may be expensive as that would mean for each of the services of our users, it will be running the log search query every few seconds/minutes? I was wondering if there was a push approach (vs the logging pull approach) or have I misunderstood that the logging notification is actually a push approach?

If I'm on the wrong path, please feel free to suggest better ways.

RAbraham
  • 5,956
  • 8
  • 45
  • 80
  • Your use of the multi-tenant phrase is throwing me. Normally one has an organization with multiple projects and there is monitoring/logging on a per project basis. Is this the story or is there something broader? Beyond this, when one uses error reporting, it is my understanding that the reported error is also logged. When logging occurs, one can set up an export that can be targeted at Pub/Sub which could trigger an email. – Kolban Jun 26 '19 at 04:15
  • Yes, my GCP Project is a serverless platform on kubernetes. We plan to host many orgs(tenants) within our project. I agree that the monitoring is a per project basis. I was wondering if I could segment it further within the project with tags(a tag representing an org/tenant) which I can specifically search for and push to the respective email for that tenant. I'll manage the emails. I just need to segregate exceptions by tag/label. Thanks for the Pub/Sub idea. – RAbraham Jun 27 '19 at 23:37
  • Interesting. I think fundamentally, you want to subscribe to some form of trigger when an Error Reporting event occurs. A quick read of the current API suggests you'd need to poll the service and this may be inefficient. One loosely-coupled approach may be to build a solution atop Notifications (https://cloud.google.com/error-reporting/docs/notifications). You configure it to email your team and then your solution parses emails and determines which of your customers ought be notified? – DazWilkin Jun 28 '19 at 21:41
  • 1
    Had a chat with the PM for Stackdriver Error Reporting. They concur with the suggestion to consider using Notifications to email an alias managed by your team and to then process and on-send emails to your customers. HTH! – DazWilkin Jul 08 '19 at 16:16
  • @DazWilkin. Wow, that is so nice of you! Thank you! I've temporarily moved to another solution but I'll check it out and get back. – RAbraham Jul 09 '19 at 11:44
  • You're welcome! Best wishes – DazWilkin Jul 09 '19 at 14:20

0 Answers0