Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 615

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T12:30:06+00:00 2024-11-25T12:30:06+00:00

Say Goodbye to Paid Sentry Alerts: Get Error Notifications on Slack for Free!

  • 62k

Are you tired of paying for Sentry's Slack integration? What if I told you there's a way to send error notifications to Slack for free? That's right—no more paying for what you can do with a few simple tricks. By leveraging Sentry's webhook, Vercel's edge functions, and Slack’s free API, you can set up a system that gets real-time error alerts sent straight to Slack without shelling out a dime. Intrigued? Let me show you how.

Why Pay for Something You Can Do for Free?

Sentry offers a built-in integration with Slack, but it’s locked behind a paywall. For smaller projects or indie developers, that’s just not worth it. Luckily, we can bypass this by creating a webhook listener on Vercel that formats error notifications and sends them to Slack via the free Slack API.

Ready to ditch the paid plans? Let’s dive in.

Step 1: Configuring the Sentry Webhook (No, It’s Not Hard)

Sentry provides a webhook legacy integration that lets you send error events to external services. Here’s how you hook that up to a free Vercel edge function:

  1. Open Your Sentry Project: Head to your project settings in Sentry.
  2. Enable Webhooks: Under Legacy Integrations, add a new webhook. This is where Sentry will send error data.
  3. Point It to Vercel: Once we set up our Vercel function, you’ll use that URL here. But first, let’s get the listener set up.

Step 2: Vercel Edge Function—The Magic Sauce

If you’re new to Vercel, it’s a serverless platform that allows you to run code at the “edge” for free (within certain limits). We’re going to deploy an edge function that will listen for Sentry events, format them, and send them to Slack. Here’s the code that does it all:

export const config = {   runtime: 'edge', };  const sendMessage = async (channel, { level, formatted, environment, email, title, culprit, project }) => {   console.info({ channel, level, formatted, environment, email, title, culprit, project });   const isError = level === "error";   const blocks = [     {       "type": "section",       "text": {         "type": "mrkdwn",         "text": `${isError ? ":red_circle:" : ""} *${title}*`,       },     },     {       "type": "section",       "fields": [         {           "type": "mrkdwn",           "text": `*Environment:*
${environment}`,         },         {           "type": "mrkdwn",           "text": `*Level:*
${level}`,         },         {           "type": "mrkdwn",           "text": `*Project:*
${project}`,         },       ],     },     {       "type": "section",       "fields": [         {           "type": "mrkdwn",           "text": `*User:*
${email}`,         },       ],     },     {       "type": "divider",     },     {       "type": "section",       "text": {         "type": "mrkdwn",         "text": `*Message:*
${formatted}`,       },     },     {       "type": "section",       "text": {         "type": "mrkdwn",         "text": `*Message:*
${culprit}`,       },     },     {       "type": "divider",     },   ];    try {     const response = await fetch('https://slack.com/api/chat.postMessage', {       method: 'POST',       headers: {         'Content-Type': 'application/json; charset=utf-8',         'Authorization': `Bearer ${process.env.SLACK_ACCESS_TOKEN}`,       },       body: JSON.stringify({         channel,         blocks,       }),     });      return response.data;   } catch (e) {     console.error(e);   } };  export default async (req) => {   const body = await req.json();   const { project, culprit, event: { level, logentry: { formatted }, user: { email }, environment, metadata: { title } } } = body;    await sendMessage(process.env.CHANNEL_ID, { level, formatted, environment, email, title, culprit, project });    return new Response(`Hello from Edge.js! ${body}`); }; 
Enter fullscreen mode Exit fullscreen mode

What This Code Does:

  • Receives Sentry Events: The function is triggered when Sentry sends an event (like an error).
  • Formats the Message: It parses the event and formats a Slack message using blocks (the fancy Slack message formatting system).
  • Sends It to Slack: Using Slack’s API, it posts the error message to a channel of your choice.

Step 3: Slack Setup—Let the Notifications Begin

Here’s how you make sure Slack gets the error alerts:

  1. Create a Slack App: Visit api.slack.com/apps and create a new app in your workspace.
  2. Permissions: Under OAuth & Permissions, add the chat:write permission.
  3. Install the App: Grab the OAuth token after installing the app to your workspace.
  4. Environment Variables: Set SLACK_ACCESS_TOKEN and CHANNEL_ID as environment variables in Vercel.

Step 4: Deploy the Function to Vercel

Push the code to a GitHub repository, connect it to Vercel, and deploy. You’ll need to add your Slack token and channel ID as environment variables. Vercel will handle the rest.

Now, when an error happens in Sentry, it will trigger your edge function, and you’ll see those notifications in Slack within seconds!

Step 5: Testing the Integration

To test if everything’s working, trigger an error in your Sentry project. Check your Slack channel for the notification! If it worked, you should see a neatly formatted message with all the error details.

Why This is Awesome

  • It’s Free: No more paying for Sentry’s Slack integration.
  • Real-Time Alerts: Get instant error notifications as soon as they happen.
  • Customizable: You control how the Slack messages look and what data they contain.
  • No Maintenance: Vercel’s serverless functions handle everything with almost no setup costs.

Bonus: Get the Code & Show Some Love ❤️

You can grab this ready-made solution on my GitHub! Feel free to customize it, use it in your projects, or even improve upon it. If you find it helpful, consider giving the repo a star ⭐ to support more content like this.

Check out the GitHub Repository Here


Got Feedback? Drop a comment or share your thoughts. And if this tutorial saved you some money or gave you a new tool in your dev arsenal, give it a share. Let’s make development easier for everyone!

sentryvercelwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.