Skip to content

solarwinds/apm-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

SolarWinds APM PHP Library

Packagist Version Packagist Downloads PHP CI codecov OpenSSF Scorecard GitHub License


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.

SWO

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.

Thanks to all contributors:

Troubleshooting

For troubleshooting, refer to the Troubleshooting Guide.

License

Apache-2.0. See LICENSE for details.

About

OpenTelemetry-based SolarWinds APM PHP library

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6