Installation & Set Up
Connect your application with Inspector.
Server requirements
PHP >= 7.2
Install
You can install Inspector using composer:
Create an Inspector instance
Be sure to include the composer autoload in your application. The first step is to create an instance of the Configuration
class using the Ingestion Key.
Get a new Ingestion Key by signing up for Inspector (https://app.inspector.dev/register) and creating a new application.
Transactions
All start with a transaction
. A Transaction represents an execution cycle and it can contains one or hundreds of segments (database queries, internal functions, etc.).
You need to start a new Transaction as soon as possible in your application execution cycle to better represent the time your script takes to fulfill an HTTP request.
Typically the transaction should be started in the entry point of your application e.g. index.php
Set the Transaction result
When your application return a response back to the client you can setup the result of the transaction using the HTTP code:
Add Context
Each transaction can be enriched with additional information to have a more complete picture of the process execution context.
You can use the addCotext
method to attach new tabs to the current Transaction:
Contextual information will be reported as additional tabs in the Transaction view. This code example creates a new tab "Label" in the Transaction details as showed in the image below:
The context is designed to help developers easily collect custom data during an execution cycle.
Make Inspector available in your application globally
If you want to use the current Inspector instance inside your code to add contexual information or new segments, you need a way to make the Inspector instance available everywhere in your application.
Use an IoC container like PHP-DI is a common way to distribute internal services inside an application. If your application has one, or implement other similar strategies, you could put the Inspector instance in the registry:
in order to use it later inside your application (e.g. add segments):
Register callbacks
Using the beforeFlush()
static method you can register a list of callbacks that will be executed just before data are sent out of your application.
This method provides a simple hook to interact with your monitoring data at the end of the transaction execution.
You can also register multiple callbacks that will be executed in the same order:
By explicitly returning FALSE
from a callback, the current transaction will not be sent to the remote platform, regardless of the value returned by other callbacks:
Last updated