refactor(telemetry): depend on PSR-18/17 interfaces, inject the client#43
refactor(telemetry): depend on PSR-18/17 interfaces, inject the client#43loks0n wants to merge 2 commits into
Conversation
The OpenTelemetry adapter built its default HTTP transport via OtlpHttpTransportFactory, which leaned on php-http/discovery to find a PSR-18 client and PSR-17 factories at runtime. That pulled symfony/http-client and nyholm/psr7 into the package purely as discovery targets, and the discovery composer plugin kept re-adding them on every update. Drop both concretes and depend only on psr/http-client + psr/http-factory. The adapter now takes a required PSR-18 ClientInterface (the meaningful choice — which HTTP stack) and builds the transport with PsrTransportFactory. The PSR-17 factories stay optional and fall back to discovery when null, so callers only wire the client in the common case. The discovery composer plugin is disabled so it stops re-adding Symfony/Nyholm. A hard dependency on utopia-php/client was ruled out: it would close a telemetry -> client -> pools -> telemetry cycle that breaks --linked CI and couples the release cadence of packages meant to version independently. The client is now wired in by the consumer, where the dependency arrow points the right way. BREAKING: OpenTelemetry's constructor now requires a PSR-18 client argument. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LQiyHv2cv5SUHsHYBAE8SQ
Greptile SummaryThis PR refactors the
Confidence Score: 5/5Safe to merge — the refactoring is well-scoped and the breaking change is intentional and documented; no functional regressions in the changed code paths. The constructor simplification and static factory introduction are straightforward and correct. The dependency swap from concretes to PSR interfaces is consistent throughout composer.json, the lock file, and the adapter code. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "refactor(telemetry): split transport/cli..." | Re-trigger Greptile |
Addresses review: with a single constructor, injecting a $transport left $endpoint, $client and the factories required-but-unused — a transport-only caller had to pass a dummy client to satisfy the type. The constructor now takes the TransportInterface it actually consumes; a static fromClient() builds that transport from a PSR-18 client (+ optional PSR-17 factories). Each entry point requires exactly what it uses, nothing is discarded, and the client stays enforced at the type level. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LQiyHv2cv5SUHsHYBAE8SQ
What
The
OpenTelemetryadapter built its default HTTP transport withOtlpHttpTransportFactory, which relies onphp-http/discoveryto locate a PSR-18 client and PSR-17 factories at runtime. That pulledsymfony/http-clientandnyholm/psr7into the package purely as discovery targets — and the discovery composer plugin kept re-adding them on everycomposer update.This drops both concretes so telemetry depends only on the PSR interfaces, and injects the client instead:
require:symfony/http-client+nyholm/psr7→psr/http-client+psr/http-factoryphp-http/discoverycomposer plugin so it stops re-adding Symfony/NyholmConstruction
Two explicit paths — each requires exactly what it uses, nothing discarded:
The constructor now takes the
TransportInterfaceit actually consumes;fromClient()is the convenience that builds one. (An earlier iteration used a single constructor, but that left$endpoint/$client/factories required-but-unused whenever a transport was injected — a transport-only caller had to pass a dummy client to satisfy the type.)Why not a hard dependency on
utopia-php/client?It would close a
telemetry → client → pools → telemetrycycle. That breaks--linkedCI (the back-edgepools → telemetry ^0.4lands on thedev-mainroot, which can't satisfy it) and couples the release cadence of packages meant to version independently. The client is now wired in by the consumer, where the dependency arrow points the right way.OpenTelemetry's constructor signature changed (now$ns, $name, $id, $transport), and the client-driven default moves toOpenTelemetry::fromClient(...). Existingnew OpenTelemetry($endpoint, $ns, $name, $id)call sites (appwrite etc.) must migrate. Warrants a minor version bump when tagged.Verification
bin/monorepo validate→ all packages validbin/monorepo check telemetry→ pint ✅ · phpstan No errors ✅ · rector ✅bin/monorepo test telemetry→ 30/30 ✅ ·--linked→ 30/30 ✅ (no cycle)🤖 Generated with Claude Code
https://claude.ai/code/session_01LQiyHv2cv5SUHsHYBAE8SQ