Repository navigation
docs: document errorlog footgun and logging util usage (#1286) #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
75787b9
docs: add logging utility guide with errorLog footgun
LucasSantana-Dev e942bcd
Merge branch 'main' into docs/1286-errorlog-footgun
LucasSantana-Dev d01504b
Merge branch 'main' into docs/1286-errorlog-footgun
LucasSantana-Dev 98a425d
docs: correct sentry level claim in errorlog footgun doc
LucasSantana-Dev 7023bf5
Merge branch 'docs/1286-errorlog-footgun' of https://github.com/Lucas…
LucasSantana-Dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # Logging | ||
|
|
||
| Lucky uses shared logging utilities that forward errors to Sentry for observability. This document describes correct usage and a common footgun to avoid. | ||
|
|
||
| ## The logging utils | ||
|
|
||
| The shared logging layer (`packages/shared/src/utils/general/log/`) exports four main functions: | ||
|
|
||
| - **`errorLog(params)`** — logs an error and sends it to Sentry; call when an exceptional condition occurs. | ||
| - **`warnLog(params)`** — logs a warning and adds a breadcrumb; use for expected fallbacks or degradation. | ||
| - **`infoLog(params)`** — logs informational messages; adds a breadcrumb. | ||
| - **`debugLog(params)`** — logs debug-level messages; respects the configured log level. | ||
|
|
||
| All accept a `LogParams` object: | ||
|
|
||
| ```typescript | ||
| type LogParams = { | ||
| message: string // Required: human-readable message | ||
| error?: unknown // Optional: the caught exception or error object | ||
| data?: unknown // Optional: structured context (guildId, userId, etc.) | ||
| correlationId?: string // Optional: request or operation id for tracing | ||
| } | ||
| ``` | ||
|
|
||
| ## The footgun: errorLog without the error object | ||
|
|
||
| Calling `errorLog({ message: "..." })` with only a message (omitting the `error` property) **silently degrades to an info-level event in Sentry**, losing the error context and stack trace. | ||
|
|
||
| The service checks whether `params.error` exists (line 106 in `service.ts`): | ||
|
|
||
| - **If `error` is present**: calls `captureException()` → Sentry receives a full exception with stack. | ||
| - **If `error` is absent**: calls `captureMessage()` with level `'error'` → **Sentry receives a message, not an exception**, and the context is much weaker for debugging. | ||
|
|
||
| ## Correct pattern | ||
|
|
||
| Always include the error object when calling `errorLog`: | ||
|
|
||
| ```typescript | ||
| // ✅ CORRECT — Sentry captures the full exception + stack | ||
| try { | ||
| await spotifyApi.search(query) | ||
| } catch (err) { | ||
| errorLog({ | ||
| message: 'Spotify search failed', | ||
| error: err, | ||
| data: { query, guildId: ctx.guildId } | ||
| }) | ||
| return fallback | ||
| } | ||
| ``` | ||
|
|
||
| ```typescript | ||
| // ❌ INCORRECT — Sentry records only a message; stack is lost | ||
| catch (err) { | ||
| errorLog({ | ||
| message: 'Spotify search failed' | ||
| }) | ||
| return fallback | ||
| } | ||
| ``` | ||
|
|
||
| For expected fallbacks (e.g., feature-toggle off, timeout, retrying), use `warnLog` instead: | ||
|
|
||
| ```typescript | ||
| // ✅ CORRECT for degradation | ||
| if (!featureToggle.enabled) { | ||
| warnLog({ message: 'Feature disabled, using fallback' }) | ||
| return fallback | ||
| } | ||
| ``` | ||
|
|
||
| ## Structured context | ||
|
|
||
| Include relevant IDs and state in the `data` field for better debugging: | ||
|
|
||
| ```typescript | ||
| errorLog({ | ||
| message: 'Discord API rate-limited', | ||
| error: err, | ||
| data: { | ||
| guildId: guild.id, | ||
| userId: user.id, | ||
| operation: 'getUserGuilds', | ||
| retryAfter: err.response?.headers?.['retry-after'] | ||
| } | ||
| }) | ||
| ``` | ||
|
|
||
| ## Related decision | ||
|
|
||
| See ADR [2026-06-01 — logging-observability-hardening](../decisions/2026-06-01-logging-observability-hardening.md) for the full logging strategy, including silent-catch enforcement (ESLint rule) and request-id threading. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.