Instrument your PHP application for Splunk Observability Cloud

The OpenTelemetry PHP extensions automatically instruments PHP applications using a PHP extension and available instrumentation libraries. Follow these steps to get started.

Note: Due to changes in the upstream OpenTelemetry documentation, "automatic instrumentation" has been changed to "zero-code instrumentation". For more information, see Instrumentation methods for Splunk Observability Cloud.

The OpenTelemetry PHP extension automatically instruments PHP applications using a PHP extension and available instrumentation libraries. You can send telemetry to the Splunk Distribution of OpenTelemetry Collector or directly to the Splunk Observability Cloud ingest endpoint.

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

Generate customized instructions using the guided setup

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

  1. Log in to Splunk Observability Cloud.

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

    1. In the navigation menu, select Data Management.

    2. Go to the Available integrations tab, or select Add Integration in the Deployed integrations tab.

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

    4. Select the APM product.

    5. Select the PHP (OpenTelemetry) tile to open the PHP OpenTelemetry guided setup.

Install the Splunk Distribution of OpenTelemetry PHP manually

If you don’t use the guided setup, follow these steps to manually install and automatically instrument your PHP application:

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

  2. Install the OpenTelemetry PHP extension using PECL in the command line:

    Linux
    SHELL
    sudo apt-get install gcc make autoconf
    pecl install opentelemetry
    Windows

    Download the precompiled DLL file from the releases page on GitHub.

    Make sure to place the DLL in your extensions’s directory, as defined by the value of extension_dir in your php.ini file.

  3. Add the extension to your php.ini file:

    Linux
    INI
    [opentelemetry]
    extension=opentelemetry.so
    Windows
    INI
    [opentelemetry]
    extension=php_opentelemetry.dll
  4. Install the required instrumentations you need using Composer:

    BASH
    php composer.phar install open-telemetry/exporter-otlp:^1.0.3
    php composer.phar install php-http/guzzle7-adapter:^1.0

    You can also install additional instrumentations. See Supported libraries and frameworks.

  5. Configure the basic settings in your php.ini file or using environment variables:

    BASH
    OTEL_PHP_AUTOLOAD_ENABLED=true \
    OTEL_SERVICE_NAME="<your-service-name>" \
    OTEL_RESOURCE_ATTRIBUTES="deployment.environment=<your_env>" \
  6. Run your application.

    See the OpenTelemetry PHP examples in GitHub for sample instrumentation scenarios.

To configure the instrumentation, see Instrumentation settings.

Connect RUM to APM through server trace data

To connect Real User Monitoring (RUM) requests from mobile and web applications with server trace data, add the OpenTelemetry server timing propagator as a dependency:

SHELL
php composer.phar install open-telemetry/opentelemetry-propagation-server-timing:^0.0.2

Send data directly to Splunk Observability Cloud

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

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

SHELL
OTEL_EXPORTER_OTLP_TRACES_HEADERS=x-sf-token=<access_token>
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<realm>.signalfx.com/trace/otlp

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

To find your Splunk realm, see the note about realms in Configure SSO integrations for Splunk Observability Cloud.

Instrumentation settings

You can configure the OpenTelemetry PHP extension using the following settings.

General settings

Environment variable Description Default Type
OTEL_SDK_DISABLED If true, disable the OpenTelemetry SDK. Defaults to false. false Boolean
OTEL_METRICS_EXEMPLAR_FILTER The filter for exemplar sampling. Possible values are with_sampled_trace, all and none. Default is with_sampled_trace. with_sampled_trace String
OTEL_PHP_TRACES_PROCESSOR Default span processor if not explicitly created via SDK. Default is batch. batch String
OTEL_PHP_LOGS_PROCESSOR Default log record processor if not explicitly created via SDK. Default is batch. batch String
OTEL_PHP_LOG_DESTINATION Destination for internal logs of OpenTelemetry. Possible values are none, stderr, stdout, psr3, debug and default. Using default uses psr3 if available, but falls back to error_log otherwise. The default value is default. default String
OTEL_PHP_DETECTORS Comma-separated list of detectors to use for resource detection. Possible values are all, env, host, os, process, process_runtime, sdk, sdk_provided, composer and none. Default is all. all String
OTEL_PHP_AUTOLOAD_ENABLED If true, automatically initialize SDK during autoloading. Default is false. false Boolean
OTEL_PHP_INTERNAL_METRICS_ENABLED If true, the SDK emits its own metrics, such as batch span and log processor state. Default is false. false Boolean
OTEL_PHP_DISABLED_INSTRUMENTATIONS Comma-separated list of instrumentations to disable. Value to use to disable a specific module is provided by the documentation of that module. Default is empty. &#160; String
OTEL_PHP_EXCLUDED_URLS Comma-separated list of URL regex patterns (matched against $_SERVER['REQUEST_URI']) where SDK autoloading is disabled. Default is empty. &#160; String

Exporter settings

Environment variable Description Default Type
OTEL_TRACES_EXPORTER Comma-separated list of exporters to be used for tracing. Default is otlp. none means no autoconfigured exporter. otlp String
OTEL_METRICS_EXPORTER Comma-separated list of exporters to be used for metrics. Default is otlp. none means no autoconfigured exporter. otlp String
OTEL_LOGS_EXPORTER Comma-separated list of exporters to be used for logs. Default is otlp. none means no autoconfigured exporter. otlp String
OTEL_EXPORTER_OTLP_ENDPOINT The OTLP traces, metrics, and logs endpoint to connect to. Must be a URL with a scheme of either http or https based on the use of TLS. If protocol is http/protobuf the version and signal will be appended to the path (e.g. v1/traces, v1/metrics, or v1/logs). Default is http://localhost:4317 when protocol is grpc, and http://localhost:4318/v1/{signal} when protocol is http/protobuf. http://localhost:4317 String
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT The OTLP traces endpoint to connect to. Must be a URL with a scheme of either http or https based on the use of TLS. Default is http://localhost:4317 when protocol is grpc, and http://localhost:4318/v1/traces when protocol is http/protobuf. http://localhost:4317 String
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT The OTLP metrics endpoint to connect to. Must be a URL with a scheme of either http or https based on the use of TLS. Default is http://localhost:4317 when protocol is grpc, and http://localhost:4318/v1/metrics when protocol is http/protobuf. http://localhost:4318/v1/metrics String
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT The OTLP logs endpoint to connect to. Must be a URL with a scheme of either http or https based on the use of TLS. Default is http://localhost:4317 when protocol is grpc, and http://localhost:4318/v1/logs when protocol is http/protobuf. http://localhost:4317 String
OTEL_EXPORTER_OTLP_INSECURE If true, allow TLS credentials verification to fail for trace, metric, and log requests. Default is false. false Boolean
OTEL_EXPORTER_OTLP_TRACES_INSECURE If true, allow TLS credentials verification to fail for trace requests. Default is false. false Boolean
OTEL_EXPORTER_OTLP_METRICS_INSECURE If true, allow TLS credentials verification to fail for metric requests. Default is false. false Boolean
OTEL_EXPORTER_OTLP_LOGS_INSECURE If true, allow TLS credentials verification to fail for log requests. Default is false. false Boolean
OTEL_EXPORTER_OTLP_CERTIFICATE The path to the file containing trusted certificates to use when verifying an OTLP trace, metric, or log server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. &#160; String
OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE The path to the file containing trusted certificates to use when verifying an OTLP trace server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. &#160; String
OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE The path to the file containing trusted certificates to use when verifying an OTLP metric server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. &#160; String
OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE The path to the file containing trusted certificates to use when verifying an OTLP log server's TLS credentials. The file should contain one or more X.509 certificates in PEM format. By default the host platform's trusted root certificates are used. &#160; String
OTEL_EXPORTER_OTLP_HEADERS Comma-separated list of key-value pairs to pass as request headers on OTLP trace, metric, and log requests. &#160; String
OTEL_EXPORTER_OTLP_TRACES_HEADERS Comma-separated list of key-value pairs to pass as request headers on OTLP trace requests. &#160; String
OTEL_EXPORTER_OTLP_METRICS_HEADERS Comma-separated list of key-value pairs to pass as request headers on OTLP metrics requests. &#160; String
OTEL_EXPORTER_OTLP_LOGS_HEADERS Comma-separated list of key-value pairs to pass as request headers on OTLP logs requests. &#160; String
OTEL_EXPORTER_OTLP_COMPRESSION The compression type to use on OTLP trace, metric, and log requests. Options include gzip. By default no compression are used. &#160; String
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION The compression type to use on OTLP trace requests. Options include gzip. By default no compression are used. &#160; String
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION The compression type to use on OTLP metric requests. Options include gzip. By default no compression are used. &#160; String
OTEL_EXPORTER_OTLP_LOGS_COMPRESSION The compression type to use on OTLP log requests. Options include gzip. By default, no compression are used. &#160; String
OTEL_EXPORTER_OTLP_TIMEOUT The maximum waiting time, in seconds, allowed to send each OTLP trace, metric, and log batch. Default is 10. 10 Int
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT The maximum waiting time, in seconds, allowed to send each OTLP trace batch. Default is 10. 10 Int
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT The maximum waiting time, in seconds, allowed to send each OTLP metric batch. Default is 10. 10 Int
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT The maximum waiting time, in seconds, allowed to send each OTLP log batch. Default is 10. 10 Int
OTEL_EXPORTER_OTLP_PROTOCOL The transport protocol to use on OTLP trace, metric, and log requests. Options include grpc and http/protobuf. http/protobuf String
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL The transport protocol to use on OTLP trace requests. Options include grpc and http/protobuf. http/protobuf String
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL The transport protocol to use on OTLP metric requests. Options include grpc and http/protobuf. http/protobuf String
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL The transport protocol to use on OTLP log requests. Options include grpc and http/protobuf. http/protobuf String
OTEL_BSP_SCHEDULE_DELAY Delay interval (in milliseconds) between two consecutive exports in batch span processor. Default is 5000. 5000 Int
OTEL_BSP_EXPORT_TIMEOUT Maximum allowed time (in milliseconds) to export data in batch span processor. Default is 30000. 30000 Int
OTEL_BSP_MAX_QUEUE_SIZE Maximum queue size in batch span processor. Default is 2048. 2048 Int
OTEL_BSP_MAX_EXPORT_BATCH_SIZE Maximum batch size in batch span processor. Default is 512. 512 Int
OTEL_METRIC_EXPORT_INTERVAL The interval, in milliseconds, between the start of two export attempts. Default is 60000. 60000 Int
OTEL_METRIC_EXPORT_TIMEOUT Maximum allowed time, in millisecond, to export metric data. Default is 30000. 30000 Int
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE The preferred output aggregation temporality. Options include delta, lowmemory, and cumulative. If cumulative, all instruments have cumulative temporality. If delta, counter (sync and async) and histograms are delta, up down counters (sync and async) are cumulative. If lowmemory, sync counter and histograms are delta, async counter and up down counters (sync and async) are cumulative. Default is cumulative. cumulative String
OTEL_BLRP_SCHEDULE_DELAY Delay interval (in milliseconds) between two consecutive exports in batch log record processor. Default is 5000. 5000 Int
OTEL_BLRP_EXPORT_TIMEOUT Maximum allowed time (in milliseconds) to export data in batch log record processor. Default is 30000. 30000 Int
OTEL_BLRP_MAX_QUEUE_SIZE Maximum queue size in batch log record processor. Default is 2048. 2048 Int
OTEL_BLRP_MAX_EXPORT_BATCH_SIZE Maximum batch size in batch log record processor. Default is 512. 512 Int
OTEL_EXPORTER_ZIPKIN_ENDPOINT The Zipkin endpoint to connect to. Default is http://localhost:9411/api/v2/spans. Currently only HTTP is supported. http://localhost:9411/api/v2/spans String
OTEL_EXPORTER_ZIPKIN_TIMEOUT Maximum time (in milliseconds) the Zipkin exporter waits for each batch export. Default is 10000. 10000 &#160;

Instrumentation settings

Environment variable Description Default Type
OTEL_SERVICE_NAME Name of the service or application you're instrumenting. Takes precedence over the service name defined in the OTEL_RESOURCE_ATTRIBUTES variable. &#160; String
OTEL_RESOURCE_ATTRIBUTES Comma-separated list of resource attributes added to every reported span. For example, key1=val1,key2=val2. &#160; String
OTEL_ATTRIBUTE_COUNT_LIMIT The maximum number of attributes. Applies to spans, span events, span links, and logs. Default is 128. 128 Int
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT Maximum length of strings for attribute values. Values larger than the limit are truncated. Default value is infinite. Empty values are treated as infinity. &#160; Int
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT The maximum number of attributes allowed for links. Applies to span links. Default is 128. 128 Int
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT The maximum number of attributes allowed for events. Applies to span events. Default is 128. 128 Int
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT The maximum number of attributes per span. Takes precedence over OTEL_ATTRIBUTE_COUNT_LIMIT. Default is 128. 128 Int
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT The maximum length of span attribute values. Takes precedence over OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT. Default is unlimited. &#160; Int
OTEL_SPAN_EVENT_COUNT_LIMIT Maximum number of events per span. Default is 128. 128 Int
OTEL_SPAN_LINK_COUNT_LIMIT Maximum number of links per span. Default is 128. 128 Int
OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT The maximum number of attributes per log record. Takes precedence over OTEL_ATTRIBUTE_COUNT_LIMIT. Default is 128. 128 Int
OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT The maximum length of log record attribute values. Takes precedence over OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT. Default is unlimited. &#160; Int