Skip to content

Remove utopia-php/logger and report errors through spans - #13457

Merged
loks0n merged 6 commits into
mainfrom
refactor/remove-utopia-logger
Sep 4, 2026
Merged

loks0n merged 6 commits into
mainfrom
refactor/remove-utopia-logger

Conversation

@loks0n

@loks0n loks0n commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Why

Every error handler built a Utopia\Logger\Log by hand and pushed it to a provider through utopia-php/fetch. That path leaks the curl handle, its socket and an eventfd until PHP's cycle collector runs (utopia-php/logger#52, reproduced on a live worker: 135 fds and 67 CLOSE_WAIT sockets after an hour), and utopia-php/fetch is archived so it cannot be fixed at the source. Meanwhile every request, job, task and realtime event already runs inside a Utopia\Span that carries the same throwable, so the logger was a second, hand-maintained copy of what the span knows.

What changed

  • utopia-php/logger is removed from composer.json and composer.lock.
  • app/init/span.php adds the utopia-php/span Sentry exporter when _APP_LOGGING_CONFIG is a sentry://PROJECT_ID:KEY@HOST/ DSN, with environment, release and server name filled from the existing env vars. The exporter only ships spans that carry an error, and handlers now set error.publish=false on expected client errors so the old publish rules (AppwriteException::isPublishable(), code 0 or >= 500) still decide what reaches Sentry.
  • Every $log->addTag() / addExtra() is now Span::add(), with dotted keys (project.id, function.id, deployment.id, database.id, dns.domain, email.skipped, webhook.signed, lock.target, ...). The Log parameter is gone from workers, proxy rule actions, Proxy\Action::verifyRule(), the embeddings endpoint and Appwrite\Locking\Lock.
  • HTTP, worker, CLI and realtime error handlers set the error on the current span instead of building a Log. CLI tasks and realtime server callbacks, which run outside a request span, open one so the failure still reaches the exporters.
  • The logError container resource (used by Migrations and Platform\Action) keeps its signature and writes to the span.
  • Removed: the logger and realtimeLogger registry entries, the log and logger container resources, _APP_LOGGING_PROVIDER, _APP_LOGGING_CONFIG_REALTIME, _APP_EXPERIMENT_LOGGING_PROVIDER and _APP_EXPERIMENT_LOGGING_CONFIG. _APP_LOGGING_CONFIG and _APP_LOGGING_FORMAT stay.

Behaviour changes to be aware of

  • Only Sentry is supported. LogOwl, Raygun and AppSignal DSNs are rejected at boot with a logged error and no export.
  • Realtime no longer has its own DSN; it uses _APP_LOGGING_CONFIG like everything else.
  • The sampled 4xx experiment (_APP_EXPERIMENT_LOGGING_CONFIG) is dropped.
  • Lock backend failures and per-text embedding failures are recorded as span attributes (lock.error, embedding.error) rather than standalone events, because they do not fail the request.
  • Doctor reports the logging adapter as enabled only for a sentry:// DSN.

Verification

  • pint --test, PHPStan (level from phpstan.neon) and php -l clean on all 36 changed files.
  • tests/unit/Locking/LockTest.php (18), tests/unit/Platform/Workers/DatabasesTest.php, MailsTest.php (3), NotificationsTest.php (25) pass. LockTest and NotificationsTest now assert on span attributes through Span\Storage\Memory instead of on Log tags.
  • Not verified here: an end-to-end Sentry delivery. The exporter is the library's own; this PR only wires it.

Downstream

appwrite-labs/cloud extends these actions and still injects log in 18 files (Workers/Mails.php, Certificates.php, Deletes.php, Builds.php, Databases.php, Patches.php, DedicatedDatabases.php, the proxy rule actions, and its own app/*.php handlers). Those must be migrated to Span::add() in the same release that bumps appwrite/server-ce, or the workers fail at boot on the missing log resource.

🤖 Generated with Claude Code

https://claude.ai/code/session_01D9ybk4YF5Q5L2xQzqhqdCT

Takeover validation (2026-09-04)

Refreshed with current main and reran CI. In an isolated PHP 8.5.9/Swoole container with garbage collection disabled, 2,000 error exports through the old logger grew file descriptors from 8 to 2,008 and RSS by about 156 MiB. The replacement span exporter delivered all 2,000 valid events while descriptors stayed at 8. Local p95 export latency was 3.96 ms versus 3.81 ms for the old path; this is a transport microbenchmark, not application throughput.

A second drill ran 20 concurrent coroutines through success, HTTP 500, connection refusal, and recovery (2,000 exports per phase). Descriptors stayed at 8 in every phase. The local sink received 6,000 valid, distinct error events, and the exporter reported all 4,000 expected transport failures. Delivery recovered after the failures.

Staging deployment and soak validation remain pending. Both regions have pre-rollout process/socket/memory, health-latency, API, worker, and queue metric baselines. No claim of a completed staging validation is made from these local drills.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces the legacy logger-based error-reporting path with span-based Sentry export and removes obsolete logger resources and configuration.

  • Configures a Sentry span exporter for publishable errors.
  • Records HTTP, realtime, worker, and CLI failures on spans.
  • Migrates logger tags and extras to structured span attributes.
  • Removes utopia-php/logger and updates affected dependency injection and tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
app/cli.php Reports uncaught CLI task errors by finishing the current span or a newly initialized error span; the previously reported double-finish path is not reachable through current task implementations.
app/init/span.php Adds Sentry exporter configuration, error publication filtering, metadata, and span-field classification.
app/controllers/general.php Replaces HTTP logger construction and metadata population with current-span attributes.
app/realtime.php Replaces the dedicated realtime logger with owned or ambient error spans.
app/init/worker/message.php Records worker errors and contextual metadata on the active job span.
composer.json Removes the obsolete Utopia logger dependency.
composer.lock Updates the resolved dependency graph after removing Utopia logger.

Reviews (9): Last reviewed commit: "Merge main into logger removal branch" | Re-trigger Greptile

Comment thread app/cli.php Resolved
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → refactor/remove-utopia-logger (after).

Metric Before After Change
🚀 Requests/sec 166.92 164.96 ⚪ -1.2%
⏱️ Latency P50 106.63 ms 106.84 ms ⚪ +0.2%
⏱️ Latency P95 237.88 ms 240.11 ms ⚪ +0.9%
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 106.84 240.11 10,260 164.96 +2.23
Account 199.06 414.64 540 9.48 +4.27
TablesDB 107.31 197.65 5,580 93.46 +5.58
Storage 89.96 191.02 2,700 46.84 -13.09
Functions 150.4 282.85 1,440 25.48 -1.33

Top API waits (after)

API request Max wait (ms)
account.get 654.94
account.prefs.update 599.12
account.name.update 573.63
tablesdb.rows.create 531.21
tablesdb.rows.delete 475.33

@loks0n
loks0n force-pushed the refactor/remove-utopia-logger branch 3 times, most recently from ae85bfe to 9888c57 Compare September 4, 2026 18:41
loks0n and others added 5 commits September 4, 2026 19:48
Every error handler built a Utopia\Logger\Log by hand and pushed it to a
third-party provider over utopia-php/fetch. That path leaks the curl handle,
its socket and an eventfd until PHP's cycle collector runs (utopia-php/logger#52),
fetch is archived, and every span already carries the same error. Errors now
flow through Utopia\Span: handlers call Span::add() for the attributes they
used to tag, set the throwable on the current span, and app/init/span.php
adds the utopia-php/span Sentry exporter when _APP_LOGGING_CONFIG holds a
sentry:// DSN. Client errors are marked error.publish=false so only server
failures are exported, matching the old publish rules.

Removed: the logger and realtimeLogger registry entries, the log/logger
container resources, the Log parameter on workers, proxy rules and the
embeddings endpoint, _APP_LOGGING_PROVIDER, _APP_LOGGING_CONFIG_REALTIME and
the _APP_EXPERIMENT_LOGGING_* variables. LogOwl, Raygun and AppSignal are
no longer supported; Sentry is the only exporter.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D9ybk4YF5Q5L2xQzqhqdCT
The exporters derive error.type/message/code/file/line/trace from the
throwable set with setError(); the hand-set copies were noise. Keep
error.publish (sampler input) and error.action (caller label).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D9ybk4YF5Q5L2xQzqhqdCT
Mirror appwrite-labs/edge: the Sentry sampler reads the exception on the
span (AppwriteException::isPublishable(), otherwise code 0 or 5xx) so
handlers no longer stamp error.publish. Classifier is a match on known keys.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D9ybk4YF5Q5L2xQzqhqdCT
main added Appwrite\Execution\Store with its own Logger; report the
best-effort mirror failure as span attributes like Lock does.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01D9ybk4YF5Q5L2xQzqhqdCT
@loks0n
loks0n force-pushed the refactor/remove-utopia-logger branch from 9888c57 to 6f91a14 Compare September 4, 2026 18:49
@loks0n
loks0n merged commit c310a67 into main Sep 4, 2026
45 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant