{"id":18123276,"url":"https://github.com/jay-johnson/slack-driven-development","last_synced_at":"2025-04-06T12:45:03.849Z","repository":{"id":72596662,"uuid":"61247574","full_name":"jay-johnson/slack-driven-development","owner":"jay-johnson","description":"Tired of crawling through logs looking for errors? This is a simple Slack bot that publishes exceptions + line number + environment name into a channel to help develop and find bugs faster","archived":false,"fork":false,"pushed_at":"2016-06-26T03:39:06.000Z","size":2574,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T18:47:03.424Z","etag":null,"topics":["error-messages","error-monitoring","exception-handler","exception-messages","exceptions","python-2","python-exceptions","python-stacktrace","slack","slackbot","stacktrace"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jay-johnson.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-15T23:25:42.000Z","updated_at":"2017-04-03T02:31:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d083cce-82ae-4f68-a5c0-17a3f56767ff","html_url":"https://github.com/jay-johnson/slack-driven-development","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fslack-driven-development","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fslack-driven-development/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fslack-driven-development/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fslack-driven-development/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jay-johnson","download_url":"https://codeload.github.com/jay-johnson/slack-driven-development/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485251,"owners_count":20946398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-messages","error-monitoring","exception-handler","exception-messages","exceptions","python-2","python-exceptions","python-stacktrace","slack","slackbot","stacktrace"],"created_at":"2024-11-01T07:08:56.122Z","updated_at":"2025-04-06T12:45:03.820Z","avatar_url":"https://github.com/jay-johnson.png","language":"Python","readme":"========================\nSlack Driven Development\n========================\nDate: **2016-06-15**\n\nSince I am always sitting in a slack channel, I wanted to share a tool I use to track exceptions across my cloud and other environments.\n\nThis repository_ is an example for posting: exceptions, tracking environment errors, and sending targeted debugging messages to a Slack channel to help decrease time spent finding + fixing bugs.\n\nI built this because I was tired of tail-ing and grep-ing through logs. Now I just wait for exceptions and errors to be published into a **debugging** Slack channel so I can quickly view: what ``environment`` had the error, the ``associated message``, and the ``source code line number``.\n\n.. _repository: https://github.com/jay-johnson/slack-driven-development\n.. role:: bash(code)\n         :language: bash\n\nSetup\n-----\n\nThis repository only works with Python 2.\n\n1. Install the official Slack Python API \n\n   .. note:: Please refer to the official `Slack repository`_ for more information\n\n   ::\n\n        sudo pip install slackclient\n\n.. _Slack repository: https://github.com/slackhq/python-slackclient\n\nGetting Started\n---------------\n\n#. Create a Slack channel for debugging messages\n\n   This demo uses a channel with the name: ``#debugging``\n\n#. Create a named Slack bot if you do not have one already\n\n   This demo uses a bot with the name: ``bugbot``\n\n#. Record the Slack bot's API Token\n\n   This demo uses a bot with an API token: ``xoxb-51351043345-oHKTiT5sXqIAlxwYzQspae54``\n    \n#. Invite the Slack bot to your debugging channel\n\n   Type this into the debugging channel and hit enter: \n    \n   ::\n        \n        /invite bugbot\n\n   .. warning:: If you do not invite the bot into the channel it can be difficult to debug\n\n#. Edit the configuration for your needs\n\n   The example file slack_driven_development.py_ uses a configuration `dictionary object`_ where you can assign these keys based off your needs:\n\n   +-----------------+------------------------------------------------------------+\n   | Key Name        | Purpose and Where to find the Value                        |\n   +=================+============================================================+\n   | **BotName**     | Name of the Slack bot that will post messages              |\n   +-----------------+------------------------------------------------------------+\n   | **ChannelName** | Name of the channel where messages are posted              |\n   +-----------------+------------------------------------------------------------+\n   | **NotifyUser**  | Name of the Slack user that gets notified for messages     |\n   +-----------------+------------------------------------------------------------+\n   | **Token**       | Slack API Token for the bot                                |\n   +-----------------+------------------------------------------------------------+\n   | **EnvName**     | A logical name for showing which environment had the error |\n   +-----------------+------------------------------------------------------------+\n\n#. Test the bot works\n\n   The included slack_driven_development.py_ file will throw an exception that will report the exception into the channel using the bot based off the simple dictionary configuration in the file.\n\n   ::\n\n        $ ./slack_driven_development.py \n        Testing an Exception that shows up in Slack\n        Sending an error message to Slack for Exception(name 'testing_how_this_looks_from_slack' is not defined)\n        Done\n        $\n\n#. Confirm the debugging message shows up in Slack channel\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/07SlackDrivenDevelopmentExample.png\n\n.. _dictionary object: https://github.com/jay-johnson/slack-driven-development/blob/78ced381ce1a1594e735943a8a9ab145425fe7d1/slack_driven_development.py#L5-L11\n.. _slack_driven_development.py: https://github.com/jay-johnson/slack-driven-development/blob/master/slack_driven_development.py\n\n\n\nScreenshots for Getting Started\n-------------------------------\n\nHere are the screenshots (as of **06-15-2016**) for getting this demo integrated with your Slack channel and bot:\n\n**1. Create a new Slack App Integration**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/01SlackAddANewIntegration.png\n\n\n**2. Build a new Integration**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/02SlackBuild.png\n    \n\n**3. Make a Custom Integration**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/03SlackMakeCustomIntegration.png\n\n\n**4. Create a new Bot**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/04SlackBotCreateNewBot.png\n    \n\n**5. Name and Add Bot**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/05SlackNameAndAddBot.png\n    \n\n**6. Record the Bot API Token in the Dictionary Configuration**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/06SlackRecordBotAPIToken.png\n    \n\n**7. Run the Slack Driven Development Demo**\n\n.. image:: https://raw.githubusercontent.com/jay-johnson/slack-driven-development/master/images/07SlackDrivenDevelopmentExample.png\n\n\nHow does this work?\n-------------------\n\n1. By using a `try/catch block`_ we can capture the exception, and pass it into a `handler method`_.\n\n   .. code-block:: python\n      :linenos:\n\n      try:\n          print \"Testing an Exception that shows up in Slack\"\n          testing_how_this_looks_from_slack\n      except Exception,k:\n          print \"Sending an error message to Slack for the expected Exception(\" + str(k) + \")\"\n          slack_msg.handle_send_slack_internal_ex(k)\n      # end of try/ex\n\n.. _try/catch block: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_driven_development.py#L15-L21\n.. _handler method: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L19-L33\n\n2. `Prepare the exception`_\n\n.. _Prepare the exception: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L19-L33\n\n3. `Inspect the exception`_\n\n   Python has a great little feature where it can `inspect the stacktrace`_ from an exception outside of the calling objects and even files. Once the file with the exception has been found, we can open the file and goto the `exact line that caused the exception`_ and `build an error report with the source code and the line number`_.\n\n   .. code-block:: python\n      :linenos:\n\n      def get_exception_error_message(self, ex, exc_type, exc_obj, exc_tb):\n\n          path_to_file = str(exc_tb.tb_frame.f_code.co_filename)\n          last_line = int(exc_tb.tb_lineno)\n          gh_line_number = int(last_line) - 1\n          file_name = str(os.path.split(exc_tb.tb_frame.f_code.co_filename)[1])\n          path_to_file = str(exc_tb.tb_frame.f_code.co_filename)\n          py_file = open(path_to_file).readlines()\n          line = \"\"\n          for line_idx,cur_line in enumerate(py_file):\n              if line_idx == gh_line_number:\n                  line = cur_line\n   \n          if str(exc_obj.message) != \"\":\n              ex_details_msg = str(exc_obj.message)\n          else:\n              ex_details_msg = str(ex)\n   \n          send_error_log_to_slack = \"\"\n          if line != \"\":\n              send_error_log_to_slack = \" File: *\" + str(path_to_file) + \"* on Line: *\" + str(last_line) + \"* Code: \\n```\" + str(line) + \"``` \\n\"\n          else:\n              send_error_log_to_slack = \"Error on Line Number: \" + str(last_line)\n  \n          return send_error_log_to_slack\n      # end of get_exception_error_message\n\n.. _Inspect the exception: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L36-L61\n.. _inspect the stacktrace: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L38-L42\n.. _exact line that caused the exception: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L42-L47\n.. _build an error report with the source code and the line number: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L54-L58\n\n4. `Send the message to the Slack channel`_\n\n   Post the message to the Slack channel and handle any exceptions.\n\n   .. note:: If your configuration `dictionary object`_ is misconfigured you will likely see an ``unauthorized`` error\n\n.. _Send the message to the Slack channel: https://github.com/jay-johnson/slack-driven-development/blob/3d81ffe3084f91fbdead00218d07f8ec3cc231f5/slack_messenger.py#L70-L76\n.. _dictionary object: https://github.com/jay-johnson/slack-driven-development/blob/78ced381ce1a1594e735943a8a9ab145425fe7d1/slack_driven_development.py#L5-L11\n\nLicense\n-------\n\nThis repository is licensed under the MIT license.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjay-johnson%2Fslack-driven-development","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjay-johnson%2Fslack-driven-development","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjay-johnson%2Fslack-driven-development/lists"}