Decouple deployment environment from logger level defaults - #215
Conversation
📝 WalkthroughWalkthroughThe change updates logging documentation and comments to state an ChangesLogging configuration alignment
Estimated code review effort: 1 (Trivial) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
@spectrum-ts/core
@spectrum-ts/elysia
@spectrum-ts/express
@spectrum-ts/fastify
@spectrum-ts/hono
@spectrum-ts/imessage
@spectrum-ts/imessage-local
@spectrum-ts/slack
spectrum-ts
@spectrum-ts/telegram
@spectrum-ts/terminal
@spectrum-ts/whatsapp-business
commit: |
There was a problem hiding this comment.
Problem analysis
What this PR is trying to fix
Two related logging design problems, both living in @photon-ai/otel and showing up through Spectrum:
-
Log verbosity was tied to deployment metadata. If
DEPLOYMENT_ENVwas unset ordevelopment, the logger defaulted todebug. That variable is really meant for OpenTelemetry’sdeployment.environmentresource attribute — not for deciding how chatty logs should be. In local/dev (where that env var is often unset), apps could get unexpectedly noisy debug output. -
An explicit SDK setting could lose to an env var. Spectrum’s
options.logLevel(and otel’ssetLogLevel/setupOtel({ logLevel })) were documented and intended as the app’s choice, butLOG_LEVELstill won. That’s surprising for a library API: you set a level in code, and the environment quietly overrides it.
Is the problem valid? Yes. Mixing “what environment am I in?” with “how much should I log?” couples two different concerns. And for an SDK, “explicit option beats ambient env” is the more predictable rule.
Is this the right fix?
Yes — this addresses the root cause, not just a symptom.
The actual behavior change is already in @photon-ai/otel@3.3.0:
- default level is always
info - programmatic level wins over
LOG_LEVEL DEPLOYMENT_ENVonly labels telemetry, and no longer affects log level
This Spectrum PR is the correct consumer follow-up: bump the dependency so Spectrum actually gets that fix, and update Spectrum’s docs/JSDoc so they no longer claim the old defaults and precedence.
That’s the right layering. Spectrum should not re-implement its own log-level policy on top of otel; it should call setLogLevel when the caller passes logLevel, and otherwise let otel’s resolution apply. The existing applyLogLevel helper already does that (it only sets a level when one is provided, so LOG_LEVEL still works as a fallback when Spectrum users don’t pass options.logLevel).
Things to be aware of
These are intentional breaking behavior changes for Spectrum users, even though the diff here looks mostly like docs + a version bump:
- Local/dev will be quieter by default. Anyone who relied on “unset
DEPLOYMENT_ENV⇒ debug logs” will needoptions.logLevel: "debug"orLOG_LEVEL=debug. - Ops can no longer use
LOG_LEVELto override a level set in code. If a host app setsSpectrum({ options: { logLevel: "info" } }),LOG_LEVEL=debugwill not win anymore. That’s the desired SDK-first policy, but deployments that depended on the old order need a heads-up. - The PR title sounds like Spectrum itself decouples these concerns. In practice, Spectrum is adopting the otel fix. That’s fine — just worth saying clearly in the summary so reviewers don’t hunt for logic that isn’t in this repo.
Verdict
Valid problem, right solution. The deeper issue was in otel’s level resolution; that was fixed properly upstream, and this PR correctly wires Spectrum onto that release and keeps the public docs honest. Not a band-aid.
Optional polish (non-blocking): call out the breaking default/precedence change in the Spectrum release notes, and consider a small test that options.logLevel beats LOG_LEVEL so this contract doesn’t regress silently the next time otel is bumped.
Sent by Cursor Automation: PR analyze
| // env var still wins inside @photon-ai/otel. | ||
| // when telemetry is off (the console logger respects it too) and takes | ||
| // precedence over LOG_LEVEL inside @photon-ai/otel. | ||
| applyLogLevel(runtimeOptions?.logLevel); |
There was a problem hiding this comment.
This comment is accurate for the new otel contract, but the behavior change itself is not implemented here — it comes from the @photon-ai/otel ^3.3.0 bump. Worth keeping the docs/comments in sync (as this PR does), and maybe noting in the PR summary that Spectrum is adopting otel#15 rather than re-encoding the policy locally.


Summary
inforegardless of deployment environmentlogLeveloptions take precedence overLOG_LEVEL@photon-ai/otelto 3.3.0 and document the updated behaviorTesting
Not run (not requested)
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Note
Low Risk
Observability-only changes (defaults and docs); local dev may see less
debugoutput unlesslogLevelorLOG_LEVELis set.Overview
Default logging is now always
info, removing the previous behavior where development (DEPLOYMENT_ENV) could default todebug.Precedence for severity is clarified in code and docs: an explicit
options.logLevelonSpectrum()wins over theLOG_LEVELenvironment variable (via@photon-ai/otel), including when telemetry is off.Dependency bump:
@photon-ai/otelis upgraded from^3.1.0to^3.3.0across the root, core, and imessage packages (lockfile also pulls in OTLP metrics export support from that release). Getting started docs note theinfodefault and thelogLevelvsLOG_LEVELordering.Reviewed by Cursor Bugbot for commit 82897cb. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Documentation
info.logLeveltakes precedence over theLOG_LEVELenvironment variable.Behavior