[RUBY] Send a notification to slack with the free version of sentry (using lambda)

About this article

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.

Target

--I'm using the free version of sentry and want to notify slack --I have an aws account

About the method

Use sentry's webhook. Specify the URI of lambda as the destination and request from lamda to slack webhook.

procedure

--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

result

You will receive the following notification. (The sample is an error caused by Rails)

スクリーンショット 2020-11-01 19.34.16.png

Finally

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

Send a notification to slack with the free version of sentry (using lambda)
Try to imitate the idea of a two-dimensional array with a one-dimensional array
Is the version of Elasticsearch you are using compatible with Java 11?
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
I tried to visualize the access of Lambda → Athena with AWS X-Ray
Send a request to the backend after authenticating with Spring Cloud Gateway
How to get the ID of a user authenticated with Firebase in Swift
Up to the point of launching a Docker container built using RedHat Quarkus
A quick note on using jshell with the official Docker image of the JDK
Make a margin to the left of the TextField
Set the time of LocalDateTime to a specific time
Manage the version of Ruby itself with rbenv
Try the free version of Progate [Java II]
Try the free version of Progate [Java I]
[Final version] Check the operation of the Japanese calendar using ICU to support the new era.
[Docker] How to see the contents of Volumes. Start a container with root privileges.
How to set the retry limit of sidekiq and notify dead queues with slack
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
Let's implement a function to limit the number of access to the API with SpringBoot + Redis
The story of making a reverse proxy with ProxyServlet
How to download the old version of Apache Tomcat
The first step to using Xib instead of StoryBoard
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
The story of building a Java version of Minecraft server with GCP (and also set a whitelist)
A Java user over a dozen years ago tried to study the functions of Java8 (Lambda expression).
Display a balloon message in BarButtonItem of NavigationBar with a size according to the amount of text.
Notify Slack of AWS bills daily with Lambda for Ruby
How to take a screenshot with the Android Studio emulator
Port C code with a lot of typecasts to Swift
A story packed with the basics of Spring Boot (solved)
Check the operation of two roles with a chat application
The idea of C # (lambda expression, for statement) to chew
A story addicted to toString () of Interface proxied with JdkDynamicAopProxy
A series of steps to create portfolio deliverables with Rails
How to move another class with a button action of another class.
[2020 version] How to send an email using Android Studio Javamail
[Ruby] How to retrieve the contents of a double hash
Takashi! I've got rice! Notification of rice using the Ovserver pattern
Explain the benefits of the State pattern with a movie rating
The story of pushing Java to Heroku using the BitBucket pipeline
A memo to start Java programming with VS Code (2020-04 version)
Be sure to compare the result of Java compareTo with 0
[jsoup] How to get the full amount of a document
Find the number of days in a month with Kotlin
How to register as a customer with Square using Tomcat
Update to the latest version without specifying the version with gradle wrapper
[Apache Tomcat] The story of using Apache OpenWebBeans to enable CDI
Create a large number of records with one command using the Ruby on Rails seeds.rb file
[Rails] Implementation of multi-layer category function using ancestry "I tried to make a window with Bootstrap 3"
I tried to express the result of before and after of Date class with a number line
I tried to take a look at the flow of Android development environment construction with Android Studio
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
A story about using the CoreImage framework to erase stains with Swift and implement a blur erase function