To notify slack, we have prepared it as an integration of sentry, but only the paid version is available.
I didn't intend to charge for it for personal projects, so I tried to make it available in the free version. Since we are focusing only on the notification part, explanations such as sentry settings are omitted.
--I'm using the free version of sentry and want to notify slack --I have an aws account
Use sentry's webhook. Specify the URI of lambda as the destination and request from lamda to slack webhook.
--Set the incoming webhook of slack and prepare the request destination. (Since there are various articles, it is omitted)
--Create lambda and set slack URI in environment variable SLACK_INCOMING_WEBHOOK_URL
--Copy and paste the following lambda process and save / deploy (sample is ruby)
require 'json'
def lambda_handler(event:, context:)
body = JSON.parse(event['body'])
post_query = {
"attachments": [
"pretext": "<#{body['url']}|Exception>\r\nproject: #{body['project_slug']}\r\nenvironment: #{body['event']['environment']}\r\ndetail: #{body['event']['metadata']['filename']}`#{body['event']['metadata']['function']}`",
"color": "#D00000",
"fields": [
"title": "#{body['event']['title']}",
"value": "#{body['culprit']}"
]
]
}
uri = URI.parse(ENV['SLACK_INCOMING_WEBHOOK_URL'])
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.post(uri.path, post_query.to_json)
{ statusCode: 200, body: JSON.generate('') }
end
You will receive the following notification. (The sample is an error caused by Rails)
Since the processing of lambda is premised on an error in Rails, there is a possibility that the information will not be displayed correctly with other frameworks. You can customize it by looking at the sentry webhook parameters.
Recommended Posts