Skip to content

chore: absorb logger into packages/logger - #14051

Closed
ChiragAgg5k wants to merge 166 commits into
mainfrom
chore/absorb-logger
Closed

ChiragAgg5k wants to merge 166 commits into
mainfrom
chore/absorb-logger

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

Moves utopia-php/logger into packages/logger. Wave 5 of #13828, following rfc/monorepo.md. logger is a standalone repository and was never in utopia-php/monorepo, so it gets the full playbook and there is no retire PR. The import is the mirror head 132236c (= 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 root require line to remove; the root only gains the autoload, autoload-dev and replace entries every package has.

logger 0.8.0 requires utopia-php/fetch ^1.1, which is archived. This PR moves the four adapters to utopia-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

Commit What
Add 'packages/logger/' from commit '132236c…' Subtree import from the mirror main with full history
chore(logger): mirror plumbing mirror.yml replaces test.yml, linter.yml, code-ql-analysis.yml; issue templates, psalm.xml and composer.lock removed; Pint, PHPStan, PHPUnit and Psalm stripped from require-dev; README banner; dead Travis badge dropped
refactor: load logger from packages/ Root wiring, step A shape, QA config, RFC baseline line. Hoists utopia-php/fetch to the root for this one commit so it validates
refactor(logger): replace utopia-php/fetch with client The adapters move to utopia-php/client, with unit tests; utopia-php/fetch leaves the root again
style(logger): strip trailing whitespace from the docs Two upstream lines that fail git diff --check

What changed

Area Change
Root composer.json Autoload, autoload-dev and replace entries added. No require change (Appwrite never required logger after 1d639e0)
Hoisting Nothing new: psr/http-client and psr/http-message are already in the root require; client and psr7 are in packages/
composer.lock Content hash only. utopia-php/fetch is added in commit 3 and removed in commit 4
src/ src/Logger/* moved up to src/. Otherwise Pint (public on class constants) and Log\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 change
Unit tier tests/ LogTest, Log/{Breadcrumb,User}Test under Utopia\Logger\Tests\, plus the new Adapter/*Test (below)
tests/E2E/ The four provider suites under Utopia\Logger\Tests\E2E\. They push to the real Sentry, Raygun, AppSignal and LogOwl APIs; the success cases now skip without TEST_SENTRY_DSN / TEST_RAYGUN_KEY / TEST_APPSIGNAL_KEY / TEST_LOGOWL_KEY (as messaging's do) instead of failing, and the invalid-credential cases still run
phpunit.xml PHPUnit 12; unit is tests minus tests/E2E, e2e is tests/E2E. No docker-compose.yml: the e2e tier needs no services
composer.json test / test:e2e scripts; minimum-stability: stable
phpstan.neon Standalone, level max over src and tests, with phpstan-baseline.neon holding 2 findings, both in Log::mask(). Added to the RFC phase 8 list
rector.php Standalone, withPhpSets() + typeDeclarations; skips the 7 rules that would rewrite src. Constructor promotion in particular would rename named arguments (new Sentry(key: …) → sentryKey:)

fetch → client

Each adapter built a fetch Client per push(). It now holds a PSR-18 client and sends a PSR-7 request.

fetch client
new Client() per push, fresh cURL handle new 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 seconds
follows redirects, max 5 withFollowRedirects(), max 50 (see below)
addHeader('Content-Type', 'application/json'), array body JSON-encoded by fetch json_encode() (same flags) and RequestFactory::body(Method::POST, …, ContentType::JSON, $headers)
X-Sentry-Auth, X-ApiKey via addHeader() same headers on the request
encoding failure → Utopia\Fetch\Exception → logged, 500 encoding failure → same log line, 500, nothing sent
Utopia\Fetch\Exception on network errors → logged, 500 Psr\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 → 500 with 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-Length and the body bytes are identical, as are the logged error lines. Remaining differences:

Where Before After
Header name casing content-type, x-sentry-auth (fetch lowercases) Content-Type, X-Sentry-Auth (case-insensitive on the wire)
All requests no Accept-Encoding Accept-Encoding advertised, decoded transparently
Redirect cap 5 hops 50 hops
Open file descriptors each push leaks its cURL handle and socket until the cycle collector runs (utopia-php/logger#52): 50 pushes with GC off went from 6 to 206 fds 50 pushes with GC off stay at 6

The 5-hop cap does not carry over for the same reason as in #13955: withFollowRedirects(maxHops:) is only on packages/client head (#13910), not in the released client 0.5.1 that the package's registry-resolved job installs. It can come back with maxHops: 5 once client 0.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/client requires it) and replaces utopia-php/fetch with utopia-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:

Consumer PHP logger
open-runtimes/proxy >=8.0.0 0.7.*
appwrite-labs/databases (none) 0.8.*
appwrite-labs/pwned >=8.5.0 ^0.8
appwrite/docker-geo >=8.3.0 ^0.7.1

Validation

Check Result
bin/monorepo validate all packages valid (also at commit 3, with fetch hoisted)
bin/monorepo check logger --fix Rector, Pint, PHPStan level max (with baseline) pass
bin/monorepo test logger (registry-resolved: client 0.5.1, psr7 0.2.2), unit 19 tests / 87 assertions OK
bin/monorepo test logger, e2e 12 tests: 4 pass (the invalid-credential pushes against the real AppSignal, LogOwl, Raygun and Sentry endpoints return 401 / DNS failure / 403 / 429), 8 skipped (no provider credentials)
vendor/bin/phpunit --testsuite packages in appwrite/appwrite:2.3.0 Completes: 9048 tests. 5 errors, none in logger: the agents DiffCheckTest cases (the worktree's .git is outside the container mount)
… --testsuite packages --filter 'Utopia\\Logger\\Tests' in appwrite/appwrite:2.3.0 19 tests / 87 assertions OK
Utopia\Logger\Adapter\Sentry resolves to packages/logger/src/Adapter/Sentry.php; no vendor/utopia-php/logger or vendor/utopia-php/fetch
composer validate --no-check-publish valid
composer lint passes
bin/monorepo split logger --dry-run 2ae51d9, fast-forward of the mirror head 132236c (+4 commits)
git diff --check clean

No E2E test covers the real providers' success path here: there are no provider credentials in this environment or in CI.

Mirror state

Ruleset The mirror had no ruleset. absorb created the canonical main ruleset (id 24307517): no deletion, no force push, PRs required with 0 approvals; the split app (4016286) always bypasses
Classic branch protection on main Still present and will block Split: push restrictions to the Owners team only (no apps), 1 required approving review, enforce_admins on. Unlike audit's, it has no allowance for the split app. Before merge, remove it (as was done for balancer) or add the split app to its restrictions

After merge

Step
Merge with a merge commit A squash orphans the package from its mirror
Confirm Split The Split run for logger is green and the mirror fast-forwards from 132236c (needs the branch protection fix above)
Release bin/monorepo release logger 0.9.0: the dependency surface changed (fetch → client + psr7, PHP 8.5)
client 0.6.0 Once released, restore the 5-hop cap with maxHops: 5
Triage mirror issues and PRs Port what is still wanted here, then close each with a pointer (below)
Monorepo PRs None: logger never lived in utopia-php/monorepo

Open on utopia-php/logger:

# Type Opened Title Author
utopia-php/logger#52 Issue 2026-09 Every push() leaks its curl handle and socket until cycle GC (utopia-php/fetch closures bind $this) @loks0n
utopia-php/logger#42 Issue 2024-12 🚀 Feature: Set event_id in Sentry Adapter so it also works with GlitchTip @cloudatlas9
utopia-php/logger#27 Issue 2023-07 🚀 Feature: Update Rollbar Logger to Send Stack Trace @stnguyen90
utopia-php/logger#24 Issue 2023-01 Update HoneyBadger Logger to send stacktrace @stnguyen90
utopia-php/logger#22 Issue 2022-11 🚀 Feature: Elastic Cloud Adapter | APM @fliitor
utopia-php/logger#4 Issue 2021-11 Help by implementing GlitchTip adapter 🛰 @Meldiron
utopia-php/logger#51 PR 2026-08 Fix fatal Error when a Log is pushed without required fields @claudear
utopia-php/logger#50 PR 2026-07 Sentry split type and value @fogelito
utopia-php/logger#46 PR 2026-02 feat: enhance logging error handling with Push exception @eldadfux
utopia-php/logger#40 PR 2024-10 Replace exceptException with try/catch @vermakhushboo
utopia-php/logger#21 PR 2022-11 Added Dynatrace Adaptor @michizhou
utopia-php/logger#20 PR 2022-10 Added Bugsnag Adaptor @michizhou
utopia-php/logger#19 PR 2022-10 Feat: Honeybadger adaptor @2002Bishwajeet
utopia-php/logger#18 PR 2022-10 Added Airbrake Adapter @devblin

utopia-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 the Logger/ segment).

🤖 Generated with Claude Code

loks0n and others added 22 commits December 13, 2024 17:42
fix: dont throw on log push failure
The property comment incorrectly referenced AppSignal's setup path. Updated to reference Raygun's correct API-key location.
…ef3118b'

git-subtree-dir: packages/logger
git-subtree-mainline: 514e2ac
git-subtree-split: 132236c
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.
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Oct 1, 2026
@ghost

ghost commented Oct 1, 2026

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The import needs minor fixes for undeclared runtime requirements, production-service tests, and documentation that no longer works.

Imports Utopia Logger into packages/logger and wires its source and tests into the root Composer autoloading. The four provider adapters now use an injectable PSR-18 client, with request and failure-path unit tests. The package also gains monorepo QA configuration, separate unit/E2E tiers, and mirror plumbing.

Verdict New comments Fixed Still open
✅ Approved 4 0 0
Finding Where
🟡 Account for the default client's cURL extension requirement packages/logger/composer.json:35
🟡 Keep automated failure tests off production provider endpoints packages/logger/tests/E2E/AdapterBase.php:110
🟡 Pass the required Sentry constructor arguments in the example packages/logger/README.md:58
🟡 Update the standalone QA commands after hoisting the tools packages/logger/README.md:103
Fix with agent prompt
### Issue 1
packages/logger/composer.json:35-39
**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.

### Issue 2
packages/logger/tests/E2E/AdapterBase.php:110-116
**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.

### Issue 3
packages/logger/README.md:58-61
**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.

### Issue 4
packages/logger/README.md:103-108
**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.
📂 Walkthrough · 10
File Change
composer.json, composer.lock Adds logger autoload, test autoload, and replacement entries; updates the lock content hash.
packages/logger/.github/workflows/mirror.yml Redirects mirror issues and pull requests to Appwrite.
packages/logger/.env.example, .gitignore, data/.gitkeep Adds provider environment placeholders and package housekeeping files.
packages/logger/README.md, CONTRIBUTING.md, CODE_OF_CONDUCT.md, LICENSE, docs/tutorials/add-logger-adapter.md Imports package documentation and licensing, with a read-only mirror banner.
packages/logger/composer.json, phpunit.xml, phpstan.neon, phpstan-baseline.neon, rector.php Defines standalone dependencies, test tiers, and hoisted QA configuration.
packages/logger/src/Adapter.php, src/Adapter/* Imports adapter contracts and switches provider transport to injectable PSR-18 clients.
packages/logger/src/Log.php, src/Log/*, src/Logger.php Imports log models, validation, sampling, and dispatch.
packages/logger/tests/Adapter/*, tests/LogTest.php, tests/Log/* Adds recording-client adapter tests and imports model unit tests.
packages/logger/tests/E2E/* Imports provider integration tests and skips success cases without credentials.
rfc/monorepo.md Records logger's two static-analysis baseline findings.

Reviewed ec2b8e6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment on lines +35 to +39
"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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +110 to +116
$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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/logger/README.md
Comment on lines +58 to +61
// Sentry
$adapter = new Sentry("[YOUR_SENTRY_DSN]");
$logger = new Logger($adapter);
$logger->addLog($log);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/logger/README.md
Comment on lines +103 to +108
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → chore/absorb-logger (after).

Metric Before After Change
🚀 Requests/sec 209.34 211.42 ⚪ +1%
⏱️ Latency P50 82.37 ms 82.65 ms ⚪ +0.3%
⏱️ Latency P95 193.68 ms 187.7 ms ⚪ -3.1%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 82.65 187.7 13,509 211.42 -5.98
Account 154.84 283.4 711 11.8 -39.97
TablesDB 79.05 139.6 7,347 118.68 -12.1
Storage 78.84 167.78 3,555 58.72 +12.09
Functions 119.35 230.12 1,896 31.73 +8.98

Top API waits (after)

API request Max wait (ms)
functions.create 427.39
account.name.update 381.87
functions.variables.update 357.76
functions.variables.create 356.33
storage.buckets.create 356.11

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Closing: Appwrite no longer uses utopia-php/logger (removed in 1d639e0, errors go through spans), and its remaining consumers (appwrite-labs/databases, appwrite-labs/pwned, appwrite/docker-geo, open-runtimes/proxy) pin 0.7/0.8 from Packagist. Logger stays standalone; the plan in #13828 is to move those consumers to span-based error reporting and archive it.

@ChiragAgg5k ChiragAgg5k closed this Oct 1, 2026
@ChiragAgg5k
ChiragAgg5k deleted the chore/absorb-logger branch October 1, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

absorb History-preserving package absorption; merge commit required

Projects

None yet

Development

Successfully merging this pull request may close these issues.