Docs » Instrument applications for Splunk APM » Instrument a PHP application

Instrument a PHP application 🔗

Important

The original µAPM product, released in 2019, is now called µAPM Previous Generation (µAPM PG). In the documentation, µAPM now refers to the product released on March 31, 2020.

If you are using µAPM Previous Generation (µAPM PG), see Overview of SignalFx Microservices APM Previous Generation (µAPM PG).

Automatically instrument a PHP application to capture and send traces to Splunk APM with the Splunk PHP Tracing Library. The Splunk PHP Tracing Library uses OpenTracing API 2.0 to instrument a PHP application. To set up instrumentation, see the Splunk PHP Tracing Library on GitHub. You can also manually instrument a PHP application by building on the OpenTracing-compatible tracer the Splunk PHP Tracing Library provides with the OpenTracing API for PHP on GitHub.

Configure the instrumentation to send traces to a Smart Agent. The Smart Agent forwards data to an APM ingest endpoint. Configure the Smart Agent to add tags to identify spans that belong to specific hosts or microservices. For more information about deploying a Smart Agent, see Deploy a SignalFx Smart Agent for Splunk APM.

If you want to configure instrumentation for an application and can’t deploy a Smart Agent, configure the instrumentation to send traces directly to an APM ingest endpoint, or to an OpenTelemetry Collector.

Optionally, deploy an OpenTelemetry Collector between a Smart Agent or instrumented code and an APM ingest endpoint. The OpenTelemetry Collector enables you to centrally manage configuration options, batching, retries, and authentication. For more information about deploying an OpenTelemetry Collector for APM, see Deploy an OpenTelemetry Collector for Splunk APM.

Requirements and supported software 🔗

To view a full list of the requirements and supported libraries and frameworks, see Supported Libraries and Frameworks on GitHub.

Add custom instrumentation to a PHP application 🔗

To trace code the Splunk PHP Tracing Library doesn’t instrument by default, use the OpenTracing API for PHP on GitHub salong with the Splunk PHP Tracing Library.

Here’s an example illustrating how you can use the OpenTracing API for PHP and the Splunk PHP Tracing Library together:

use SignalFx\GlobalTracer;
use OpenTracing\Tags;

function myApplicationLogic($indicator) {
  $tracer = GlobalTracer::get(); //  Provides the tracer used by signalfx_tracing instrumentations
  $span = $tracer->startActiveSpan('myApplicationLogic')->getSpan();
  $span->setTag('indicator', $indicator);

  try {
    $widget = myAdditionalApplicationLogic($indicator);
    $span->setTag('widget', $widget);
    return $widget;
  } catch (Exception $e) {
    $span->setTag(Tags\ERROR, true)
    throw $e;
  } finally {
    $span->finish();
  }
}