PHP Features
PECL Extension
Several instruments require the native extension to be included, including timing of Redis, Elasticsearch, and Memcached.
For more information, or to compile manually, the README has additional instructions.
sudo pecl install scoutapm
Deploy Tracking
Scout can track deploys, making it easier to correlate specific deploys to changes in performance.
Scout identifies deploys via the following approaches:
-
Detecting the current git sha (this is automatically detected when
composer install
is run) -
Setting the SCOUT_REVISION_SHA environment variable equal to the SHA of your latest release during deployment:
git rev-parse --short HEAD
Request Queuing
Our PHP integration can measure the time it takes a request to reach your application from farther upstream (a load balancer or web server). This appears in Scout as “Request Queueing” and provides an indication of your application’s capacity. Large request queueing time is an indication that your app needs more capacity.
Please view request queueing section to learn how to get these insights.
Custom Context
Context lets you see the key attributes of requests. For example, you can add custom context to answer critical questions like:
- Which plan was the customer who had a slow request on?
- How many users are impacted by slow requests?
- How many trial customers are impacted by slow requests?
- How much of an impact are slow requests having on our highest paying customers?
It’s simple to add custom context to your app:
use Scoutapm\Laravel\Facades\ScoutApm; // Laravel only: Add near the other use statements
ScoutApm::addContext("Key", "Value");
// for example, passing in the user_id
// ScoutApm::addContext("user_id", Auth::id());
// or if you have an $agent instance:
$agent->addContext("Key", "Value");
Context Key Restrictions
The Context key
must be a String
with only printable characters. Custom
context keys may contain alphanumeric characters, dashes, and underscores.
Spaces are not allowed.
Attempts to add invalid context will be ignored.
Context Value Types
Context values can be any json-serializable type. Examples:
"1.1.1.1"
"free"
100
PII
To best help protect your data, we suggest using ids instead of explicit names and emails
Custom Instrumentation
You can extend Scout to trace transactions outside our officially supported libraries (e.g. Cron jobs and other web frameworks) and time the execution of sections of code that falls outside our provided instrumentation.
Transactions & Timing
Scout’s instrumentation is divided into 2 areas:
- Transactions: these wrap around an entire flow of work, like a web request or Cron job. The Scout Web UI groups data under transactions.
- Timing: these measure small pieces of code that occur inside of a transaction, like an HTTP request to an outside service, or a database call. This is displayed within a transaction trace in the UI.
Instrumenting Transactions
A transaction groups a sequence of work under in the Scout UI. These are used to generate transaction traces. For example, you may create a transaction that wraps around the entire execution of a PHP script that is ran as a Cron Job.
The Laravel instrumentation does this all for you. You only will need to manually instrument transactions in special cases. Contact us at support@scoutapm.com for help.
Limits
We limit the number of unique transactions that can be instrumented. Tracking too many uniquely named transactions can impact the performance of the UI. Do not dynamically generate transaction names in your instrumentation as this can quickly exceed our rate limits. Use context to add high-dimensionality information instead.
Web or Background transactions?
Scout distinguishes between two types of transactions:
WebTransaction
: For transactions that impact the user-facing experience. Time spent in these transactions will appear on your app overboard dashboard and appear in the “Web” area of the UI.BackgroundTransaction
: For transactions that don’t have an impact on the user-facing experience (example: cron jobs). These will be available in the “Background Jobs” area of the UI.
$agent->webTransaction("GET Users", function() { ... your code ... });
$agent->send();
Timing functions and blocks of code
In existing transactions, both automatically created with Laravel instruments, and also manually created, you can time sections of code that are interesting to your application.
Traces that allocate significant amount of time to Controller
or Job
layers
are good candidates to add custom instrumentation. This indicates a significant
amount of time is falling outside our default instrumentation.
Limits
We limit the number of metrics that can be instrumented. Tracking too many unique metrics can impact the performance of our UI. Do not dynamically generate metric types in your instrumentation as this can quickly exceed our rate limits.
For high-cardinality details, use tags.
Getting Started
With existing code like:
$request = new ServiceRequest();
$request->setApiVersion($version);
It is wrapped with instrumentation:
// At top, with other imports
use Scoutapm\Laravel\Facades\ScoutApm;
// Replacing the above code
$request = ScoutApm::instrument(
"Custom", // Kind
"Building Service Request", // Name
function ($span) use ($version) {
$request = new ServiceRequest();
$request->setApiVersion($version);
return $request;
}
);
-
kind
- A high level area of the application. This defaults toCustom
. Your whole application should have a very low number of unique strings here. In our built-in instruments, this is things likeTemplate
andSQL
. For custom instrumentation, it can be strings likeMongoDB
orHTTP
or similar. This should not change based on input or state of the application. -
name
- A semi-detailed version of what the section of code is. It should be static between different invocations of the method. Individual details like a user ID, or counts or other data points can be added as tags. Names likeretreive_from_api
orGET
are good names. -
span
- An object that represents instrumenting this section of code. You can set tags on it by calling$span->tag("key", "value")
-
tags
- A dictionary of key/value pairs. Key should be a string, but value can be any json-able structure. High-cardinality fields like a user ID are permitted.ARM and graviton Support
We now have support for ARM and graviton.
-
Our PHP agent does not automatically detect ARM support, currently
- To explicitly connect, the core_agent_triple configuration setting must be specified:
SCOUT_CORE_AGENT_TRIPLE=aarch64-unknown-linux-musl SCOUT_CORE_AGENT_VERSION=v1.3.1
-