From 5158dc6d4040d0ef73a2e2156a26b105b722f49f Mon Sep 17 00:00:00 2001 From: Matt Kafonek Date: Wed, 26 Apr 2023 13:43:45 -0400 Subject: [PATCH] better error logs in datadog (#104) * better error logs in datadog * changelog * prepare 0.3.0 release (#105) --- CHANGELOG.md | 3 +++ pyproject.toml | 2 +- sending/base.py | 24 ++++++++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cbf9be..e22554d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.3.0] - 2023-04-26 ### Added - Standard Noteable open source patterns - Contributing / Code of Conduct files @@ -21,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `WebsocketManager` backend uses vanilla `logging` instead of `structlog`, remove need for `structlog` dependency once `managed-service-fixtures` also drops it - `JupyterBackend` introduce a short sleep in its poll loop while investigating 100% CPU usage - `JupyterBackend` zmq polling changed fairly significantly to avoid missing messages while reconnecting socket after a max message size disconnect +- Try to include tracebacks during exception logs for inbound / outbound / process workers ## [0.2.2] - 2022-07-28 ### Changed diff --git a/pyproject.toml b/pyproject.toml index bbbeed6..f5012fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sending" -version = "0.2.2" +version = "0.3.0" description = "Library for pub/sub usage within an async application" authors = ["Nicholas Wold "] diff --git a/sending/base.py b/sending/base.py index ccf9dbe..db06649 100644 --- a/sending/base.py +++ b/sending/base.py @@ -13,6 +13,7 @@ import abc import asyncio import enum +import traceback from collections import defaultdict, namedtuple from functools import partial, wraps from typing import Callable, Dict, List, Optional, Set @@ -302,8 +303,11 @@ async def _outbound_worker(self): message = message._replace(contents=await coro(message.contents)) logger.debug(f"Sending message to topic: {message.topic}") await self._publish(message) - except Exception: - logger.exception("Uncaught exception found while publishing message") + except Exception as e: + tb_str = traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__) + logger.exception( + "Uncaught exception found while publishing message", exc_info="".join(tb_str) + ) finally: self.outbound_queue.task_done() @@ -334,8 +338,12 @@ async def _inbound_worker(self): await asyncio.gather( *[self._delegate_to_callback(message, cb_id) for cb_id in callback_ids] ) - except Exception: - logger.exception("Uncaught exception found while processing inbound message") + except Exception as e: + tb_str = traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__) + logger.exception( + "Uncaught exception found while processing inbound message", + exc_info="".join(tb_str), + ) finally: self.inbound_queue.task_done() @@ -360,8 +368,12 @@ async def _delegate_to_callback(self, message: QueuedMessage, callback_id: UUID) logger.debug( f"Skipping callback '{cb.qualname}' because predicate returned False" ) - except Exception: - logger.exception("Uncaught exception encountered while delegating to callback") + except Exception as e: + tb_str = traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__) + logger.exception( + "Uncaught exception encountered while delegating to callback", + exc_info="".join(tb_str), + ) async def _poll_loop(self): while True: