Skip to content

Commit ad32024

Browse files
committed
fix: remove double-logging from capture_exception -- saves log ingestion cost
capture_exception() was calling logger.error() internally, but every caller (50 call sites) also calls logger.error() before/after it. Result: every error printed to stdout twice, doubling log volume for errors in production log aggregators. Now capture_exception() only sends to Sentry. Callers handle their own logging. Fallback logger.error() only fires when Sentry SDK is not installed (so errors aren't silently lost in local dev). 284 tests pass.
1 parent 84d7cee commit ad32024

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

backend/services/observability.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,20 @@ def add_breadcrumb(message: str, category: str = "custom", level: str = "info",
155155

156156
def capture_exception(error: Exception, **context):
157157
"""
158-
Capture exception with additional context.
158+
Capture exception to Sentry with additional context.
159159
160-
Args:
161-
error: The exception to capture
162-
**context: Additional context to attach
160+
Does NOT log to stdout -- callers are responsible for logging.
161+
This avoids double-logging when callers do logger.error() + capture_exception().
163162
"""
164163
try:
165164
import sentry_sdk
166165
with sentry_sdk.push_scope() as scope:
167166
for key, value in context.items():
168167
scope.set_extra(key, value)
169168
sentry_sdk.capture_exception(error)
170-
171-
# Also log it
172-
logger.error(
173-
f"Exception captured: {type(error).__name__}: {str(error)}",
174-
**context
175-
)
176169
except ImportError:
177-
logger.error(f"Exception: {error}", **context)
170+
# No Sentry -- log as fallback so errors aren't silently lost
171+
logger.error(f"Exception (no Sentry): {type(error).__name__}: {error}", **context)
178172

179173

180174
def capture_message(message: str, level: str = "info", **context):

0 commit comments

Comments
 (0)