How to configure alert for cloud run app

I am running my python based application inside the cloud run job , application used to process some files ,I can see the logs in log explorer and I am also able to set logging alerts for specific log strings , but the issue is it email alerts not sending the details logs for which file this alerts generated , is there anyway in GCP we can set alerts it will also send details logs define in strings in attached email 

thanks in advance 

2 4 1,027
4 REPLIES 4

Alerting setup to encompass specific log details in the email notifications.

Create a Log Metric:

  • Go to the GCP Console.
  • Navigate to "Logging" in the "Operations" section.
  • Select "Logs Explorer."
  • Construct a filter to match the logs you want to include in the alert, e.g., resource.type="cloud_run_revision" AND textPayload:"your_log_string".
  • Click "Create Metric" and configure the metric details.

Set Up an Alert Policy:

  • Go to the GCP Console.
  • Navigate to "Monitoring" in the "Operations" section.
  • Select "Alerting."
  • Click on "Create Policy."
  • Configure the conditions based on your metrics, setting the threshold and duration.
  • In the "Notification channels" section, add your email as a notification channel.

Configure Email Content:

  • For more detailed email content, use a notification channel that supports additional content, such as "Email (Legacy)." Click "Add Notification Channel" and select "Email (Legacy)."
  • Edit the notification channel, and you'll find an option to add a "Custom Message" or "Email Subject." Here, you can include variables like $ALERT_POLICY_NAME, $METRIC_NAME, and $CONDITION_NAME to provide more context.

Test the Alert:

  • After setting up the alert policy, it's a good practice to test it.
  • Trigger the condition by generating the logs that match your filter criteria.

By following these steps, you should receive email alerts that include details about the logs associated with the triggered alert. Adjust the metric, filter, and notification channel settings based on your specific requirements.

Thank you @Robina  for the help, I have configure this logging and alert mechanism but in alert email it is just providing information of alert strings but on which file it is coming those details missing from the alert email , to see the details I need to go to the given link to see details logs , any option we can see details logs also in the alert email?

thanks in advance 

Customize the email content by using a notification channel that supports additional content, such as "Email (Legacy)"

Configure Email Content:

  • After creating the notification channel, select "Email (Legacy)" as the notification channel type.
  • Edit the notification channel, and you'll find an option to add a "Custom Message" or "Email Subject."
  • Use variables like $ALERT_POLICY_NAME, $METRIC_NAME, and $CONDITION_NAME to provide more context.
  • Additionally, include variables related to log details, such as $FAULT_MESSAGE or $FAULT_DESCRIPTION, depending on the specifics of your logs.

Modify Email Content with Log Details:

Use log-specific variables in the email content to fetch relevant information. For example:

Alert details:
Policy: $ALERT_POLICY_NAME
Metric: $METRIC_NAME
Condition: $CONDITION_NAME
Log Details: $LOG_DETAILS_VARIABLE

Replace $LOG_DETAILS_VARIABLE with the appropriate variable representing the log details you want to include.

Test the Modified Alert:

  • After updating the email content, trigger the condition to test the alert.
  • Check the email notification to ensure that it now includes the desired log details.

 

thank you @Robina  Let me try and update you 🙂