Skip to content

Add messaging send telemetry#130

Merged
ChiragAgg5k merged 3 commits into
mainfrom
feat/messaging-send-telemetry
Jun 16, 2026
Merged

Add messaging send telemetry#130
ChiragAgg5k merged 3 commits into
mainfrom
feat/messaging-send-telemetry

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

Adds library-level telemetry for message sends.

  • Adds utopia-php/telemetry and initializes adapters with NoTelemetry by default
  • Records messaging.send counts from Adapter::send() with type, provider, optional origin, and result attributes
  • Adds optional message origin metadata to email, SMS, push, and Discord messages
  • Preserves origin when GEOSMS splits SMS sends by local adapter
  • Adds focused coverage for success, failure, thrown-send, and default no-telemetry paths

Test Plan

  • ./vendor/bin/phpunit tests/Messaging/Adapter/TelemetryTest.php
  • composer lint
  • composer analyse

Related PRs and Issues

Have you read the Contributing Guidelines on issues?

Yes.

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces library-level telemetry to utopia-php/messaging by wiring a messaging.send counter into the base Adapter::send() flow, adds optional origin metadata to all message types, and propagates telemetry through GEOSMS's sub-adapter tree.

  • Adapter now holds a Counter (defaulting to NoTelemetry) and records successes and failures after every send() call; counts are derived solely from the results array, dropping the earlier reliance on the inconsistent deliveredTo field.
  • GEOSMS overrides setTelemetry() to propagate the configured backend to its $defaultAdapter and every $localAdapter, and preserves origin when splitting SMS sends across local adapters.
  • All four message types (SMS, Email, Push, Discord) now implement setOrigin()/getOrigin() on the Message interface, enabling optional per-message provenance in telemetry attributes.

Confidence Score: 5/5

The change is safe to merge. All existing adapters are unaffected at runtime (telemetry defaults to a no-op), the recording logic is covered by focused tests, and GEOSMS origin propagation works correctly.

The core recording path in Adapter derives counts from the results array, not the legacy deliveredTo field, which is a genuine correctness improvement. GEOSMS telemetry propagation is tested end-to-end. No behavioural changes exist for callers that don't opt in to telemetry.

GEOSMS.php — the constructor call to setTelemetry on the default adapter is a minor footgun worth a follow-up doc-comment or removal.

Important Files Changed

Filename Overview
src/Utopia/Messaging/Adapter.php Adds telemetry counter field, setTelemetry(), recordSend(), recordResponse(), and telemetryAttributes(); recording now derives counts purely from results array, ignoring the legacy deliveredTo field.
src/Utopia/Messaging/Adapter/SMS/GEOSMS.php Adds per-instance telemetry field, overrides setTelemetry() to propagate to defaultAdapter and all localAdapters, and preserves origin when splitting sends; constructor resets the default adapter's telemetry to NoTelemetry.
tests/Messaging/Adapter/TelemetryTest.php New test file covering success/failure recording, thrown-send failure path, counts-from-results (not from deliveredTo), GEOSMS telemetry propagation, and no-op NoTelemetry default path.
src/Utopia/Messaging/Message.php Interface extended with setOrigin/getOrigin methods required by all message types for telemetry origin tracking.
src/Utopia/Messaging/Messages/SMS.php Implements new setOrigin/getOrigin interface methods with a nullable origin property.
src/Utopia/Messaging/Messages/Email.php Implements new setOrigin/getOrigin interface methods with a nullable origin property.
src/Utopia/Messaging/Messages/Push.php Implements new setOrigin/getOrigin interface methods with a nullable origin property.
src/Utopia/Messaging/Messages/Discord.php Implements new setOrigin/getOrigin interface methods with a nullable origin property.
composer.json Adds utopia-php/telemetry ^0.4 dependency and allow-plugins entries for php-http/discovery and tbachert/spi.

Reviews (3): Last reviewed commit: "Require origin metadata on messages" | Re-trigger Greptile

Comment thread src/Utopia/Messaging/Adapter.php
Comment thread src/Utopia/Messaging/Adapter.php Outdated
@ChiragAgg5k ChiragAgg5k merged commit 2a8e82c into main Jun 16, 2026
3 of 4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the feat/messaging-send-telemetry branch June 16, 2026 03:45
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.

2 participants