Defer rare telemetry instrument creation#4
Conversation
Greptile SummaryThis PR defers creation of four rare/event-driven telemetry instruments (
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to instrument creation order, all existing tests pass, and two new tests directly exercise the lazy-creation contract. The diff touches only how four instruments are registered with the telemetry adapter; the recording call-sites (->add(), ->record()) are identical to before. The lazy factories return the same Counter/Gauge types the properties already declare, so no type unsafety is introduced. The new tests cover the two cases that matter most — no instrument created on a clean success path, and the correct subset created on a forced transition — and the pre-existing suite exercises recording values through those same instruments. No behavioural logic was changed. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "Defer rare telemetry instrument creation" | Re-trigger Greptile |
Summary
utopia-php/telemetryto the released^0.4package that includes lazy instrument factories.Why
OpenTelemetry registers instruments with the meter when they are created. If circuit breakers eagerly create rare event metrics, periodic exports can include registered instruments that have no datapoints. For event-driven metrics, no event should mean no instrument stream yet.
Steady-state metrics remain eager because zero is meaningful for breaker state and counts. Rare metrics now use the telemetry package's lazy factories so they only register when data is actually recorded.
Testing
composer test:unit./vendor/bin/phpstan analyse --memory-limit=512Mcomposer lint