Repository navigation
chore: absorb logger into packages/logger - #14051
ChiragAgg5k wants to merge 166 commits into
Conversation
Co-authored-by: Christy Jacob <[email protected]>
fix: dont throw on log push failure
feat: timeouts
The property comment incorrectly referenced AppSignal's setup path. Updated to reference Raygun's correct API-key location.
Migrate adapters to utopia-php/fetch
mirror.yml replaces test.yml, linter.yml and code-ql-analysis.yml; the issue templates, psalm.xml and composer.lock go; Pint, PHPStan, PHPUnit and Psalm leave require-dev, since the root toolchain is canonical. The README gains the mirror banner and loses the dead Travis badge.
Autoload Utopia\Logger from packages/logger and replace utopia-php/logger. Appwrite has not used the logger since errors moved to spans; it is absorbed for its outside consumers, so there is no root require line to drop. utopia-php/fetch is hoisted to the root until the next commit moves the adapters to client. Step A: flat src/, Utopia\Logger\Tests\ over tests/, the provider suites under tests/E2E/ (skipped without a credential, as messaging's are), PHPUnit 12, a standalone level-max phpstan.neon with a 2-finding baseline, and a standalone rector.php that leaves src as released. User's constructor declares its nullable parameters explicitly, which PHP 8.4 deprecates leaving implicit.
The Sentry, Raygun, AppSignal and LogOwl adapters send their JSON through a PSR-18 client instead of the archived utopia-php/fetch: the default is utopia-php/client's cURL adapter with the same request and connect timeouts and redirects followed, and each constructor takes an optional trailing ClientInterface. The method, URL, auth headers and body bytes are unchanged; a failed request or an unencodable payload still logs the same line and returns 500, and an error status is still logged with its body. Unit tests push a fixed log through a recording client and assert what each adapter sends. The package now requires PHP 8.5, as utopia-php/client does, and utopia-php/fetch leaves the root lock again.
Upstream lines in the README and the adapter tutorial that fail git diff --check.
🔵 Tier A · Mergeable after minor fixes
Imports Utopia Logger into
Fix with agent prompt📂 Walkthrough · 10
Reviewed |
| "php": ">=8.5", | ||
| "psr/http-client": "^1.0", | ||
| "psr/http-message": "^1.1 || ^2.0", | ||
| "utopia-php/client": "^0.5", | ||
| "utopia-php/psr7": "^0.2.1" |
There was a problem hiding this comment.
Account for the default client's cURL extension requirement
utopia-php/client only suggests ext-curl, so Composer can install this package without it, but every default adapter constructor immediately uses cURL constants through new CurlAdapter() and fails with an uncaught Error. Please declare the default backend's extension requirement, or defer initialization and handle its absence if supporting non-cURL injected clients is intentional.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/logger/composer.json
Line: 35-39
Comment:
**Account for the default client's cURL extension requirement**
`utopia-php/client` only suggests `ext-curl`, so Composer can install this package without it, but every default adapter constructor immediately uses cURL constants through `new CurlAdapter()` and fails with an uncaught `Error`. Please declare the default backend's extension requirement, or defer initialization and handle its absence if supporting non-cURL injected clients is intentional.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
🟡 Minor · bug · Reply if this doesn't apply.
| $logger = new Logger($this->invalidAdapter); | ||
|
|
||
| // Should return an error status code without throwing | ||
| $statusCode = $logger->addLog($this->log); | ||
|
|
||
| // Should return > 400 status code | ||
| $this->assertGreaterThan(400, $statusCode); |
There was a problem hiding this comment.
Keep automated failure tests off production provider endpoints
The invalid-credential tests still call the real AppSignal, Raygun, and Sentry services even when no credentials are configured, making the E2E tier depend on their availability and rate limits. This violates AGENTS.md's explicit rule, “Never call production third-party services from automated tests”; use a local endpoint or the recording client for these cases.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/logger/tests/E2E/AdapterBase.php
Line: 110-116
Comment:
**Keep automated failure tests off production provider endpoints**
The invalid-credential tests still call the real AppSignal, Raygun, and Sentry services even when no credentials are configured, making the E2E tier depend on their availability and rate limits. This violates AGENTS.md's explicit rule, “Never call production third-party services from automated tests”; use a local endpoint or the recording client for these cases.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
🟡 Minor · testing · Reply if this doesn't apply.
| // Sentry | ||
| $adapter = new Sentry("[YOUR_SENTRY_DSN]"); | ||
| $logger = new Logger($adapter); | ||
| $logger->addLog($log); |
There was a problem hiding this comment.
Pass the required Sentry constructor arguments in the example
The getting-started example throws ArgumentCountError at new Sentry(...): the constructor requires both a project ID and a key, and does not parse a DSN. Please show those arguments and the host, or parse the DSN as the E2E setup does.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/logger/README.md
Line: 58-61
Comment:
**Pass the required Sentry constructor arguments in the example**
The getting-started example throws `ArgumentCountError` at `new Sentry(...)`: the constructor requires both a project ID and a key, and does not parse a DSN. Please show those arguments and the host, or parse the DSN as the E2E setup does.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
🟡 Minor · documentation · Reply if this doesn't apply.
| To run all unit tests, prepare the `.env` file using `.env.example` as a template. Then, run: | ||
|
|
||
| ```bash | ||
| docker run --rm --interactive --tty --env-file .env \ | ||
| --volume $PWD:/app \ | ||
| composer test |
There was a problem hiding this comment.
Update the standalone QA commands after hoisting the tools
Following the documented install and test commands in the mirror no longer works: require-dev no longer installs PHPUnit, so composer test cannot find phpunit. The later composer check command also references a removed script; please point contributors to bin/monorepo test logger and bin/monorepo check logger in Appwrite instead.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/logger/README.md
Line: 103-108
Comment:
**Update the standalone QA commands after hoisting the tools**
Following the documented install and test commands in the mirror no longer works: `require-dev` no longer installs PHPUnit, so `composer test` cannot find `phpunit`. The later `composer check` command also references a removed script; please point contributors to `bin/monorepo test logger` and `bin/monorepo check logger` in Appwrite instead.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
🟡 Minor · documentation · Reply if this doesn't apply.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
Closing: Appwrite no longer uses |
Summary
Moves
utopia-php/loggerintopackages/logger. Wave 5 of #13828, followingrfc/monorepo.md.loggeris a standalone repository and was never inutopia-php/monorepo, so it gets the full playbook and there is no retire PR. The import is the mirror head132236c(=0.8.0).Appwrite itself no longer uses
Utopia\Logger: it was removed in 1d639e0, when errors started going through spans. The package is absorbed for its outside consumers (open-runtimes/proxy, appwrite-labs/databases, appwrite-labs/pwned, appwrite/docker-geo). So there is no rootrequireline to remove; the root only gains the autoload, autoload-dev andreplaceentries every package has.logger 0.8.0 requires
utopia-php/fetch ^1.1, which is archived. This PR moves the four adapters toutopia-php/client(PSR-18), as #13955 did for audit.Important
Merge with a merge commit, not a squash. A squash drops the
git-subtree-*annotation and orphans the package from its mirror.Commits
Add 'packages/logger/' from commit '132236c…'mainwith full historychore(logger): mirror plumbingmirror.ymlreplacestest.yml,linter.yml,code-ql-analysis.yml; issue templates,psalm.xmlandcomposer.lockremoved; Pint, PHPStan, PHPUnit and Psalm stripped fromrequire-dev; README banner; dead Travis badge droppedrefactor: load logger from packages/utopia-php/fetchto the root for this one commit so it validatesrefactor(logger): replace utopia-php/fetch with clientutopia-php/client, with unit tests;utopia-php/fetchleaves the root againstyle(logger): strip trailing whitespace from the docsgit diff --checkWhat changed
composer.jsonreplaceentries added. Norequirechange (Appwrite never required logger after 1d639e0)psr/http-clientandpsr/http-messageare already in the rootrequire;clientandpsr7are inpackages/composer.lockutopia-php/fetchis added in commit 3 and removed in commit 4src/src/Logger/*moved up tosrc/. Otherwise Pint (publicon class constants) andLog\User's constructor declaring its nullable parameters as?string(PHP 8.4 deprecates the implicit form, and Appwrite runs 8.5). Commit 4 is the only other changetests/LogTest,Log/{Breadcrumb,User}TestunderUtopia\Logger\Tests\, plus the newAdapter/*Test(below)tests/E2E/Utopia\Logger\Tests\E2E\. They push to the real Sentry, Raygun, AppSignal and LogOwl APIs; the success cases now skip withoutTEST_SENTRY_DSN/TEST_RAYGUN_KEY/TEST_APPSIGNAL_KEY/TEST_LOGOWL_KEY(as messaging's do) instead of failing, and the invalid-credential cases still runphpunit.xmlunitistestsminustests/E2E,e2eistests/E2E. Nodocker-compose.yml: the e2e tier needs no servicescomposer.jsontest/test:e2escripts;minimum-stability: stablephpstan.neonsrcandtests, withphpstan-baseline.neonholding 2 findings, both inLog::mask(). Added to the RFC phase 8 listrector.phpwithPhpSets()+typeDeclarations; skips the 7 rules that would rewritesrc. Constructor promotion in particular would rename named arguments (new Sentry(key: …)→sentryKey:)fetch → client
Each adapter built a fetch
Clientperpush(). It now holds a PSR-18 client and sends a PSR-7 request.new Client()per push, fresh cURL handlenew Client(new CurlAdapter())built once in the constructor, connection reuse off (a fresh handle per request)setTimeout($timeout * 1000)/setConnectTimeout($connectTimeout * 1000)withTimeout($timeout)/withConnectTimeout($connectTimeout), same secondswithFollowRedirects(), max 50 (see below)addHeader('Content-Type', 'application/json'), array body JSON-encoded by fetchjson_encode()(same flags) andRequestFactory::body(Method::POST, …, ContentType::JSON, $headers)X-Sentry-Auth,X-ApiKeyviaaddHeader()Utopia\Fetch\Exception→ logged,500500, nothing sentUtopia\Fetch\Exceptionon network errors → logged,500Psr\Http\Client\ClientExceptionInterface(and a URI the parser rejects) → same log line,500$response->text()in the error-status log(string) $response->getBody()Each constructor gains an optional trailing
?ClientInterface $client = null, so the request each adapter sends is unit tested through a recording PSR-18 double (tests/Adapter/Client.php, the same shape as audit's): method, URL,Content-Type, auth headers and the full decoded body for all four, the default hosts for Sentry and LogOwl, the error-status log line, network failure →500, and an unencodable payload →500with no request sent. Reverting the Raygun header or the Sentry path turns them red.I also pushed the same log through the fetch version (commit 3) and this one against a local echo server, for Sentry and LogOwl (the two that take a host). Method, path,
Content-Lengthand the body bytes are identical, as are the logged error lines. Remaining differences:content-type,x-sentry-auth(fetch lowercases)Content-Type,X-Sentry-Auth(case-insensitive on the wire)Accept-EncodingAccept-Encodingadvertised, decoded transparentlyThe 5-hop cap does not carry over for the same reason as in #13955:
withFollowRedirects(maxHops:)is only onpackages/clienthead (#13910), not in the releasedclient0.5.1 that the package's registry-resolved job installs. It can come back withmaxHops: 5onceclient0.6.0 is out.The log lines keep their "push failed with fetch error:" wording so anything matching on them keeps working.
Consumer impact
The switch raises the package's floor to PHP 8.5 (
utopia-php/clientrequires it) and replacesutopia-php/fetchwithutopia-php/client+utopia-php/psr7, so it needs a minor release. Every consumer pins a range that will not pick it up on its own:>=8.0.00.7.*0.8.*>=8.5.0^0.8>=8.3.0^0.7.1Validation
bin/monorepo validatefetchhoisted)bin/monorepo check logger --fixbin/monorepo test logger(registry-resolved:client0.5.1,psr70.2.2), unitbin/monorepo test logger, e2evendor/bin/phpunit --testsuite packagesinappwrite/appwrite:2.3.0logger: theagentsDiffCheckTestcases (the worktree's.gitis outside the container mount)… --testsuite packages --filter 'Utopia\\Logger\\Tests'inappwrite/appwrite:2.3.0Utopia\Logger\Adapter\Sentryresolves topackages/logger/src/Adapter/Sentry.php; novendor/utopia-php/loggerorvendor/utopia-php/fetchcomposer validate --no-check-publishcomposer lintbin/monorepo split logger --dry-run2ae51d9, fast-forward of the mirror head132236c(+4 commits)git diff --checkNo E2E test covers the real providers' success path here: there are no provider credentials in this environment or in CI.
Mirror state
absorbcreated the canonicalmainruleset (id24307517): no deletion, no force push, PRs required with 0 approvals; the split app (4016286) always bypassesmainSplit: push restrictions to theOwnersteam only (no apps), 1 required approving review,enforce_adminson. Unlike audit's, it has no allowance for the split app. Before merge, remove it (as was done forbalancer) or add the split app to its restrictionsAfter merge
Splitrun forloggeris green and the mirror fast-forwards from132236c(needs the branch protection fix above)bin/monorepo release logger 0.9.0: the dependency surface changed (fetch→client+psr7, PHP 8.5)client0.6.0maxHops: 5loggernever lived inutopia-php/monorepoOpen on utopia-php/logger:
event_idin Sentry Adapter so it also works with GlitchTiputopia-php/logger#52 is fixed by this PR (measured above). #27 and #24 refer to Rollbar and HoneyBadger adapters that are not in the package. Nothing is ported here; anything still wanted gets re-opened against
packages/logger/src/(paths lost theLogger/segment).🤖 Generated with Claude Code