Docs » Instrument back-end applications to send spans to Splunk APM » Instrument PHP applications for Splunk Observability Cloud » Instrument a PHP application for Splunk Observability Cloud

Instrument a PHP application for Splunk Observability Cloud πŸ”—

The SignalFx Tracing Library for PHP automatically instruments PHP applications.

To get started, use the guided setup or follow the instructions manually.

Generate customized instructions using the guided setup πŸ”—

To generate all the basic installation commands for your environment and application, use the PHP guided setup. To access the PHP guided setup, follow these steps:

  1. Log in to Observability Cloud.

  2. Open the PHP guided setup. Optionally, you can navigate to the guided setup on your own:

    1. In the left navigation menu, select Data Management.

    2. Select Add Integration to open the Integrate Your Data page.

    3. In the integration filter menu, select By Product.

    4. Select the APM product.

    5. Select the PHP tile to open the PHP guided setup.

Instrument a PHP application πŸ”—

Follow these steps to automatically instrument your application:

  1. Check that you meet the requirements. See PHP instrumentation compatibility and requirements.

  2. Download the installation script from the following location:

    curl -LO  https://github.com/signalfx/signalfx-php-tracing/releases/latest/download/signalfx-setup.php
    
  3. Install by running the installation script:

    php signalfx-setup.php --php-bin=all
    

    Note

    If you omit the --php-bin option, you can interactively select the PHP installation.

  4. Set the following environment variables:

    # Add the following lines to your Apache configuration file
    
    SetEnv SIGNALFX_SERVICE_NAME="<my-service-name>"
    SetEnv SIGNALFX_ENDPOINT_URL='http://localhost:9080/v1/trace'
    SetEnv SIGNALFX_TRACE_GLOBAL_TAGS="deployment.environment<my_environment>"
    
  5. Restart your server.

Note

If you need to add custom attributes to spans or want to manually generate spans, instrument your PHP application or service manually. See Manually instrument PHP applications for Splunk Observability Cloud.

INI file settings πŸ”—

If you don’t set any environment variable, the library extracts default values from the INI file. The prefix for settings defined using environment variables that start with SIGNALFX_TRACE_ is signalfx.trace.. For all other environment variables that start with SIGNALFX_ the prefix is signalfx..

You can use the signalfx-setup.php script to set INI file options without having to manually locate each file. For example:

php signalfx-setup.php --update-config --signalfx.endpoint_url=http://172.17.0.1:9080/v1/trace

This is useful for options common to all PHP services running in the system, like endpoints.

Deploy the PHP instrumentation in Kubernetes πŸ”—

To deploy the PHP instrumentation in Kubernetes, configure the Kubernetes Downward API to expose environment variables to Kubernetes resources.

The following example shows how to update a deployment to expose environment variables by adding the agent configuration under the .spec.template.spec.containers.env section:

apiVersion: apps/v1
kind: Deployment
spec:
   selector:
      matchLabels:
         app: your-application
   template:
      spec:
         containers:
         - name: myapp
            env:
               - name: SIGNALFX_PHP_LIBRARY
               valueFrom:
                  fieldRef:
                     fieldPath: status.hostIP
               - name: SIGNALFX_SERVICE_NAME
                 value: "<service-name>"
               - name: SIGNALFX_ENDPOINT_URL
                 value: "http://<endpoint>:9080/v1/trace"
               - name: SIGNALFX_TRACE_GLOBAL_TAGS
                 value: "deployment.environment:<my_environment>"

Send data directly to Observability Cloud πŸ”—

By default, all telemetry is sent to the local instance of the Splunk Distribution of OpenTelemetry Collector.

To bypass the OTel Collector and send data directly to Observability Cloud, set the following environment variables:

SetEnv SIGNALFX_ACCESS_TOKEN=<access_token>
SetEnv SIGNALFX_ENDPOINT_URL=https://ingest.<realm>.signalfx.com/v2/trace/signalfxv1

To obtain an access token, see Retrieve and manage user API access tokens using Splunk Observability Cloud.

In the ingest endpoint URL, realm is the Observability Cloud realm, for example, us0. To find the realm name of your account, follow these steps:

  1. Open the left navigation menu in Observability Cloud.

  2. Select Settings.

  3. Select your username.

The realm name appears in the Organizations section.

Note

For more information on the ingest API endpoints, see Send APM traces.