fix: honor LOG_LEVEL in hub-worker - #115
Closed
xernobyl wants to merge 1 commit into
Closed
Conversation
hub-worker never configured slog, so it ran on Go's default handler at info
regardless of LOG_LEVEL, while hub-api honored it. That matters for ENG-1916
specifically: when a missing enrichment credential takes down the worker, the
worker's logs are the only place the actionable error appears, and its debug
lines were unreachable.
Move the level parsing and handler setup into internal/observability, which
already owns the logging handler, and call it from both entrypoints. Living
there also means the logic is covered by make test-unit, which runs ./cmd/api
and ./internal/... but not ./cmd/worker.
Note for operators: this changes hub-worker's log stream and format, not just
its level. It previously used Go's default handler, which writes to stderr as
2026/07/28 10:37:10 INFO Worker running client_id=...
and now matches hub-api, writing to stdout as
time=2026-07-28T10:37:10.962Z level=INFO msg="Worker running" client_id=...
Container log collection is unaffected, but anything parsing hub-worker output
or separating stderr from stdout needs updating. hub-api is unchanged,
including configuring logging before reporting a config-load failure so a
broken config still produces output. Unrecognized levels keep falling back to
info.
Contributor
Author
|
Folded into #114 — the log-level commit is now the fifth commit there, so this is redundant. Closing. Kept as its own commit in #114, and #114's description now carries the operator heads-up about the worker's stream and format change (stderr → stdout, default handler → |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
hub-workernever configuredslog, so it ignoredLOG_LEVELentirely and ran on Go's default handler, whilehub-apihonored it. SettingLOG_LEVEL=erroron the worker did nothing.It's a bit worse than just the level being ignored: because the worker was on the default handler and the API on a configured
TextHandler, the two processes emitted different formats to different streams. Same deployment, same image, two log shapes.This came out of ENG-1916 (hub#114), where a missing enrichment credential takes down
hub-worker. After that change the worker's logs become the only place the actionable error appears, so it matters that they're readable and that debug is reachable. Splitting it out from #114 since it's an independent concern and, as below, it changes output that people may be parsing.The level parsing and handler setup move into
internal/observability, which already owns the logging handler (TraceContextHandler), and both entrypoints call it. Living there also means the logic is actually covered bymake test-unit, which runs./cmd/apiand./internal/...but not./cmd/worker.Heads-up for operators — output changes, not just the level
hub-workerpreviously wrote to stderr as:and now matches
hub-api, writing to stdout as:Container log collection is unaffected (both streams are captured), but anything parsing
hub-workeroutput, or relying on stderr/stdout separation, needs updating. Worth a line in the release notes.hub-apibehavior is unchanged, including that it configures logging before reporting a config-load failure so a broken config still produces output — the worker now does the same. Unrecognized levels still fall back to info rather than silencing logs, which felt like the safer default for a typo'd env var.One small oddity preserved rather than fixed: only the exact string
warnmatches, soLOG_LEVEL=warningfalls back to info. That's pre-existing; I pinned it in a test rather than changing it, but happy to make it acceptwarningif people think that's a trap.How should this be tested?
The behavior is easiest to see as a before/after against a released image. With any valid
DATABASE_URLandAPI_KEY, run the worker briefly withLOG_LEVEL=error:ghcr.io/formbricks/hub:0.8.1→ still printsINFOlines (2026/07/28 ... INFO Worker running ...), i.e.LOG_LEVELignored, default-handler format.INFO, and withLOG_LEVELunset printstime=... level=INFO msg="Worker running" ..., matchinghub-api.ParseLogLevelitself is covered by a table test ininternal/observability/logging_test.go, including the casing and unknown-value fallbacks.Checklist
Required
make buildmake tests(integration tests intests/) — not run for this change; it touches no DB or job path, andmake test-unitcovers the added logicmake fmtandmake lint; no new warningsgit pull origin mainmigrations/— n/a, no schema changeAppreciated
docs/if changes were necessary — n/a, though the stream/format change above is worth a release notemake tests-coverage— n/a for a change this size; the new logic has a direct unit test