solarwinds / apm
Solarwinds specific OpenTelemetry SDK for PHP
Installs: 70
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 1
pkg:composer/solarwinds/apm
Requires
- php: ^8.1
- google/protobuf: ^3.22 || ^4.0
- nyholm/psr7-server: ^1.1
- open-telemetry/api: ^1.6
- open-telemetry/exporter-otlp: ^1.2
- open-telemetry/sdk: ^1.8
- open-telemetry/sdk-configuration: ^0.3.0
- open-telemetry/sem-conv: ^1.30
- php-http/discovery: ^1.14
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0.1|^2.0
- psr/log: ^1.1|^2.0|^3.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- mockery/mockery: ^1.6.12
- open-telemetry/dev-tools: dev-main
- phpspec/prophecy: ^1.22
- phpspec/prophecy-phpunit: ^2
- phpstan/phpstan: ^1.12
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.4
- phpunit/phpunit: ^10 || ^11
- ramsey/uuid: ^3.0 || ^4.0
This package is auto-updated.
Last update: 2025-11-21 19:46:10 UTC
README
SolarWinds APM PHP is an OpenTelemetry-based library for distributed tracing and observability in PHP applications. It provides automatic and manual instrumentation, seamless integration with the SolarWinds Observability platform, and supports modern PHP frameworks.
Prerequisites
Before you begin, ensure you have:
Check your versions:
php -v composer -v
Installation
Install the SolarWinds APM library:
composer require solarwinds/apm
Install a PSR-compatible HTTP client (required for OTLP exporter):
composer require guzzlehttp/guzzle
Set your service key (via environment variable):
export SW_APM_SERVICE_KEY=<your-service-key>
Set the collector endpoint, default is apm.collector.na-01.cloud.solarwinds.com:
export SW_APM_COLLECTOR=<your-collector-url>
Example Application
This section demonstrates automatic instrumentation using Slim and SolarWinds APM.
1. Create a minimal Slim app
composer init --no-interaction --require slim/slim:"^4" --require slim/psr7:"^1" composer update
Create index.php:
<?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/vendor/autoload.php'; $app = AppFactory::create(); $app->get('/rolldice', function (Request $request, Response $response) { $result = random_int(1,6); $response->getBody()->write(strval($result)); return $response; }); $app->run();
Run the app:
php -S localhost:8080
Visit http://localhost:8080/rolldice to test.
2. Add zero-code instrumentation
Install the OpenTelemetry PHP extension (instructions) and verify:
php --ri opentelemetry
Add SolarWinds APM Library and required dependencies. More instrumentation libraries can be found here:
composer config allow-plugins.php-http/discovery false
composer require guzzlehttp/guzzle solarwinds/apm open-telemetry/opentelemetry-auto-slim open-telemetry/exporter-otlp
3. Run with tracing enabled
Get your <token> from SolarWinds SaaS Free Trial.
Start the app with tracing:
env OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_SERVICE_NAME=php-example \
OTEL_TRACES_SAMPLER=solarwinds_http \
OTEL_PROPAGATORS=baggage,tracecontext,swotracestate,xtraceoptions \
OTEL_EXPERIMENTAL_RESPONSE_PROPAGATORS=xtrace,xtraceoptionsresponse \
OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.collector.na-01.cloud.solarwinds.com:443 \
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>" \
SW_APM_SERVICE_KEY=<token>:php-example \
php -S localhost:8080
Reload http://localhost:8080/rolldice and view traces in the SolarWinds Observability platform.
Custom Transaction Name
Set a custom transaction name at the beginning of your application:
use Solarwinds\ApmPhp\API\TransactionName; TransactionName::set('custom-transaction-name');
Upgrade from SolarWinds APM PHP library 8.x
If you are upgrading from version 8.x, fully uninstall the previous version before installing 9.x or later to avoid conflicts. Instruction can be found in the UPGRADE.md.
Contributing
Contributions are welcome! See CONTRIBUTING.md for details.
Troubleshooting
For troubleshooting, refer to the Troubleshooting Guide.
License
Apache-2.0. See LICENSE for details.