### Install Inspector PHP Agent Source: https://docs.inspector.dev/guides/raw-php/installation Installs the Inspector APM PHP agent using Composer. This is the primary method for adding the library to your project. ```bash composer require inspector-apm/inspector-php ``` -------------------------------- ### Start and Mark Transaction Source: https://docs.inspector.dev/guides/raw-php/installation Starts a new transaction, typically at the application's entry point, and marks it as a request. The transaction name is derived from the request URI. ```php $pathInfo = explode('?', $_SERVER["REQUEST_URI"]); $path = array_shift($pathInfo); /* * A transaction should start as soon as possible, * typically in the "index.php" file of your application. */ $inspector->startTransaction($path) ->markAsRequest(); // Continue with the script... ``` -------------------------------- ### Make Inspector Instance Global (IoC) Source: https://docs.inspector.dev/guides/raw-php/installation Demonstrates how to make the Inspector instance globally accessible within an application, for example, by registering it with an Inversion of Control (IoC) container like PHP-DI. ```php $container->set('inspector', $inspector); ``` -------------------------------- ### Sample Specific Transactions Source: https://docs.inspector.dev/guides/laravel/installation Implement transaction sampling to control data reporting frequency for specific endpoints or jobs. This helps manage quota consumption while maintaining detailed metrics for critical operations. The example shows sampling 70% of 'GET /healthceck' calls and provides a pattern for sampling Jobs. ```php transaction()->name === 'GET /healthceck') { $prob = mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax(); return $prob < 0.7; // Report 70% of the times } // Sample specific jobs if ($inspector->transaction()->name === ExampleJob::class) { $prob = mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax(); return $prob < 0.7; // Report 70% of the times } }); } } ``` -------------------------------- ### List Platforms Response Example Source: https://docs.inspector.dev/rest-api/platform Example JSON response structure for the /api/platforms endpoint, detailing supported platforms. ```json [ { "id": 1, "name": "Laravel", "language": "php", "client_version": "4.6.21" }, { "id": 2, "name": "PHP", "language": "php", "client_version": "3.5.17" }, { "id": 3, "name": "NodeJs", "language": "javascript", "client_version": "1.9.4" }, { "id": 3, "name": "ExpressJs", "language": "javascript", "client_version": "1.9.4" }, { "id": 3, "name": "Fastify", "language": "javascript", "client_version": "1.9.4" } ] ``` -------------------------------- ### Install Inspector Laravel Package Source: https://docs.inspector.dev/guides/laravel/installation Composer command to install the latest version of the Inspector Laravel package. This adds the necessary files and dependencies to your project. ```Shell composer require inspector-apm/inspector-laravel ``` -------------------------------- ### Implement ShouldQueue for Scheduled Jobs Source: https://docs.inspector.dev/guides/laravel/installation Example of a job class implementing the `ShouldQueue` interface in Laravel. This is necessary for Inspector to correctly monitor scheduled jobs dispatched to the queue. ```PHP namespace App\Jobs; use Illuminate\Contracts\Queue\ShouldQueue; class ProcessAudioFiles implements ShouldQueue { ... } ``` -------------------------------- ### Check Laravel Version Source: https://docs.inspector.dev/guides/laravel/installation Command to determine the Laravel version of your application. This helps in confirming the framework version before proceeding with package installation. ```Shell php artisan --version ``` -------------------------------- ### Install Inspector APM for Slim Source: https://docs.inspector.dev/guides/slim Installs the Inspector APM package for Slim applications using Composer. This is the initial step to integrate the monitoring agent into your project. ```shell composer require inspector-apm/inspector-slim ``` -------------------------------- ### Create Inspector Instance Source: https://docs.inspector.dev/guides/raw-php/installation Initializes the Inspector service by creating an instance of the Configuration class with your unique Ingestion Key. Ensure the Composer autoloader is included. ```php startSegment('api', $url) ->start($timespamp_start) ->end($duration_ms); ``` -------------------------------- ### Example 200 OK Response Source: https://docs.inspector.dev/rest-api/analytics Provides an example of a successful API response (HTTP 200 OK). The response is a JSON array containing objects with 'date' (timestamp) and 'num' (count) fields. ```json [ { "date": 1617494400000, "num": 0 }, { "date": 1617580800000, "num": 0 }, { "date": 1617667200000, "num": 0 }, { "date": 1617753600000, "num": 0 }, { "date": 1617840000000, "num": 0 }, { "date": 1617926400000, "num": 1 }, { "date": 1618012800000, "num": 0 }, { "date": 1618099200000, "num": 0 }, { "date": 1618185600000, "num": 0 }, { "date": 1618272000000, "num": 0 }, { "date": 1618358400000, "num": 0 }, { "date": 1618444800000, "num": 0 }, { "date": 1618531200000, "num": 0 }, { "date": 1618617600000, "num": 0 }, { "date": 1618704000000, "num": 0 }, { "date": 1618790400000, "num": 0 }, { "date": 1618876800000, "num": 0 }, { "date": 1618963200000, "num": 0 }, { "date": 1619049600000, "num": 0 }, { "date": 1619136000000, "num": 0 }, { "date": 1619222400000, "num": 0 }, { "date": 1619308800000, "num": 0 }, { "date": 1619395200000, "num": 0 }, { "date": 1619481600000, "num": 0 }, { "date": 1619568000000, "num": 0 }, { "date": 1619654400000, "num": 0 }, { "date": 1619740800000, "num": 0 }, { "date": 1619827200000, "num": 0 }, { "date": 1619913600000, "num": 0 }, { "date": 1620000000000, "num": 0 }, { "date": 1620086400000, "num": 0 } ] ``` -------------------------------- ### Check PHP Version Source: https://docs.inspector.dev/guides/laravel/installation Command to verify the installed PHP version on your server. This is crucial for ensuring compatibility with the Inspector package requirements. ```Shell php -v ``` -------------------------------- ### Register Before Flush Callback Source: https://docs.inspector.dev/guides/laravel/installation Register a callback function that executes before data is sent to the remote platform. This callback receives the Inspector instance, allowing for pre-transmission modifications or checks. ```php use Inspector\Laravel\Facades\Inspector as InspectorFacade; use Inspector\Inspector; InspectorFacade::beforeFlush(function (Inspector $inspector) { // Do something before data are sent. }); ``` -------------------------------- ### Test Inspector Configuration Source: https://docs.inspector.dev/guides/symfony/installation Executes a Symfony console command to verify that the application is correctly configured and can successfully send data to the Inspector service. This is a crucial step after initial setup. ```Bash php bin/console inspector:test ``` -------------------------------- ### Enable Inspector Facade for Lumen Source: https://docs.inspector.dev/guides/laravel/installation Enables the use of the Inspector facade in Lumen applications. This requires uncommenting the `withFacades()` call in the `bootstrap/app.php` file. ```PHP $app->withFacades(); ``` -------------------------------- ### Performance Distribution Response Example Source: https://docs.inspector.dev/rest-api/transactions An example JSON response structure for the performance distribution endpoint, showing millisecond buckets and the number of occurrences within each bucket. ```JSON [ { "ms": 0, "occurrences": 29 }, { "ms": 152, "occurrences": 30 }, { "ms": 304, "occurrences": 1 }, { "ms": 456, "occurrences": 0 }, { "ms": 608, "occurrences": 0 }, { "ms": 760, "occurrences": 0 }, { "ms": 912, "occurrences": 0 }, { "ms": 1064, "occurrences": 0 }, { "ms": 1216, "occurrences": 0 }, { "ms": 1368, "occurrences": 0 }, { "ms": 1520, "occurrences": 0 }, { "ms": 1672, "occurrences": 0 }, { "ms": 1824, "occurrences": 0 }, { "ms": 1976, "occurrences": 0 }, { "ms": 2128, "occurrences": 0 }, { "ms": 2280, "occurrences": 0 }, { "ms": 2432, "occurrences": 0 }, { "ms": 2584, "occurrences": 0 }, { "ms": 2736, "occurrences": 0 }, { "ms": 2888, "occurrences": 0 }, { "ms": 3040, "occurrences": 0 }, { "ms": 3192, "occurrences": 0 }, { "ms": 5776, "occurrences": 1 }, { "ms": 5928, "occurrences": 5 }, { "ms": 6080, "occurrences": 9 } ] ``` -------------------------------- ### Install Inspector Nova Link via Composer Source: https://docs.inspector.dev/guides/laravel/laravel-nova-tool Installs the latest version of the Inspector Nova Link package using Composer. This is the initial step to integrate Inspector APM with Laravel Nova. ```bash composer require inspector-apm/inspector-nova-link ``` -------------------------------- ### Register OutOfMemoryBootstrapper Source: https://docs.inspector.dev/guides/laravel/installation Code snippet to register the `OutOfMemoryBootstrapper` in Laravel's HTTP and Console kernels. This ensures Inspector can report transactions even when the app runs out of memory. ```PHP protected function bootstrappers() { return array_merge( [\Inspector\Laravel\OutOfMemoryBootstrapper::class], parent::bootstrappers() ); } ``` -------------------------------- ### Test Inspector Connection Source: https://docs.inspector.dev/guides/laravel/installation Artisan command to verify that your Laravel application can successfully send data to the Inspector service. This is a crucial step after configuration. ```Shell php artisan inspector:test ``` -------------------------------- ### Update Inspector Ingestion URL Source: https://docs.inspector.dev/guides/laravel/upgrade-guide Ensure the `url` parameter in your published `inspector.php` configuration file is set to the new Inspector ingestion system URL: https://ingest.inspector.dev. ```php $config['inspector']['url'] = 'https://ingest.inspector.dev'; ``` -------------------------------- ### Initialize Inspector with Configuration Source: https://docs.inspector.dev/guides/raw-php/configuration Demonstrates how to create a Configuration instance with an ingestion key and pass it to the Inspector constructor. This sets up the basic connection and identification for the package. ```php $configuration = new Configuration('YOUR_INGESTION_KEY'); // Pass the configuration to the Inspector constructor. $inspector = new Inspector($configuration); ``` -------------------------------- ### Add Segment to Transaction Source: https://docs.inspector.dev/guides/raw-php/installation Adds a segment to the current transaction to monitor specific code blocks or function calls. This example shows how to retrieve the Inspector instance from a container and wrap a service call. ```php class UserController extends BaseController { /** * Example of how to get the Inspector instance from a container. */ public function action() { // Get the instance from the container. $inspector = $container->get('inspector'); // Add a new segment to monitor an action. return $inspector->addSegment(function () { return $this->someService->action(); }, 'someService', 'action'); } } ``` -------------------------------- ### GET /api/apps/:id/segments - List Segments Source: https://docs.inspector.dev/rest-api/segments Retrieves a list of Segments for a given App within a specified interval. Requires App ID and filtering parameters like start date and end date. Supports filtering by segment types and labels. ```APIDOC Base URI: https://app.inspector.dev Endpoint: GET /api/apps/:id/segments Description: Get the list of Segments in the given interval. Path Parameters: - id (Integer, required): App's identifier Headers: - Content-Type: application/json - Authorization: Bearer Body Parameters: - filter.start (string, required): ISO-8601 date format for the start of the interval. - filter.end (string): ISO-8601 date format for the end of the interval. - filter.types (array): Filter the transactions list by servers. - filter.query_string (string): Filter by Segment's label. Response (200 OK): Returns a JSON array where each element represents a segment type (e.g., 'mysql') containing a list of segment objects. Each segment object includes details like type, start time, duration, hash, memory peak, label, app_id, timestamp, and hits. Example Request Structure: GET https://app.inspector.dev/api/apps/389/segments?filter.start=2024-10-01T00:00:00Z&filter.end=2024-10-01T23:59:59Z Headers: Content-Type: application/json Authorization: Bearer YOUR_TOKEN ``` -------------------------------- ### Set Custom Service Name Source: https://docs.inspector.dev/guides/laravel/installation Configure a custom service name for monitoring data, useful in dynamic environments like Kubernetes or auto-scaling setups. This groups monitoring data by service type (e.g., API, workers) rather than individual hostnames. ```php transaction() ->host ->hostname = config('app.service_name') ?? 'rest-api'; }); } } ``` -------------------------------- ### Segments List Response Example Source: https://docs.inspector.dev/rest-api/segments Example JSON response for the Segments List API endpoint, showing transaction metrics for different segment types. ```json [ { "type": "mysql", "segments": [ { "type": "mysql", "start": 123, "duration": 42.8, "group_hash": "4fbb4fa36bad346bbe8a26827a244e70", "hash": "37d6f2a1bd370759ff46cc63266603b81b60da4774bfa9a72af7bf26ba3d4fb1", "memory_peak": 16.98, "label": "SELECT * FROM users", "app_id": 389, "timestamp": "2024-10-04 16:52:02", "hits": 60 } ] } ] ``` -------------------------------- ### Clear Laravel Configuration Cache Source: https://docs.inspector.dev/guides/laravel/installation Command to clear the cached configuration files in a Laravel application. This should be done before installing new packages to prevent conflicts. ```Shell php artisan config:clear ``` -------------------------------- ### Configure PHP Functions for Docker Runtime Source: https://docs.inspector.dev/guides/laravel/laravel-vapor An example `php.ini` configuration snippet. It demonstrates how to ensure critical functions like `proc_open` and `proc_close` are not disabled, which is necessary for Inspector to function correctly within a Docker runtime. ```ini disable_functions=exec,passthru,shell_exec,system,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source ``` -------------------------------- ### Access Inspector Instance with Helper Function (PHP) Source: https://docs.inspector.dev/guides/codeigniter/configuration This snippet shows how to load the `inspector` helper and then use the `inspector()` function to access the Inspector instance. It demonstrates adding a custom segment to the monitoring with a specified type and label. ```PHP // Load the helper helper('inspector'); // Use the inspector() function inspector()->addSegment(function () { // Your code here... }, 'type', 'label'); ``` -------------------------------- ### App Details Response Payload Source: https://docs.inspector.dev/rest-api/application Example JSON payload representing the details of an application. This structure includes identifiers, configuration flags, platform information, user associations, and timestamps. ```JSON { "id": 123, "name": "App Demo", "favorite": false, "client_version": "4.7.33", "key": "xxxxxxxxxxxxxxxxx", "serverless": false, "weekly_report": true, "platform": { "id": 1, "name": "Laravel", "language": "PHP" }, "users": [1, 2], "created_at": "2024-03-01 10:52", "updated_at": "2024-03-01 10:52" } ``` -------------------------------- ### Zero Downtime Deployment Root Path Configuration Source: https://docs.inspector.dev/concepts/ai-bug-fixer Illustrates how to configure the root server path for applications using zero downtime deployment strategies, which involve dynamic release directories. The wildcard character '*' is used to map the changing release directory. ```sh # The final directory will change on every release /var/www/html/public_html/releases/382758329/ # This is how you should configure the root server path on Inspector /var/www/html/public_html/releases/*/ ``` -------------------------------- ### Errors Trend API Response Example Source: https://docs.inspector.dev/rest-api/analytics Example JSON response detailing detected exceptions, including their message, handling status, class, file, line number, timestamps, and historical occurrence histograms. ```json [ { "id": 24, "message": "First Exception detected", "handled": true, "muted": false, "class": "Exception", "file": "C:\\xampp\\htdocs\\crongenius\\vendor\\inspector-apm\\inspector-laravel\\src\\Commands\\TestCommand.php", "line": 71, "hash": "287366827414d79f8f4775c5a99e0d05", "last_seen_at": "2020-10-09 14:05:41", "created_at": "2020-10-08 14:48:55", "histogram_day": { "2020-10-15 07:00": 0, "2020-10-15 08:00": 1, "2020-10-15 09:00": 1, "2020-10-15 10:00": 7, "2020-10-15 11:00": 0, "2020-10-15 12:00": 0, "2020-10-15 13:00": 1, "2020-10-15 14:00": 1, "2020-10-15 15:00": 3, "2020-10-15 16:00": 0, "2020-10-15 17:00": 0, "2020-10-15 18:00": 21, "2020-10-15 19:00": 6, "2020-10-15 20:00": 0, "2020-10-15 21:00": 0, "2020-10-15 22:00": 16, "2020-10-15 23:00": 0, "2020-10-16 00:00": 0, "2020-10-16 01:00": 0, "2020-10-16 02:00": 0, "2020-10-16 03:00": 0, "2020-10-16 04:00": 0, "2020-10-16 05:00": 0, "2020-10-16 06:00": 0, "2020-10-16 07:00": 0 }, "histogram_month": { "2020-09-16 07:00": 0, "2020-09-17 07:00": 0, "2020-09-18 07:00": 0, "2020-09-19 07:00": 0, "2020-09-20 07:00": 0, "2020-09-21 07:00": 0, "2020-09-22 07:00": 0, "2020-09-23 07:00": 0, "2020-09-24 07:00": 5, "2020-09-25 07:00": 0, "2020-09-26 07:00": 0, "2020-09-27 07:00": 0, "2020-09-28 07:00": 0, "2020-09-29 07:00": 0, "2020-09-30 07:00": 0, "2020-10-01 07:00": 0, "2020-10-02 07:00": 21, "2020-10-03 07:00": 8, "2020-10-04 07:00": 0, "2020-10-05 07:00": 0, "2020-10-06 07:00": 0, "2020-10-07 07:00": 0, "2020-10-08 07:00": 0, "2020-10-09 07:00": 4, "2020-10-10 07:00": 0, "2020-10-11 07:00": 0, "2020-10-12 07:00": 4, "2020-10-13 07:00": 0, "2020-10-14 07:00": 0, "2020-10-15 07:00": 2, "2020-10-16 07:00": 127 }, "histogram_hour": { "2020-10-16 06:36": 0, "2020-10-16 06:38": 0, "2020-10-16 06:40": 0, "2020-10-16 06:42": 0, "2020-10-16 06:44": 0, "2020-10-16 06:46": 0, "2020-10-16 06:48": 4, "2020-10-16 06:50": 27, "2020-10-16 06:52": 25, "2020-10-16 06:54": 0, "2020-10-16 06:56": 3, "2020-10-16 06:58": 0, "2020-10-16 07:00": 0, "2020-10-16 07:02": 5, "2020-10-16 07:04": 6, "2020-10-16 07:06": 6, "2020-10-16 07:08": 0, "2020-10-16 07:10": 0, "2020-10-16 07:12": 0, "2020-10-16 07:14": 0, "2020-10-16 07:16": 0, "2020-10-16 07:18": 19, "2020-10-16 07:20": 0, "2020-10-16 07:22": 0, "2020-10-16 07:24": 0, "2020-10-16 07:26": 0, "2020-10-16 07:28": 0, "2020-10-16 07:30": 0, "2020-10-16 07:32": 5, "2020-10-16 07:34": 30, "2020-10-16 07:36": 0 }, "total": 4 } ] ``` -------------------------------- ### List Platforms API Source: https://docs.inspector.dev/rest-api/platform This endpoint retrieves a list of all supported platforms. It requires an 'Authentication' header with an API key. The response is a JSON array containing objects, each representing a platform with its ID, name, primary language, and client version. ```APIDOC GET https://app.inspector.dev/api/platforms Headers: Authentication: string (API key) Response (200 OK): [ { "id": 1, "name": "Laravel", "language": "php", "client_version": "4.6.21" }, { "id": 2, "name": "PHP", "language": "php", "client_version": "3.5.17" }, { "id": 3, "name": "NodeJs", "language": "javascript", "client_version": "1.9.4" }, { "id": 3, "name": "ExpressJs", "language": "javascript", "client_version": "1.9.4" }, { "id": 3, "name": "Fastify", "language": "javascript", "client_version": "1.9.4" } ] ``` -------------------------------- ### Get Application Errors API Source: https://docs.inspector.dev/rest-api/analytics Retrieves a list of errors detected in a given application. Requires the project ID and authentication. ```APIDOC GET /api/projects/:id/errors Description: Retrieve the list of errors detected in the given application. Path Parameters: - id (string): Project's ID. Headers: - Authentication (string): API key. Response (200 OK): - List of detected errors (details not specified in provided text). ``` -------------------------------- ### Test Route with Exception Source: https://docs.inspector.dev/guides/slim Creates a test route that intentionally throws an exception. This is used to verify that the Inspector agent is capturing and reporting errors correctly. ```php $app->get('/test', function () { throw new \Exception('My First Exception.'); }); ``` -------------------------------- ### Test Inspector Configuration Source: https://docs.inspector.dev/guides/laravel/laravel-vapor Runs a test command provided by the Inspector package to verify that the monitoring setup is correctly configured before deploying to production. ```sh php artisan inspector:test ``` -------------------------------- ### Configure Inspector Ingestion Key Source: https://docs.inspector.dev/guides/symfony/installation Creates the `inspector.yaml` configuration file within the `config/packages` directory. This file sets the `ingestion_key` using an environment variable, which is essential for connecting to the Inspector service. ```YAML inspector: ingestion_key: '%env(INSPECTOR_INGESTION_KEY)%' ```