Enabling and configuring PHP tracing
By default, PHP tracing is enabled in the agent configuration file. When PHP tracing is enabled, the PHP sensor automatically installs the PHP Tracer (also referred to as the Instana PHP Tracing extension) in your PHP runtime.
Requirements
The PHP sensor enables tracing only if the detected PHP runtime has the JSON extension support. If any of the following extensions are detected in a PHP runtime, the PHP Tracer installation is disabled automatically:
- SourceGuardian
- New Relic
- Dynatrace
- Datadog
If the ionCube Loader extension is detected in a PHP runtime, the PHP Tracer is installed with PHP userland tracing disabled.
PHP tracing process
When PHP tracing is enabled in the agent configuration file, the PHP sensor automatically manages the installation and configuration of the PHP Tracing extension as outlined in the following steps:
-
The PHP sensor downloads the PHP Tracing extension and enables it in the PHP runtime INI configuration as follows:
- If the PHP runtime is configured with a separate directory for additional INI files, the PHP sensor places a
zzz-instana.inifile that contains the PHP Tracing extension's INI settings in this directory. - Otherwise, the PHP sensor configures PHP Tracer by appending the INI settings to the main
php.inifile.
Do not modify
zzz-instana.inibecause the PHP sensor overwrites it during every installation based on the configurations in the Instana agentconfiguration.yamlfile. - If the PHP runtime is configured with a separate directory for additional INI files, the PHP sensor places a
-
The PHP sensor then attempts to gracefully restart the PHP environment to load the PHP Tracing extension into memory.
-
If the PHP runtime is successfully restarted, the PHP Tracing extension starts collecting traces in the PHP runtime.
-
If the automatic restart doesn't work due to the SAPI type of the PHP runtime, you need to manually restart PHP to load the PHP Tracing extension into memory. For more information on automating the PHP runtime restart, see Automatic restarts.
-
The PHP sensor generates reasonable defaults for PHP Tracing extension's INI settings. However, you can adjust these settings to accommodate for highly specific needs. For more information, see Advanced customization.
If you encounter issues with automatic installation of the PHP Tracing extension, you can also manually install it. For more information, see Manually installing PHP Tracing extension.
Advanced customization
The PHP sensor frequently overwrites zzz-instana.ini, so do not change this INI file. Instead, you can add your own custom INI file that overrides the default Instana INI settings in zzz-instana.ini. PHP loads the INI files in alphanumeric order, with the last occurring instance of a setting being the effective value. To make sure the INI settings in your custom INI file override the INI settings in zzz-instana.ini, name your custom INI file to zzzzz-instana-extras.ini (notice the prefix zzzzz-) so that it loads after zzz-instana.ini. In containerized scenarios, your custom INI file can be mounted dynamically or made part of the image.
The following settings are available for all versions of PHP:
-
instana.batch_threshold_us: The length and distance threshold in which batching of spans happens. The default value is 10000 microseconds. -
instana.backtrace_limit: Specifies the stack trace depth. The allowed value range is1-25(default). The stack trace configuration feature provides more control over stack trace collection than theinstana.backtrace_limitINI setting because it allows disabling stack trace collection completely or enabling them only for erroneous spans. For more details, refer to the Configuring stack traces section. -
instana.disabled_instrumentation(deprecated): Specifies a bitmask of instrumentations to disable. The default value is 0 (none). For more details, refer to the Disabling instrumentation section. This INI setting is deprecated and replaced by the span disabling feature, which provides better instrumentation disabling configurability. -
instana.disable_userland_tracing: Disables all tracing for nonnative PHP extensions and PHP userland code like frameworks. The default value is 0 (off). -
instana.enable_cli: Enable or disable tracing for the CLI SAPI. 1 = on. 0 = off. The default value is 0 (off). -
instana.log_level: The level to log: 0 = off, 1 = ERROR, 2 = WARN, 3 = INFO, and 4 = DEBUG. The default value is 0 (off). -
instana.segfault_error_log: Capture or avoid a backtrace to PHP's error log on segmentation faults. The default value is 0 (off). -
instana.span_chunk_size: The number of spans to keep in PHP's memory before they are sent to the agent. This number directly affects batching. For example, chunks of one effectively disable batching.
The following settings are exclusive to PHP 5:
-
instana.socket: The address of the TCP socket of the Instana PHP sensor. The socket address is determined during installation and defaults to tcp://127.0.0.1:16816.
The following settings are exclusive to PHP 7.0 and later:
-
instana.buffer_hard_limit: The maximum number of spans to be kept in the buffer if the agent becomes unresponsive. Spans starting from the oldest are dropped until the buffer is contained within this limit. The default value is 1000. -
instana.buffer_maximum_delay_ms: The maximum interval between subsequent clearance of a span buffer. The default value is 1000 ms. -
instana.buffer_soft_limit: The maximum number of spans to be buffered before a span buffer is cleared. The default value is 500.
The following settings are exclusive to PHP 8.1 and later:
-
instana.span_filter_config_file: Specifies the absolute path of the YAML file that contains the configuration for disabling the traces or filtering spans. The PHP sensor updates this setting in the agentconfiguration.yamlfile to enable span disabling and filtering. The default value is<System_Temp>/instana-php/instana_span_filter_config.yaml. For more information about this setting, see Additional steps for YAML configuration section.
The following table is a complete list of environment variables for configuring the PHP extension:
| Environment variable | Default value |
|---|---|
INSTANA_AGENT_HOST |
127.0.0.1 |
INSTANA_AGENT_PORT |
42699 |
INSTANA_SERVICE_NAME |
EMPTY |
INSTANA_DEBUG |
OFF |
INSTANA_STACK_TRACE_LENGTH |
25 |
INSTANA_EXTRA_HTTP_HEADERS |
NONE |
INSTANA_SECRETS |
password, key, secret |
INSTANA_LOG_LEVEL |
NONE |
These environment variables take precedence over configurations in zzz-instana.ini. For more information, see environment variables.
If you need help with these settings, contact IBM Support.
Capturing custom HTTP headers
The PHP Tracer can capture custom HTTP headers in entry and exit spans. To capture these headers, specify the list of headers in any one of the following configurations:
-
PHP INI setting:
instana.extra_http_headers=HEADER1,HEADER2 -
Environment variable configuration:
INSTANA_EXTRA_HTTP_HEADERS=HEADER1;HEADER2
Alternatively, you can capture the HTTP headers of every tracked request or response by setting the headers list in the agent configuration.yaml file. For more information, see Capturing custom HTTP headers .
The PHP Tracer preserves spaces in both header keys and values.
This feature is available in PHP Tracer 4.7.0 and later.
Disabling spans
The PHP Tracer supports disabling traces or spans for specific span type (frameworks, libraries, and instrumentations) or entire groups of libraries (span category). With this span disabling feature, you can customize the tracing according to the needs of your application. Network costs can be reduced by reporting only the traces that are essential to your application.
This feature is available in PHP Tracer 5.3.0 and later.
Configuration methods
Use one of the following methods to provide the configuration to disable tracing:
For details about configuration precedence, see Configuration precedence for disabling spans.
Option 1: Span disabling through a custom configuration file
To disable spans through a custom configuration file, set the environment variable INSTANA_CONFIG_PATH to the absolute path of the YAML file with your configuration.
- The custom configuration file must not be a symbolic link. It must have read (
r) permission and all its parent directories must have execute (x) permission granted for the user or group with which the PHP runtime or PHP worker processes are running. - When you enable this feature for the first time or start with an empty YAML configuration, restart the PHP runtime after updating the configuration. Subsequent configuration changes take effect without requiring another restart.
For details about the span disabling configuration, see Span disabling configuration.
Example: To disable tracing for all databases calls (except MongoDB) and all logging frameworks, complete the following steps:
-
Create a separate YAML file and copy the following configuration into it:
tracing: disable: - databases: true - mongodb: false - logging: true -
Set the environment variable
INSTANA_CONFIG_PATHto the absolute path of the YAML file to which the content is placed as follows:INSTANA_CONFIG_PATH=<your YAML file>
Option 2: Span disabling through Instana agent configuration
To configure span disabling through Instana agent configuration, create or update the com.instana.tracing.disable section with span disabling configuration in the agent configuration.yaml file.
Additional steps are required in certain PHP runtimes when configuring span filtering through this method. For details, see Additional steps for YAML configuration.
For details about the span disabling configuration, see Span disabling configuration.
Example: To disable tracing for all database calls (except Redis) and all logging frameworks, update the agent configuration.yaml with the following snippet:
com.instana.tracing:
disable:
- databases: true
- redis: false
- logging: true
Span disabling configuration
For information about span disabling configuration syntax, see Disabling tracing.
Disabling tracing for a category disables the span generation for all the libraries under that category. See the following list of categories supported by PHP Tracer:
- databases
- frameworks
- messaging
- protocols
- logging
- templating
- Others (No category key is available for others)
You can use all instrumentation identifiers listed in the auto-instrumented libraries and frameworks table to configure span disable rules for specific span types.
Configuration precedence for disabling spans
Span disabling rules are applied in the following order of precedence, listed from highest to lowest:
- Span disabling rules from the custom configuration file that is passed through the
INSTANA_CONFIG_PATHenvironment variable. - Span disabling configured in the
instana.disabled_instrumentationINI setting. - Span disabling rules from the agent
configuration.yamlfile.
If a PHP runtime detects multiple configurations, it applies only the span disabling rules from the configuration with the highest precedence.
For example, if a PHP runtime has the following span disabling rules set through INSTANA_CONFIG_PATH environment variable:
com.instana.tracing:
disable:
- logging: true
- databases: true
- redis: false
And the same runtime has the following INI setting:
instana.disabled_instrumentation=24 ; disables redis (16) and curl (8) instrumentations
With this example configuration, the PHP Tracer works as follows:
- Tracing for all logging libraries is disabled.
- Tracing for all databases is disabled except for Redis.
The instana.disabled_instrumentation INI setting is ignored as the INSTANA_CONFIG_PATH environment variable takes precedence. Therefore, all instrumentations that are not disabled through the configuration file specified by the INSTANA_CONFIG_PATH environment variable are enabled.
If span disabling rules are set through both the INSTANA_CONFIG_PATH environment variable and the agent configuration.yaml file, then the rules from the configuration.yaml file are ignored.
Filtering spans
You can reduce the amount of trace data collected and ingested by Instana by using the span filtering feature. You can customize the filtering rules to exclude irrelevant spans or traces and include important ones based on span attributes. These filtering rules give you a finer control over selectively monitoring spans.
This feature is available in PHP Tracer 5.8.0 and later while HTTP span filtering is supported from PHP Tracer 5.7.1.
Configuration methods
Use one of the following methods to configure span filtering rules:
For details about configuration precedence between span disabling and span filtering, see Configuration precedence for filtering spans.
Option 1: Span filtering through a custom configuration file
To configure span filtering through a custom configuration file, set the environment variable INSTANA_CONFIG_PATH to the absolute path of the YAML file with your configuration.
- The custom configuration file must not be a symbolic link. It must have read (
r) permission and all its parent directories must have execute (x) permission granted for the user or group with which the PHP runtime or PHP worker processes are running. - When you enable this feature for the first time or start with an empty YAML configuration, restart the PHP runtime after updating the configuration. Subsequent configuration changes take effect without requiring another restart.
For details about the filtering configuration, see Span filtering configurationspan filtering configuration.
For a list of span attributes that can be used in span filtering configuration, see Span filtering configuration.
Example: To exclude spans with HTTP endpoints that end with /health or /ping, complete the following steps:
-
Create a separate YAML file and copy the following configuration into it:
tracing: filter: exclude: - name: ignore status checks attributes: - key: http.url values: [/health, /ping] match_type: endswith -
Set the environment variable
INSTANA_CONFIG_PATHto the absolute path of the YAML file to which the content is placed as follows:INSTANA_CONFIG_PATH=<your YAML file>
Option 2: Span filtering through Instana agent configuration
To configure span filtering through Instana agent configuration, create or update the com.instana.tracing.filter section with span filtering configuration rules in the agent configuration.yaml file.
Additional steps are required in certain PHP runtimes when configuring span filtering through this method. For details, see Additional steps for YAML configuration.
For details about the span filtering configuration, see Span filtering configuration.
For a list of span attributes that can be used in span filtering configuration, see Span attributes for filtering.
For details about configuration precedence between span disabling rules and span filtering rules, see Configuration precedence.
Example: To exclude all PDO spans on the tempdb, update the agent configuration.yaml with the following snippet:
com.instana.tracing:
filter:
exclude:
- name: exclude PDO spans for tempdb
attributes:
- key: pdo.dsn
values: [dbname=tempdb]
match_type: contains
Span filtering configuration
The span filtering rules use the following YAML syntax:
filter:
deactivate: <boolean>
<policy>: exclude | include
- name: <string>
suppression: <boolean> # only applicable to exclude rules
attributes:
- key: <string> # category | kind | type | span attribute (like http.url, pdo.stmt, etc.)
values: List <string>
match_type: <string> # strict | startswith | endswith | contains
| Field | Required | Description |
|---|---|---|
filter |
Mandatory | Root node for all filtering rules. |
deactivate |
Optional | Feature toggle to deactivate filter configuration when set to true without removing configured filter rules. Default value is false (filtering is activated). |
policy |
Mandatory | exclude policy holds the exclude rules that exclude spans from a trace. include policy holds the include rules that include spans in a trace. include rules override exclude rules. |
name |
Mandatory | Human-readable name that describes the filter rule. |
suppression |
Optional | Specifies whether to suppress child spans and downstream tracing when a span matches an exclude rule. Default value is true. When set to false, the parent span is excluded from the trace but downstream tracing is not suppressed. |
attributes |
Mandatory | List of span attributes that must all match for a rule to apply. |
key |
Mandatory | Span attribute key. |
values |
Mandatory | List of values to match for the span attribute key. An attribute matches if any of its values match. Wildcards and regular expressions are not supported. |
match_type |
Optional | Defines how the values of span attributes are matched. Valid values: strict (default), startswith, endswith, and contains. |
Span kinds for filtering
You can use the exit span kind to match various exit spans.
Span categories for filtering
You can use the following span categories for filtering: databases, frameworks, messaging, http, logging, templating. See auto-instrumented libraries and frameworks to determine which category a technology or span type belongs to.
Span types for filtering
You can use all instrumentation identifiers listed in the auto-instrumented libraries and frameworks as span types for filtering.
Span attributes for filtering
The following subsections list the span attributes for each span type that can be used for filtering.
php span type
| Span attribute | Description | Example value |
|---|---|---|
php.script |
The relative path of the PHP script from the document root. The value always begins with a /. |
/index.php |
php.version |
PHP version | 8.5.1 |
Span attributes for http span category
curl, pecl_http, soap, and streams are of the http span type and belong to the http span category. The following span attributes of the http span type can be used for HTTP endpoint filtering:
| Span attribute | Description | Example value |
|---|---|---|
http.url |
URL | http://www.example.com/items |
http.method |
HTTP method | GET |
http.status |
HTTP response status code | 200 |
http.host |
Hostname | www.example.com |
http.header.<header-name> |
HTTP header | header-value |
http.params |
HTTP query string | action=edit&id=5 |
http.route_id |
Route ID. Available for the root PHP span when a Laravel, Symfony, or Laminas call involves a named route. | home |
http.path_tpl |
Route URI. Available for the root PHP span when a Laravel call involves routing. | /products/{category}/item/{item} |
soap.action |
SOAP action to call on the endpoint | http://www.example.com/item/#delete |
frameworks span category
| Framework | Span type | Span attributes |
|---|---|---|
| Laminas | laminas |
laminas.controller, laminas.action, laminas.route_name. laminas.module, laminasview.template, laminasview.subtemplate_count, laminasview.renderer |
| Laravel | laravel |
laravel.action, laravel.controller, laravel.route |
| Symfony | symfony |
symfony.action, symfony.controller, symfony.route, symfony.api_collection_operation, symfony.api_item_operation, symfony.api_subresource_operation_name, symfony.api_resource_class, symfony.route_params, symfony.event_count |
| WordPress | wordpress |
wp.action, wp.view, wp.post_title |
| Zend Framework | zf |
zf.controller, zf.action, zf.route_name. zf.module, zfview.template, zfview.subtemplate_count, zfview.renderer |
databases span category
| Databases | Span type | Span attributes |
|---|---|---|
| Cassandra | cassandra |
cassandra.cluster, cassandra.keyspace, cassandra.query, cassandra.error |
| Couchbase | couchbase |
couchbase.hostname, couchbase.bucket, couchbase.type, couchbase.stmt, couchbase.error, couchbase.error_code |
| Elasticsearch | elasticsearch |
elasticsearch.id, elasticsearch.index, elasticsearch.type, elasticsearch.action, elasticsearch.address, elasticsearch.endpoint, elasticsearch.error, elasticsearch.hits, elasticsearch.port, elasticsearch.query |
| IBM Db2 | db2 |
db2.dsn, db2.stmt, db2.error |
| LDAP | ldap |
ldap.url, ldap.query, ldap.error |
| Memcache | memcache |
memcache.command, memcache.connection |
| Memcached | memcache |
memcached.connection, memcached.operation, memcached.resultCode, memcached.resultMessage |
| MongoDB | mongo |
mongo.command, mongo.service, mongo.filter, mongo.namespace, mongo.error, mongo.error_code |
| MS SQL | mssql |
mssql.host, mssql.port, mssql.user, mssql.db, mssql.stmt, mssql.error |
| MySQL | mysql |
mysqli.dsn, mysqli.stmt, mysqli.error |
| OCI8 | oci8 |
oci8.conn, oci8.stmt, oci8.error, oci8.error_code |
| PDO | pdo |
pdo.driver, pdo.dsn, pdo.stmt, pdo.error, pdo.error_code |
| Redis | redis |
redis.command, redis.connection, redis.driver, redis.key, |
messaging span category
| Messaging | Span type | Span attributes |
|---|---|---|
| AMQP | amqp |
amqp.connection, amqp.command, amqp.routingkey |
| Google Cloud Pub/Sub | gcpsa |
gcps.op, gcps.projid, gcps.sub, gcps.top, gcpsa.op, gcpsa.projid, gcpsa.snap, gcpsa.sub, gcpsa.top |
gcps and the span attributes for snapshot related spans have the prefix gcpsa.logging span category
| Logging | Span type | Span attributes |
|---|---|---|
| Drupal logger | log.drupal |
log.message |
| Monolog | log.monolog |
log.message |
| Yii logger | log.yii |
log.message |
| Zend logger | log.zendlog |
log.message |
templating span category
| Templating | Span type | Span attributes |
|---|---|---|
| Blade | blade |
blade.view, blade.path, blade.subtemplate_count |
| Twig | twig |
twig.name, twig.path, twig.subtemplate_count |
| Instrumentation | Span type | Span attributes |
|---|---|---|
| Shell | shell |
shell.cmd, shell.exitCode |
| Exceptions | exceptions |
error.file, error.msg, error.type |
| Sessions | sessions |
session.save_handler |
Example span filtering configuration
The following example shows a span filtering configuration:
# Use 'tracing' section if using custom configuration file
# Use 'com.instana.tracing' section if using agent configuration.yaml file
com.instana.tracing:
filter:
exclude:
- name: exclude HTTP spans based on URL attribute
attributes:
- key: http.url
values: [http://service.app.com]
match_type: startswith
- name: exclude HTTP spans based on HTTP header attribute
suppression: false
attributes:
- key: http.header.X-APPNAME
values: [MyApp]
match_type: strict
- name: exclude logging spans
attributes:
- key: category
values: [logging]
include:
- name: include HTTP spans based on HTTP method and HTTP URL attributes
attributes:
- key: http.method
values: [GET, POST]
- key: http.url
values: [/login, /cart/add, /payment/checkout]
match_type: endswith
- name: include monolog spans related to errors
attributes:
- key: type
values: [monolog]
- key: log.message
values: [error, fail]
match_type: contains
In the preceding example, the filtering configuration enforces the following rules:
- Exclude HTTP spans whose URL starts with
http://service.app.comand suppress child spans and downstream tracing. - Exclude HTTP spans that contain a request header
X-APPNAME:MyAppand do not suppress child spans and downstream tracing. - Exclude logging spans.
- Include HTTP spans with the
GETorPOSTmethod, and a URL that ends with/login,/cart/add, or/payment/checkout. - Include Monolog spans with a message containing
errororfail.
Configuration precedence for filtering spans
Configuration rules related to span disabling and span filtering are applied in the following order of precedence:
- Span disabling configuration through custom configuration file
- Span filtering configuration through custom configuration file file
- Span disabling configuration through agent
configuration.yamlfile - Span filtering configuration through agent
configuration.yamlfile
When a custom configuration file is used, the rules in the agent configuration.yaml file are ignored. If both disabling and filtering are configured in the same file, both apply, but a disabling rule that affects the same span as a filtering rule takes precedence.
instana.disabled_instrumentation INI setting cannot be included with an includefilter rule. Limitations of span filtering
- Suppressing child spans and downstream tracing is not supported in the following cases:
- Exclude rules based on span attributes that are only known after the HTTP request completes. For example, an exclude rule with
http.statusorhttp.header.<response-header-name>span attributes cannot enforce suppression. - Exclude rules based on
http.route_idorhttp.path_tplspan attributes.
- Exclude rules based on span attributes that are only known after the HTTP request completes. For example, an exclude rule with
- Suppressing downstream tracing is not supported for exclude rules on non-root and non-HTTP spans.
Configuring stack traces
Configure stack trace collection to control the amount of trace data collected and ingested by Instana.
By default, the PHP Tracer captures stack trace for all spans (except entry spans) with a stack trace depth of 25 frames. You can control the amount of trace data collected and ingested by Instana by using the stack trace configuration to customize the PHP Tracer to collect stack trace only for erroneous spans, or disable stack trace collection completely while also having control over the stack trace depth.
The PHP Tracer always collects stack traces for exception spans, even if stack trace collection is disabled, because they offer insights into debugging runtime exceptions in your PHP application.
This feature is available in PHP Tracer 5.9.0 and later.
Configuration methods
Configure stack traces using custom configuration files, environment variables, or Instana agent configuration.
Use one of the following methods to configure stack traces:
For details about configuration precedence between different configuration methods, see Configuration precedence for stack traces.
Option 1: Configuring stack traces through a custom configuration file
Configure stack traces by setting the INSTANA_CONFIG_PATH environment variable to point to a YAML configuration file.
To configure stack traces through a custom configuration file, set the environment variable INSTANA_CONFIG_PATH to the absolute path of the YAML file with your configuration.
- The custom configuration file must not be a symbolic link. It must have read (
r) permission and all its parent directories must have execute (x) permission granted for the user or group running the PHP runtime or PHP worker processes. - When you enable this feature for the first time or start with an empty YAML configuration, restart the PHP runtime after updating the configuration. Subsequent configuration changes take effect without requiring another restart.
For details about the stack trace configuration, see Stack trace configuration.
Example: To collect stack trace for only erroneous spans with a stack trace depth of 12, complete the following steps:
- Create a separate YAML file and copy the following configuration into it:
tracing: global: stack-trace: error stack-trace-length: 12 - Set the environment variable INSTANA_CONFIG_PATH to the absolute path of the YAML file to which the content is placed as follows:
INSTANA_CONFIG_PATH=<your YAML file>
Option 2: Configuring stack traces through environment variables
Configure stack trace level and depth using the INSTANA_STACK_TRACE and INSTANA_STACK_TRACE_LENGTH environment variables.
You can also configure the stack trace level and stack trace length through the environment variables INSTANA_STACK_TRACE and INSTANA_STACK_TRACE_LENGTH.
| Environment variable | Description | Supported values |
|---|---|---|
| INSTANA_STACK_TRACE | Stack trace level | all (default): Collect stack traces for all spans
|
| INSTANA_STACK_TRACE_LENGTH | Stack trace depth | 1 – 25 |
Option 3: Configuring stack traces through Instana agent configuration
Configure stack traces by updating the com.instana.tracing.global section in the agent configuration.yaml file.
To configure stack traces through Instana agent configuration, create or update the com.instana.tracing.global section with stack trace configuration in the agent configuration.yaml file.
Additional steps are required in certain PHP runtimes when configuring stack traces feature through this method. For details, see Additional steps for YAML configuration.
For details about the stack trace configuration, see Stack trace configuration.
Example: To collect stack trace for all spans with a stack trace depth of 4, update the agent configuration.yaml with the following snippet:
com.instana.tracing:
global:
stack-trace: all
stack-trace-length: 4
Stack trace configuration
Use YAML syntax to configure stack trace level and depth settings.
Use the following YAML syntax to provide the stack trace configuration:
# Use 'tracing' section if using custom configuration file
# Use 'com.instana.tracing' section if using agent configuration.yaml file
tracing:
global:
stack-trace: <string>
stack-trace-length: <int>
| Field | Description | Supported values |
|---|---|---|
stack-trace |
Stack trace level | all (default): Collect stack traces for all spans
|
stack-trace-length |
Stack trace depth | 1 – 25 |
Configuration precedence for stack traces
Stack trace configuration is applied in order of precedence from custom configuration files to agent configuration.
Stack trace configuration is applied in the following order of precedence, listed from highest to lowest:
- Stack trace configuration from the custom configuration file that is passed through the INSTANA_CONFIG_PATH environment variable.
- Stack trace configuration set through the environment variables INSTANA_STACK_TRACE and INSTANA_STACK_TRACE_LENGTH.
- Stack trace length set through
instana.backtrace_limitINI setting. - Stack trace configuration from the agent configuration.yaml file.
The precedence is evaluated and applied separately for stack trace mode and stack trace length settings across the different configuration methods listed in the preceding section.
Additional steps for YAML configuration
The PHP sensor detects changes in the agent configuration.yaml file and makes a copy of the global, disable, and filter sections in com.instana.tracing into a separate file at <System Temp>/instana-php/instana_span_filter_config.yaml. The generated file's absolute path is assigned to the instana.span_filter_config_file INI setting so that PHP Tracer can detect and apply any subsequent changes to the configuration.yaml file without any restarts to the PHP runtime. The PHP runtime must have read access to the system's temp folder to read the configuration.
The following subsections provide the additional steps that are required in some environments for the PHP runtime to have sufficient access to the system's temp folder.
Linux PHP runtimes running as a systemd service with PrivateTmp directive
Configure systemd services with PrivateTmp directive to allow PHP Tracer access to YAML configuration.
If your PHP runtime is a systemd service configured with the PrivateTmp directive, then the PHP processes get their own temp directory that is isolated from the host's system temp directory. The PHP sensor cannot write to the process's temp directory, so the PHP Tracer cannot read the YAML configuration in such PHP runtimes.
If disabling the PrivateTmp setting in the PHP systemd service is not ideal to your requirements, you can use a custom configuration file instead for configuring span disabling rules, span filtering rules and stack traces without disabling PrivateTmp in the PHP systemd service.
Alternatively, if your PHP runtime does not need the temp file system isolation offered by the PrivateTmp setting, then you can disable PrivateTmp for the PHP systemd service by following these steps and continue to use the agent configuration.yaml file for configuring span disabling rules, span filtering rules and stack traces:
- Edit the PHP systemd service unit file by running the following command:
sudo systemctl edit <systemd-service-unit-name> # systemd service names are usually named like apache2.service, php8.3-fpm.service, etc., - Set the
PrivateTmpdirective tofalsein the[Service]section:[Service] PrivateTmp=false - Reload systemd configuration
systemctl daemon-reload - Restart the systemd service to apply the changes.
Windows IIS server
IIS worker processes sometimes lack access to the Windows temp folder. This insufficient access to the temp folder is due to the application pool identity that is used to run the worker processes lacking sufficient read or write permissions to the temp folder. To resolve this access issue, perform the following steps:
-
Confirm the identity of your application pool by running the following command in your PowerShell terminal:
& $env:windir\system32\inetsrv\appcmd.exe list apppool <your AppPool> /text:processModel.identityType -
If the identity is not
ApplicationPoolIdentity, run the following command to update the identity:& $env:windir\system32\inetsrv\appcmd.exe set AppPool <your AppPool> -processModel.identityType:ApplicationPoolIdentity -
Restart your application pool to apply the changes:
& $env:windir\system32\inetsrv\appcmd.exe recycle apppool <your AppPool>IIS server detects the application pool running with the identity
ApplicationPoolIdentity, and creates a virtual user with the name of your application pool. -
To give the PHP runtime, that is, IIS worker processes read access to the
<SYSTEM_TEMP>directory, use the following command:icacls "<SYSTEM_TEMP>" /grant "IIS APPPOOL\<your AppPool>:(OI)(CI)R" /T /C
Disabling instrumentation
To disable instrumentation for a specific library or a set of libraries from the PHP INI settings, use the instana.disabled_instrumentation setting. It takes the bitmask value of the libraries for which you want the tracing to be disabled. To get the bitmask values of the libraries, refer to the Instrumentation flag column located in the Instrumented libraries and frameworks section.
To disable instrumentation for multiple libraries, add its respective Instrumentation flag values. For example, to disable tracing for MongoDB calls (with instrumentation flag: 32) and Redis data store calls (with instrumentation flag: 16), add the following line in your INI settings file:
instana.disabled_instrumentation=48 ; 32 + 16 = 48
Use the Disabling spans feature instead of the instana.disabled_instrumentation setting for better control over generating spans in your PHP Tracer.
Automatic restarts
Since the PHP Tracer is a PHP extension that is loaded into the PHP runtime, enabling and disabling PHP tracing or changing the installed PHP Tracing extension version requires a restart of the PHP runtime for the changes to take effect.
The PHP sensor is capable of automatically and gracefully restarting Apache and PHP-FPM runtimes. But manual restart is required for the following PHP runtime scenarios:
- PHP runtimes with CGI SAPI: You need to manually restart the PHP runtime.
- PHP runtimes with pre-forked worker processes: You need to manually restart the PHP master process.
You can automate the manual restarts required in the preceding cases and also change the way PHP sensor attempts to restart your PHP runtime by specifying a notification script for tracing.notificationScript in the com.instana.plugin.php section in the agent configuration.yaml file.
This setting takes the absolute path to an executable shell script (Linux) or PowerShell script (Windows). When a PHP runtime restart is needed, the PHP sensor runs the script that is defined in tracing.notificationScript instead of using its default restart commands.
Considerations for designing the notification script
The notification script runs once per PHP runtime, which means that the script might not be triggered for all processes that run the same PHP executable file. To load the PHP Tracing extension into memory, you must make sure that your script restarts all the processes that run from that PHP executable file.
When this script is configured and run successfully, it overrides the default mechanism for automatic restarts. Unlike the default mechanism, the script gets executed for any SAPI, so it can be used to automate restarts for PHP-CGI environments. If you want to disable automatic restarts completely, configure an empty script.
The PHP sensor sets the following environment variables for the script execution:
INSTANA_EXT_VERSION_OLD = the version of the tracing extension currently in memory
INSTANA_EXT_VERSION_NEW = the version of the tracing extension after a restart
INSTANA_PID_HOST = the PID of the process on the host, e.g. your Apache, PHP-FPM or PHP-CGI
INSTANA_PID_CONTAINER = the PID the host process has in a container (if applicable)
INSTANA_CONTAINER = the ID/name of the container the process is running in (if applicable)
The following example shows a script that logs extension changes to a file and restarts Apache:
#!/bin/bash
echo "Found new tracing extension." >> php_update.log;
echo "INSTANA_EXT_VERSION_OLD=$INSTANA_EXT_VERSION_OLD" >> php_update.log;
echo "INSTANA_EXT_VERSION_NEW=$INSTANA_EXT_VERSION_NEW" >> php_update.log;
echo "INSTANA_PID_HOST=$INSTANA_PID_HOST" >> php_update.log;
echo "INSTANA_PID_CONTAINER=$INSTANA_PID_CONTAINER" >> php_update.log;
echo "INSTANA_CONTAINER=$INSTANA_CONTAINER" >> php_update.log;
echo "restarting apache" >> php_update.log;
apachectl -k graceful >> php_update.log;
If your Apache runs inside a container, replace the last line in the sample script with the following line:
docker exec $INSTANA_CONTAINER apachectl -k graceful;
For PHP-FPM, you can send a SIGUSR2 to gracefully restart it as shown in the following example:
docker exec $INSTANA_CONTAINER kill -USR2 $INSTANA_PID_CONTAINER;
A graceful restart loads the PHP extension into memory without restarting the master process. So this loading works even when the process runs as PID 1 inside the container. If you cannot or do not want to use the restart approach, you can also create a snapshot of the running container instance, stop it, and open a new instance easily:
#!/bin/bash
IMAGE_HASH=$(docker inspect --format='{{.Config.Image}}' $INSTANA_CONTAINER)
IMAGE_NAME=$(docker images | grep $IMAGE_HASH | awk '{print $1}')
IMAGE_TAG="instana-php-$INSTANA_EXT_VERSION_NEW"
docker commit $INSTANA_CONTAINER $IMAGE_NAME:$IMAGE_TAG &&
docker stop $INSTANA_CONTAINER &&
docker run -d --rm $IMAGE_NAME:$IMAGE_TAG
This action uses the container ID passed to the script to find the name of the container image. It then commits the currently running container into a new image that is tagged with the new PHP extension version number. It then stops the original container and starts a container from the newly tagged image. While this action triggers the installation routine in the PHP sensor again, it does not trigger the notification script again because the extension is already installed.
These examples assume that you are using Docker as your container engine. But since the triggered shell script is completely under your control, you can put any logic that you need to make automatic restarts work for your setup.
Disabling PHP tracing
To disable PHP tracing, complete the following steps:
-
In the
com.instana.plugin.phpsection in the agentconfiguration.yamlfile, settracing.enabledtofalse. If the agentconfiguration.yamlfile does not have thecom.instana.plugin.phpsection, you need to add it as follows:com.instana.plugin.php: tracing: enabled: falseNote: Commenting thecom.instana.plugin.phpsection does not disable PHP tracing as it is enabled by default.The PHP sensor automatically removes the PHP Tracing extension's INI settings from the PHP INI configuration. Then, it attempts to gracefully restart the PHP runtime to remove the PHP Tracing extension from memory. After the PHP runtime is successfully restarted, PHP tracing is completely disabled.
-
If the PHP sensor cannot automatically restart the PHP runtime, manually restart the PHP runtime to completely disable PHP tracing. The ability of the PHP sensor to automatically restart the PHP runtime depends on the SAPI type. You can control this behavior and automate the PHP runtime restart that is needed to remove the PHP Tracer from memory. For more information, see Automatic restarts.
Note: You must read Automatic restarts and carefully consider if your PHP runtime needs to be manually restarted to remove the PHP Tracing extension from memory. -
Verify that the PHP Tracing extension is no longer enabled in your PHP runtime by checking that
instanais not listed in the list of extensions that are enabled in your PHP INI configuration. You can get the list of enabled PHP extensions by executing the PHP binary used by your PHP runtime with the option-m. The following example shows how to list the enabled PHP extensions by using thephp-fpmbinary:$> php-fpm -m [PHP Modules] curl json PDO sqlite3 Zend OPcache zlib [Zend Modules] Zend OPcacheNote: To confirm whether the PHP Tracing extension is disabled in Apache with themod_phpruntime, create a PHP script with the content<?php phpinfo();in the webserver's document root to make Apache serve the script. You can then open the URL to this script in your browser and verify thatinstanais not present in the list of enabled PHP extensions.If you encounter errors during this procedure, you can manually disable PHP tracing and uninstall the PHP Tracing extension. For more information, see Manually disabling PHP tracing.
Uninstalling the Instana agent does not automatically remove the PHP Tracing extension from the PHP runtimes that are already instrumented. Before you uninstall the Instana agent, disable the PHP tracing to uninstall the PHP Tracing extension from all PHP runtimes in the host. For more information, see Uninstalling the Instana agent.
Disabling PHP Tracing extension installation
To disable the automatic installation of the PHP Tracing extension in newly detected PHP runtimes, set tracing.installExtension to false in the com.instana.plugin.php section in the agent configuration.yaml file:
com.instana.plugin.php:
tracing:
enabled: true
installExtension: false
Troubleshooting
Absence of PHP traces in the Instana UI
If you use Plesk, you need to run plesk bin php_handler --reread.
If you don't see any traces appearing in the Instana UI for PHP applications, complete the following steps:
-
Verify the following prerequisites:
- The PHP sensor is enabled. For more information, see Disabling PHP Tracing.
- The PHP Tracing extension binary is available. For more information, see Disabling the PHP Tracing extension.
- The PHP Tracing extension is enabled in the agent configuration file. For more information, see Removing the PHP Tracing extension file.
-
Reload the PHP Tracing extension by running the following
reloadcommand on the service that runs PHP applications:-
For Apache:
systemctl reload apache2 -
For PHP-FPM:
systemctl reload php<version>-fpmReplace <version> in the reload command with the actual version that is installed in the system.
-
If you still don't see any traces in the Instana UI and your operating system includes SELinux by default or adds it to the environment for security purposes, SELinux might be responsible for the issue.
The PHP Tracer extension communicates with the PHP daemon over the Unix TCP socket <socket path> and with the Instana agent over TCP/IP port 42699. When SELinux is set to enforcing mode, it prevents the PHP extension and daemon from communicating with each other unless SELinux is configured to allow it.
To verify whether SELinux is responsible for the issue, check /var/log/audit/audit.log for any silent denials that are recorded for the PHP daemon. Alternatively, you can do a smoke test by completing the following steps:
- Disable SELinux temporarily.
- Restart PHP daemon.
If SELinux is identified as the cause for the issue, you can resolve it by using any one of the following options:
-
Configure SELinux to allow PHP Tracer to communicate: With SELinux, you can follow your own security policies to configure a custom policy to allow for communication. For more information about creating and modifying SELinux policy, see the following links:
-
Set SELinux to permissive mode: In this mode, your services can operate without restrictions. You can restore the default setting by restarting the server. To set SELinux to permissive mode, see SELinux permissive mode.
-
Disable SELinux: Instana does not actively encourage you to disable security software. A right and safe approach is to create a SELinux policy. However, if you decide to disable SELinux, see Disable SELinux.
Enabling logging
By default, logging is turned off. To enable it, refer to the following steps.
- Enable logging by using environment variables.
- To set the log level to debug, set
INSTANA_DEBUGtoTRUEorINSTANA_LOG_LEVEL=4
- To set the log level to debug, set
- Enable logging by using INI file.
-
Locate a file named
zzz-instana.iniin the scan directory of your PHP installation. For example, runningphp --ini | grep zzz-instana.iniorphp-fpm<version> -i | grep zzz-instana.inireveals its location. -
Add the line
instana.log_level=4tozzz-instana.ini. -
When you run the PHP runtime of your choice, make sure that some logging is present in the output and that the extension is enabled. For example, you can run
php --ri instanaorphp-fpm<version> -i | grep instanato verify.Example:
[instana.INFO] Initializing, logging at level 4 -
Reload the PHP tracing extension as described here. Skipping this step will ultimately result in no logging.
-
/var/log/apache2/error.log for Apache2 and /var/log/php<version>-fpm.log for PHP-FPM.Manually installing PHP Tracing extension
To manually install the PHP Tracing extension, complete the following steps:
-
Download the Instana PHP Tracing extension as follows:
-
Download the shell script from the following repository:
https://artifact-public.instana.io/artifactory/shared/com/instana/php/instana-ext-download-script/php-instana-ext-download-script.sh -
Run the shell script to download the extension suitable for your environment. The following command shows the available options:
./php-instana-ext-download-script.sh -a <aarch64/x86_64> -l <musl/glibc> -p <PHP version> -t <NTS/ZTS> -d <serverless/native> -s <OpenSSL version> -v <Instana extension version>-
For the PHP version, provide major and minor version numbers. For example, to download the Instana extension for PHP 8.4.12, run the shell script with flag
-p 8.4. -
For the OpenSSL version, use the option
-s ssl1to download the extension that supports OpenSSL 1.1 or use-s ssl3to download the extension that supports OpenSSL 3.x. -
For the Instana extension version, the default value is
release, which downloads the latest version available. Use-vflag to download the artifact for any specific version. For example, run the script with-v 4.7.0to download the extension with the release version 4.7.0. -
To see all the options available for the script, run the following command:
./php-instana-ext-download-script.sh
-
-
-
Install the extension as follows:
-
Move the downloaded
.sofile to the PHP CLI extension directory. -
Create an INI file,
zzz-instana.ini, as shown in the following example, and save it to the PHP CLI additional INI directory. Replace<hostIP>with the IP address of the Instana agent host so that the agent is reachable from the PHP environment.; this file was automatically generated by Instana ; ; any changes made to this file are expected to be overwritten when ; a new version of the Instana PHP Tracer extension is installed [instana] extension=<php cli extension dir path where extension.so file is placed> instana.socket=<hostIP>:16816 instana.agent_endpoint=http://<hostIP>:42699 instana.use_agent_endpoint=1 instana.auto_profile_socket=tcp://<hostIP>:42699 instana.enable_auto_profile=0 instana.secrets_matcher=contains-ignore-case instana.secrets_list="key,pass,secret" instana.extra_http_headers= instana.pid_in_root_namespace=<pid of PHP process in hostnamespace> instana.enable_cli=1
-
Manually disabling PHP tracing
Following the steps outlined in Disabling PHP tracing disables PHP tracing completely, including removal of the PHP Tracing extension from your PHP runtime.
If you encounter errors during this procedure and you want to manually disable PHP tracing and uninstall the PHP Tracing extension, complete the following steps:
-
Make sure that PHP tracing is disabled in the agent
configuration.yamlfile as follows:com.instana.plugin.php: tracing: enabled: falseThis configuration prevents the PHP sensor from reinstalling the PHP Tracing extension again.
-
Disable the PHP Tracing extension in your PHP INI configuration. See Disabling the PHP Tracing extension.
-
Remove the PHP Tracing extension file from your system. See Removing the PHP Tracing extension file.
Disabling the PHP Tracing extension
When the PHP sensor installed the extension, it also enabled the extension for your PHP installation. Enabling the extension means that the PHP sensor either placed the zzz-instana.ini file into your Additional Ini files folder or enabled it directly in your php.ini.
To find out where it was enabled, run the PHP binary for which you enabled tracing. The following example shows how to identify the configuration with a PHP-FPM binary:
$> php-fpm7.0 -i | egrep "^(Scan|Loaded)"
Loaded Configuration File => /etc/php/7.0/fpm/php.ini
Scan this dir for additional .ini files => /etc/php/7.0/fpm/conf.d
In this example, the zzz-instana.ini file is located in /etc/php/7.0/fpm/conf.d. If no Additional Ini files folder is available, or the zzz-instana.ini file does not exist at that location, check your php.ini instead. In this example, the file is in /etc/php/7.0/fpm/php.ini.
On Windows, run the following command in PowerShell to get the location of the php.ini file or the location of the Additional Ini files folder for PHP-CGI:
PS C:\> php-cgi -i | Select-String -Pattern '(Scan|Loaded Configuration)' | ForEach-Object { ($_ -replace '<br\s*/?>', "`n") -replace '<[^>]+>', ''}
Loaded Configuration File C:\Php\php.ini
Scan this dir for additional .ini files (none)
<?php phpinfo(); into a web accessible location on Apache and open it in a browser for the same information.To disable the PHP tracing extension, complete the following steps:
-
Open the appropriate
inifile in an editor and prefix the semicolon (;) in the lineextension=/path/to/instana.soas follows. Adding a semicolon comments out the line.;extension=/path/to/instana.soAlternatively, remove the line
extension=/path/to/instana.soaltogether. Do not remove it if you intend to enable the extension at a later point. -
If you have the
zzz-instana.inifile, you can also remove the file completely as follows:$> sudo rm /etc/php/7.0/fpm/conf.d/zzz-instana.iniOn Windows, you can remove the file by running the following command in PowerShell (as Administrator):
PS C:\> Remove-Item -Path C:\Php\conf\zzz-instana.iniImportant: Do not remove your entirephp.inifile. -
Restart your PHP runtime to remove the PHP Tracing extension from memory. If your PHP runtime uses pre-forked workers, you need to restart the PHP master process now.
Removing the PHP Tracing extension file
PHP logs startup errors when it cannot find an extension, so before you remove the extension, you must also disable it. For more information, see Disabling the PHP Tracing extension.
The PHP sensor places the Instana PHP tracing extension into the directory that is given in the extension_dir setting in your php.ini. To find out the setting, run the PHP binary for which you enabled tracing. The following example shows how to identify the configuration with a PHP-FPM binary:
$> php-fpm7.0 -i | egrep ^extension_dir
extension_dir => /usr/lib/php/20151012 => /usr/lib/php/ext
<?php phpinfo(); into a web accessible location on Apache and open it in a browser for the same information.The PHP sensor uses only the first value, so in the example, you can find the extension at /usr/lib/php/20151012. The path to the extension is also given in your php.ini or the zzz-instana.ini file.
On Windows, you can run the following command in PowerShell to find out extension_dir:
PS C:\> php-cgi -i | Select-String -Pattern 'extension_dir' | ForEach-Object { ($_ -replace '<br\s*/?>', "`n") -replace '<[^>]+>', ' '}
extension_dir C:\php\ext C:\php\ext
To remove the extension, run the following command:
$> sudo rm /usr/lib/php/20151012/instana.so
On Windows, you can remove the file by running the following command in PowerShell (as administrator):
PS C:\> Remove-Item -Path C:\Php\ext\instana.dll
If you are using pre-forked workers and did not already restart your PHP master process when you disabled the extension, you need to restart it for the changes to take effect.