Skip to content

feat: enhance structured logging with service context and dynamic levels#1168

Merged
pirosiki197 merged 1 commit intomainfrom
feat/slog-service-context
Mar 8, 2026
Merged

feat: enhance structured logging with service context and dynamic levels#1168
pirosiki197 merged 1 commit intomainfrom
feat/slog-service-context

Conversation

@pirosiki197
Copy link
Copy Markdown
Contributor

@pirosiki197 pirosiki197 commented Mar 8, 2026

なぜやるか

ログにservice.nameservice.versionがあると、見たときにわかりやすい

やったこと

service.nameservice.versionをログに含めた

やらなかったこと

資料

Summary by CodeRabbit

リリースノート

  • New Features

    • ログレベルをランタイムで動的に調整できるようになりました。
  • Refactor

    • ロギング初期化プロセスを改善し、サービス名、バージョン、リビジョン情報をログコンテキストに含めるようになりました。

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

Preview (prod backend + PR dashboard) → https://1168.ns-preview.trapti.tech/

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

ウォークスルー

ロギングの初期化フローを再構成し、main関数での早期初期化から、根コマンドのPersistentPreRunでのサービス名に基づく遅延初期化に変更しました。InitLoggerの署名を変更してサービスメタデータを受け取り、ランタイムレベル調整にSetLogLevelを導入し、PrintVersionファンクションを削除しました。

変更内容

コホート / ファイル 概要
ロギング初期化の実装
pkg/util/slogutil/init.go, pkg/util/slogutil/logger.go
古いInitLoggerを削除し、サービス名、バージョン、リビジョンのメタデータを受け取る新しいInitLoggerを実装。SetLogLevelを追加してランタイムでのログレベル変更をサポート。
CLIコマンド初期化
cmd/main.go
根コマンドのPersistentPreRunを修正し、PrintVersionの呼び出しをインラインのサービス名導出とInitLoggerの呼び出しに置き換え。
ログレベルフラグ
pkg/util/cli/flag.go
SetupDebugFlagとSetupLogLevelFlagのOnInitializeで、InitLoggerの呼び出しをSetLogLevelに変更。
バージョン情報出力
pkg/util/cli/version.go
PrintVersionファンクションと関連インポート(log/slog、github.com/spf13/cobra)を削除。

推定コード審査工数

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、変更内容の主要な目的「サービスコンテキストと動的ログレベル機能の強化」を明確に要約しており、正確かつ具体的です。
Description check ✅ Passed プルリクエスト説明は必須セクション「なぜやるか」「やったこと」「やらなかったこと」「資料」をすべて含んでいます。ただしいくつかのセクションは最小限の内容です。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/slog-service-context

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pirosiki197 pirosiki197 enabled auto-merge March 8, 2026 14:28
@pirosiki197 pirosiki197 merged commit 3cc7562 into main Mar 8, 2026
15 of 16 checks passed
@pirosiki197 pirosiki197 deleted the feat/slog-service-context branch March 8, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant