Application Observability PHP quickstart
Follow these steps to get started quickly with Grafana Application Observability:
- Install the instrumentation library
- Configure an application
- Run the application
- Observe the service in Application Observability
This guide is intended for local development or evaluation setups and sends data directly to Grafana Cloud without a data collector.
Note
For a production setup with a data collector and troubleshooting information, consult the production documentation.
Install the instrumentation library
The OpenTelemetry PHP extension requires the following to be installed:
Install the latest release of the OpenTelemetry PHP extension:
pecl install opentelemetry
Install the protobuf extension for improved OTLP exporter performance:
pecl install protobuf
Add the extensions to php.ini
:
extension=protobuf.so
[opentelemetry]
extension=opentelemetry.so
Install required packages via composer
, including auto-instrumentation for the Slim framework:
composer require \
open-telemetry/sdk \
open-telemetry/exporter-otlp \
open-telemetry/opentelemetry-auto-slim \
php-http/guzzle7-adapter
If Composer autoloading is not already enabled, modify the application entrypoint to include this line:
require __DIR__ . '/vendor/autoload.php';
Note
A number of popular PHP libraries have auto-instrumention packages available, including Laravel and WordPress. You can find the full list here.
Configure an application
Next, customize the following shell script to configure an application:
<authentication environment variables from step 3>
export OTEL_SERVICE_NAME=<Service Name>
export OTEL_PHP_AUTOLOAD_ENABLED=true
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_PROPAGATORS=baggage,tracecontext
php -S localhost:8080
Follow these steps to get necessary information for the shell script:
Sign in to Grafana Cloud, register for a Free Grafana Cloud account if required, the browser will navigate to the Grafana Cloud Portal page https://grafana.com/profile/org.
If the account has access to multiple Grafana Cloud Organizations, select an organization from the top left organization dropdown.
If the organization has access to multiple Grafana Cloud Stacks, navigate to a stack from the left side bar or the main Stacks list.
With a stack selected, or in the single stack scenario, below Manage your Grafana Cloud Stack, click Configure in the OpenTelemetry section:
In the Password / API Token section, click on Generate now to create a new API token:
- Give the API token a name, for example
cart-service
- Click on Create token
- Click on Close without copying the token
- Click on Copy to Clipboard to copy the environment variables to the clipboard
- Give the API token a name, for example
- Pick a Service Name to identify the service, for example
cart
- Replace
php -S localhost:8080
with the start command that runs the application to instrument
Run the application
Finally, run the application with the shell script and make some requests to the service to send data to Grafana Cloud.
Observe the service in Application Observability
Open Application observability:
- Navigate to a stack
https://<your-stack-name.>grafana.net
- Expand the top left menu below the Grafana logo
- Click on Application
Activate metrics generation
Application Observability relies on metrics generated from traces already sent to Grafana Cloud Traces.
Metrics generation is self-serve, and can be enabled during onboarding and disabled from Application Observability configuration.
To complete the setup, click Activate Application Observability to enable metrics generation.
Note
After activating Application Observability and enabling metrics generation, it might take up to five minutes to generate metrics and show graphs.
Visualize and discover
Discover more about Application Observability in the documentation:
- Service Inventory: filter, and search services and view RED metrics.
- Service Overview: traces, logs, RED metrics, operations, and runtime information.
- Service Map: graph of connected services, service dependencies, and data flow.