Log ownership: a raising frame must not log the traceback
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 71/100
- issue の種類
- リファクタリング
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- kafka, postgresql, python
調査の方向性
まず adr/002-observability/002-observability.md を読み、その後 src/writers/writer_kafka.py、src/writers/writer_postgres.py、src/writers/writer_eventbridge.py、src/handlers/handler_topic.py、src/handlers/handler_token.py の例外およびログの経路を調査してください。各ログ出力された例外を呼び出し元(_write_to_all()、dispatch_request()、_refresh_keys_if_needed())まで追跡し、traceback の責任をどこに持たせるべきかを確認してください。これらのフローの unit test を追加または更新し、ログレベルごとの件数を検証してください。受け入れ条件は、書き込みに失敗した場合に集約された ERROR が 1 件、writer ごとに WARNING が 1 件、アクセス設定がない場合に ERROR が正確に 1 件、リクエストが成功した場合のトークン更新時には ERROR が発生しないことです。
索引モデルが issue の本文から書いたものです。
説明
Description of Technical Debt
ADR-002 states the invariant an ERROR alarm depends on: among records emitted during a single invocation, the count of ERROR records equals the count of 5xx responses the service built to report a failed request.
Three sites break it today, each the same way — a frame logs at ERROR and then lets the exception escape to a frame that logs it again:
| Site | Today | Effect |
|---|---|---|
src/writers/writer_kafka.py, writer_postgres.py, writer_eventbridge.py |
ERROR before raise WriteError |
Writer ERROR + _write_to_all() WARNING + aggregate ERROR = two ERROR records for one failed write, and on exception paths the same traceback twice |
src/handlers/handler_topic.py, missing access config |
ERROR before raise RuntimeError |
Handler ERROR + boundary logger.exception = two ERROR for one 500 |
src/handlers/handler_token.py, with_public_keys_queried() |
logger.exception before raise RuntimeError |
_refresh_keys_if_needed() catches it at WARNING and the request still succeeds: one ERROR, zero 5xx |
Impact of Technical Debt
- An alarm on
level = "ERROR"counts log lines, not failed requests. One failed Postgres write reads as two failures, so any future alerting or EMF metric built on the ERROR count is inflated from day one. - The
handler_tokencase is the inverse and worse: a token refresh that fails but recovers emits anERRORon a request that returns 2xx, so the ERROR count also has false entries unrelated to any failure. - The same traceback is written two or three times per failed write, inflating CloudWatch cost on exactly the requests that are already the most expensive to log.
- ADR-002 documents the invariant as the contract. Until these are fixed, the code and the ADR disagree, which is a trap for the next person wiring up monitoring.
Category
Code Quality / Refactoring
Priority
Medium - Should be addressed soon
Proposed Solution
The fix is ownership, not level. Downgrading the writers to WARNING is not enough: _write_to_all() already emits a WARNING carrying the same traceback, so the duplicate simply moves one level down.
Apply the rule ADR-002 §Attaching tracebacks states:
A traceback is logged exactly once, by the frame that converts the exception into a response or swallows it. A frame that wraps and re-raises does not log it above
DEBUG.
Concretely:
- Writers — drop the
ERRORbeforeraise WriteError. Useraise WriteError(...) from excsoexc_info=Trueon the caller'sWARNINGformats the full__cause__chain; nothing is lost. ADEBUGbreadcrumb is acceptable where the writer knows something the caller does not. handler_topic, missing access config — drop thelogger.error; the boundarylogger.exceptionindispatch_request()already owns that record.handler_token.with_public_keys_queried()— drop thelogger.exceptionentirely. The function cannot know whether its caller treats the failure as fatal (initialization) or recoverable (refresh), so the decision belongs to the callers: the init path logsERROR,_refresh_keys_if_needed()keeps its existingWARNING.
Effort Estimate
1 day, including test updates
Dependencies / Related
- ADR-002 §Logging strategy and §Attaching tracebacks (
adr/002-observability/002-observability.md) - #193
- PR #204
- #220 — the other invariant gap found in the same review
Additional Context
Acceptance:
- A failed write emits exactly one
ERROR(the aggregate) and oneWARNINGper failing writer. - A 500 from missing access configuration emits exactly one
ERROR. - A failed token refresh that still returns 2xx emits no
ERROR. - Unit tests assert the record counts per level, not just the messages, so a regression fails the build rather than quietly re-inflating the count.
- 主要言語
- Python
- スター
- 4
- フォーク
- 0
- 平均マージ
- 3日 7時間
- マージ済み PR(30日)
- 11
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
AbsaOSS/EventGate のほかの issue
-
refactoring type:tech-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 32/100
メンテナーはふだん 2 日以内に返信
-
infrastructure type:tech-debt
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
AbsaOSS/EventGate の issue をすべて見る
似ている issue
-
Quantized sample scoring and slicing discard the configured epsilon gap対応中かも @sylvesterkaczmarek が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google-deepmind/distrax#364 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 66/100
suitenumerique/conversations#798 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
fabriziosalmi/certmate#1207 ·
メンテナーはふだん 1 日以内に返信
-
[work-item] adam-adae-onset-emergence: document the minute-precision datetime coercion (ASTTMF not derivable)対応中かも @muse-yamaa-bot が今日担当しました。 オープンwork-item
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信