PHP Custom Instrumentation
  • 1 Minute to read
  • Dark
    Light
  • PDF

PHP Custom Instrumentation

  • Dark
    Light
  • PDF

Article Summary

Configuration

Custom Instrumentation allows you to track classes and functions not natively supported in our PHP Profiler. Include a stackify.json file in your application's DOCUMENT_ROOT.

Example:

{
  "instrumentation": [
    {
      "class": "SampleClass1",
      "method": "execute"
    },
    {
      "class": "SampleClass2",
      "method": "index"
    }
  ]
}
NOTE:

If you are trying to track methods in procedural code that has no class, you can leave the class empty.

{
  "instrumentation": [
    {
      "class": "",
      "method": "sample_function"
    }
  ]
}

Custom Instrumentation is supported in the Stackify PHP profiler 1.3+ versions.

Optionally, you may specify the location of stackify.json by adding stackify.config_file=[stackify.json path] to your php.ini.

Example:

[stackify]
extension=stackify.so
stackify.application_name=PHP Application
stackify.environment_name=Production
stackify.config_file=/var/www/html/stackify.json

Tracked Functions

Tracked Functions allows you track a specific method call across requests, data will show up in your application dashboard under the Tracked Functions tab.

Example:

{
  "instrumentation": [
    {
      "class": "SampleClass1",
      "method": "execute",
      "trackedFunction": true,
      "trackedFunctionName": "{{ClassName}}.{{MethodName}}"
    },
    {
      "class": "SampleClass2",
      "method": "index",
      "trackedFunction": true,
      "trackedFunctionName": "{{ClassName}}.{{MethodName}}"
    }
  ]
}

Custom Trace Entry Point

Custom Trace Entry Points are useful when profiling a PHP CLI application. By default each PHP file execution is tracked as a transaction. The following configuration allows you to detail a specific method to override this default behavior. This can be helpful when you have a long running PHP script that spawns multiple transactions (such as monitoring a queue).

{
  "instrumentation": [
    {
      "class": "QueueProcessor",
      "method": "processMessage",
      "startTrace": true
    }
  ]
}

See PHP CLI Support for more details on setting up a PHP CLI application.


Was this article helpful?