feat(logging): [4/4] DB connection-error logging middleware (database channel)#478
Merged
turegjorup merged 17 commits intoJun 9, 2026
Conversation
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 08:15
6049208 to
b751a5d
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 08:16
e3f9c6b to
9f92726
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 08:27
b751a5d to
db66d92
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 08:27
9f92726 to
6e2ef9f
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 08:46
db66d92 to
0c8f2ca
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 08:47
6e2ef9f to
ef3ee54
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 08:52
0c8f2ca to
57d45c1
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 08:53
ef3ee54 to
79c07ce
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 08:59
57d45c1 to
f174bae
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 09:00
79c07ce to
214d30c
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
2 times, most recently
from
June 3, 2026 11:14
dd333e7 to
54c7952
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 11:16
214d30c to
f0fa004
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
2 times, most recently
from
June 3, 2026 12:10
ae123e3 to
d030c28
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 12:10
f0fa004 to
5173e6c
Compare
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 21:03
d030c28 to
e57f37b
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 21:05
5173e6c to
940ed3e
Compare
…hannel Add the `database` Monolog channel and a DBAL driver middleware that logs connection failures so operators without database access get a signal (ADR 011). Logging-only — no reconnect/retry. - ConnectionErrorDriver wraps connect() and reads the raw driver error code (a middleware sits below DBAL's exception conversion, which does not classify 1040/1203/2003 as ConnectionException). Connection-pressure / unreachability codes log at critical, other connect failures at error. The original exception is rethrown unchanged; only the host is logged, never the password or DSN. - Register the middleware with the explicit doctrine.middleware tag (the bundle collects tagged services; implementing the interface is not enough) and bind the database channel. - Add a prod per-channel handler for `database` (LOG_LEVEL_DATABASE with the LOG_LEVEL fallback) and document the event=db.connection_error shape. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
turegjorup
force-pushed
the
feature/logging-phpstan-gate
branch
from
June 3, 2026 21:31
e57f37b to
22ea6f9
Compare
turegjorup
force-pushed
the
feature/db-connection-error-logging
branch
from
June 3, 2026 21:31
940ed3e to
8cb3bb0
Compare
…to feature/db-connection-error-logging # Conflicts: # CHANGELOG.md
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
… channel Rename ConnectionErrorMiddleware's injected logger $logger -> $databaseLogger so the constructor self-documents its channel; binding key updated to match. ConnectionErrorDriver keeps its positional $logger (not a channel-bound service). No behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… db.response.status_code The database connection-error record now carries an OTel-compliant categorisation: error.type holds a stable low-cardinality token (too_many_connections, access_denied, …) mapped from the driver code, falling back to the stringified code when unmapped. The verbose driver text remains in exception.message. Also rename the bespoke db.error_code to the OTel database semantic-convention attribute db.response.status_code (emitted as a string). Doc table and ConnectionErrorDriver test updated accordingly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…to feature/db-connection-error-logging
The database channel has its own always-on handler; add it to the main handler's channel blacklist so a critical connection error isn't emitted twice (see the per-channel duplicate-emission fix). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ion host There is no db.host OTel attribute; connection host/port are the general server.address / server.port attributes. Rename db.host -> server.address (host only, never password/DSN) and emit server.port conditionally (omit-when-absent, per OTel). Doc table and driver test updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
…to feature/db-connection-error-logging
tuj
approved these changes
Jun 9, 2026
…to feature/db-connection-error-logging
Base automatically changed from
feature/logging-phpstan-gate
to
feature/structured-logging-semconv
June 9, 2026 14:09
turegjorup
merged commit Jun 9, 2026
c442096
into
feature/structured-logging-semconv
25 checks passed
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.
PR 4 of 4 — Structured logging
Final PR of the series. Base is
feature/logging-phpstan-gateuntil the earlier PRs merge, then retargets torelease/3.0.0.Logs MariaDB connection-establishment failures from the application layer so operators without database access get a failure signal (ADR 011). Logging-only — no reconnect/retry.
What this PR does
databasechannel — added tomonolog.yamland a prod per-channel handler (LOG_LEVEL_DATABASE, sameLOG_LEVELfallback,LOG_PATHdestination).ConnectionErrorMiddleware+ConnectionErrorDriver— a DBAL driver middleware wrappingconnect(). It reads the raw driver error code, because a middleware sits below DBAL's exception conversion, which does not classify1040(too many connections),1203,2003(connection refused), etc. asConnectionException. Fires for every SAPI (web, CLI, Messenger) regardless of whether app code later swallows the exception.1040,1203,1226,2002,2003,2005) →critical; other connect failures (e.g.1045credentials) →error.event=db.connection_error,db.error_code,db.sqlstate,db.host(host only — never password/DSN), and the exception under theexceptionkey.doctrine.middlewaretag (doctrine-bundle collects tagged services inMiddlewaresPass; implementing the interface alone isn't enough), bound to@monolog.logger.database. Confirmed present on the default connection viadebug:container --tag=doctrine.middleware.docs/logging.mdgains thedatabasechannel and theevent=db.connection_errorshape.Mid-query drops (
2006/2013) are out of scope (establishment only), per ADR 011.Verification
composer code-analysis— greencomposer coding-standards-check+ env-coverage — greencomposer test— 180 tests, green (addedConnectionErrorDriverTest: a stub driver throwsDriver\Exceptionwith code2003→critical /1045→error; asserts channel, level,db.*keys, and no secret-bearing keys)cache:clear --env=prod— handler + middleware wiring resolve🤖 Generated with Claude Code