Php

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/php"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/accb3110-9909-4ba2-9e22-1123c76da228/social-card.svg?v=3e7ae33eec8b" alt="Php" width="600" height="315"></a>

<!-- status: ga language: php -->

PHP: zero-code instrumentation

The OpenTelemetry PHP extension hooks function calls at runtime, so framework packages instrument Laravel, Symfony, Slim, PDO and PSR-18 clients without a code change. Nothing Watchtower-specific is installed: it reads the standard OTEL_* variables.

  1. Create a project, then an ingestion key (wti_...) with the ingest:traces scope. The key is shown once.

  2. Point the SDK at the gateway and pass the key in the x-watchtower-key header:

export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.example.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS=x-watchtower-key=wti_YOUR_KEY
export OTEL_SERVICE_NAME=my-service
export OTEL_PHP_AUTOLOAD_ENABLED=true
  1. Install the extension and the packages, then enable the extension in php.ini (extension=opentelemetry):

pecl install opentelemetry
composer require open-telemetry/sdk open-telemetry/exporter-otlp open-telemetry/opentelemetry-auto-laravel
php -S 0.0.0.0:8080 -t public

Swap opentelemetry-auto-laravel for the package of your framework (-symfony, -slim, -psr18, -pdo).

  1. Send one request to the service, then open the project's onboarding screen: it turns green when the first span arrives.

Updated