Skip to content

Instantly share code, notes, and snippets.

View 6mini's full-sized avatar

Yoonmin Lee 6mini

View GitHub Profile
@6mini
6mini / slack_error_notification.py
Last active June 20, 2024 02:17
파이썬(Python) 프로그램에서 에러가 발생했을 때 슬랙(Slack)으로 알림을 보내는 기능이다. send_slack_notification 함수를 통해 Slack API에 메시지를 전송하고, handle_error 함수를 통해 발생한 예외의 내용과 스택 트레이스를 슬랙으로 전송한다. 스택 트레이스가 길 경우, 여러 메시지로 분할하여 전송하며, 깔끔한 알림 시스템 구축을 위해 스레드의 댓글로 전송한다.
import json
import requests
import traceback
import time
def send_slack_notification(blocks, thread_ts=None):
"""
Slack 채널에 메시지를 전송하는 함수이다.
Args: