### Start Transaction PHP Source: https://docs.inspector.dev/guides/raw-php/installation Starts a new transaction, typically at the entry point of the application (e.g., index.php). Marks the transaction as a request. ```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... ``` -------------------------------- ### Install Inspector PHP Agent Source: https://docs.inspector.dev/guides/raw-php/installation Installs the Inspector PHP agent using Composer. Ensure you have Composer installed and configured. ```bash composer require inspector-apm/inspector-php ``` -------------------------------- ### Create Inspector Instance PHP Source: https://docs.inspector.dev/guides/raw-php/installation Creates a new Inspector instance using the provided Ingestion Key. Requires including the Composer autoloader. ```php transaction()->name === 'GET /healthceck') { $prob = mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax(); return $prob < 0.7; // Report 70% of the times } }); } } ``` -------------------------------- ### Access Inspector Instance via Container PHP Source: https://docs.inspector.dev/guides/raw-php/installation Demonstrates how to make the Inspector instance globally available using a dependency injection container and access it within a controller. ```php $container->set('inspector', $inspector); ``` ```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'); } } ``` -------------------------------- ### Register Before-Flush Callback PHP Source: https://docs.inspector.dev/guides/raw-php/installation Registers callbacks to be executed just before data is flushed from the application. Callbacks can be used to modify or prevent data sending. ```php Inspector::beforeFlush(function (\Inspector\Inspector $inspector) { // Do something }); ``` ```php // First Inspector::beforeFlush(function (\Inspector\Inspector $inspector) { // Do something }); // Second Inspector::beforeFlush(function (\Inspector\Inspector $inspector) { // Do something }); // Last Inspector::beforeFlush(function (\Inspector\Inspector $inspector) { // Do something }); ``` ```php Inspector::beforeFlush(function (\Inspector\Inspector $inspector) { if ($inspector->transaction()->name === 'GET /api') { return false; // <- Do not send data to the remote platform. } }); ``` -------------------------------- ### Add Context to Transaction PHP Source: https://docs.inspector.dev/guides/raw-php/installation Adds contextual information to the current transaction, which appears as additional tabs in the Inspector UI. ```php $inspector->transaction()?->addContext('label', ['foo' => 'bar']); ``` -------------------------------- ### Install Inspector Symfony Bundle using Composer Source: https://docs.inspector.dev/guides/symfony/installation This command installs the latest version of the Inspector Symfony bundle using Composer. Ensure you have Composer installed and your project is initialized as a Symfony application. ```bash composer require inspector-apm/inspector-symfony ``` -------------------------------- ### Access Inspector Instance: Helper Function & Facade (PHP) Source: https://docs.inspector.dev/guides/laravel/installation Provides examples of how to obtain the current Inspector instance using the global `inspector()` helper function or the `Inspector` Facade to add custom segments to transactions. ```php /* * Using the helper function */ inspector()->addSegment(function () { // Do something }, 'label'); /* * Using the Facade */ \Inspector\Laravel\Facades\Inspector::addSegment(function () { // Do something }, 'label'); ``` -------------------------------- ### Install Inspector with Composer Source: https://docs.inspector.dev/guides/slim Installs the latest version of the Inspector APM package for Slim using Composer. ```bash composer require inspector-apm/inspector-slim ``` -------------------------------- ### Verify Inspector Installation Source: https://docs.inspector.dev/guides/codeigniter/installation Runs a diagnostic command provided by the Inspector package to check if the installation and configuration are correct. This command helps ensure that Inspector is ready for production deployment. ```bash php spark inspector:test ``` -------------------------------- ### Install Inspector Laravel Package Source: https://docs.inspector.dev/guides/laravel/installation Composer command to install the latest version of the Inspector.dev Laravel package. This adds the necessary components to your project. ```bash composer require inspector-apm/inspector-laravel ``` -------------------------------- ### Test Inspector Configuration and Data Sending Source: https://docs.inspector.dev/guides/symfony/installation Execute this Symfony command to verify that your application is correctly configured and can successfully send data to the Inspector service. This is a crucial step after installation and configuration. ```bash php bin/console inspector:test ``` -------------------------------- ### Verify PHP Version Source: https://docs.inspector.dev/guides/laravel/installation Command to check the installed PHP version on your server. This is a prerequisite for installing the Inspector package. ```bash php -v ``` -------------------------------- ### Sample Transactions by Job (PHP) Source: https://docs.inspector.dev/guides/laravel/installation Illustrates how to sample transactions for specific background jobs by using their fully qualified class name within the `beforeFlush` conditional logic. ```php if ($inspector->transaction()->name === ExampleJob::class) { $prob = mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax(); return $prob < 0.7; // Report 70% of the times } ``` -------------------------------- ### Performance Distribution Response Example Source: https://docs.inspector.dev/rest-api/transactions An example of a successful response (HTTP 200) for the performance distribution endpoint, showing the time in milliseconds ('ms') and the number of occurrences for each time 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 } ] ``` -------------------------------- ### Set Transaction Result PHP Source: https://docs.inspector.dev/guides/raw-php/installation Sets the result of the current transaction, typically using the HTTP status code returned by the application. ```php $inspector->transaction()->setResult(200); ``` -------------------------------- ### Install Inspector CodeIgniter Package Source: https://docs.inspector.dev/guides/codeigniter/installation Installs the Inspector APM package for CodeIgniter using Composer. This is the initial step to integrate Inspector into your application. ```bash composer require inspector-apm/inspector-codeigniter ``` -------------------------------- ### Verify Laravel Version Source: https://docs.inspector.dev/guides/laravel/installation Command to determine the Laravel version of your application. Ensures compatibility with the Inspector package. ```bash php artisan --version ``` -------------------------------- ### Segments API Response Example Source: https://docs.inspector.dev/rest-api/segments Example of a successful JSON response from the Segments API, listing segments grouped by type (e.g., 'mysql') with details like hits, duration, and label. ```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 } ] } ] ``` -------------------------------- ### Publish Inspector Configuration File Source: https://docs.inspector.dev/guides/laravel/configuration This command publishes the Inspector configuration file to your project, allowing for full control over the package's behavior. It creates the `config/inspector.php` file. ```bash php artisan vendor:publish --provider="Inspector\Laravel\InspectorServiceProvider" ``` -------------------------------- ### Install Inspector Nova Link via Composer Source: https://docs.inspector.dev/guides/laravel/laravel-nova-tool This command installs the Inspector Nova Link package using Composer. Ensure Composer is installed and accessible in your environment. ```bash composer require inspector-apm/inspector-nova-link ``` -------------------------------- ### Use Inspector Helper for Custom Monitoring Source: https://docs.inspector.dev/guides/codeigniter/installation Demonstrates how to use the Inspector helper to monitor custom code blocks by adding segments and manually reporting exceptions. This allows for granular performance tracking beyond automatic monitoring. ```php // Load the helper if you haven't added it to Autoload.php helper('inspector'); // Monitor custom code blocks $json = inspector()->addSegment(function () { return file_get_contents('auth.json'); }, 'http', 'READ auth.json'); // Report an exception inspector()->reportException(new \Exception("Whoops there's an error here.")); ``` -------------------------------- ### Access Inspector Instance via Dependency Injection (PHP) Source: https://docs.inspector.dev/guides/laravel/installation Demonstrates how to inject the Inspector instance directly into a controller's method by type-hinting the argument with the Inspector class for direct access. ```php namespace App\Http\Controllers; use Illuminate\Http\Request; use Inspector\Laravel\Inspector; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index(Inspector $inspector) { return view('home'); } } ``` -------------------------------- ### Install Drupal Inspector Monitoring with Composer Source: https://docs.inspector.dev/guides/drupal Installs the latest version of the Drupal Inspector Monitoring module using Composer. This is the primary method for adding the monitoring package to a Drupal project. ```bash composer require drupal/inspector_monitoring ``` -------------------------------- ### Enable Facades for Lumen Source: https://docs.inspector.dev/guides/laravel/installation Enables the use of facades in Lumen applications, which is necessary if you intend to use the Inspector facade. ```php $app->withFacades(); ``` -------------------------------- ### Clear Laravel Configuration Cache Source: https://docs.inspector.dev/guides/laravel/installation Command to clear the cached configuration in Laravel. This is recommended before installing the Inspector package to prevent potential conflicts or errors. ```bash php artisan config:clear ``` -------------------------------- ### Register Before Flush Callback Source: https://docs.inspector.dev/guides/laravel/installation Registering a callback function in the `boot` method of `AppServiceProvider` to execute custom logic before Inspector sends data to its platform. This allows for data manipulation or additional processing. ```php use Inspector\Laravel\Facades\Inspector as InspectorFacade; use Inspector\Inspector; InspectorFacade::beforeFlush(function (Inspector $inspector) { // Do something before data are sent. }); ``` -------------------------------- ### Publish Inspector Configuration File Source: https://docs.inspector.dev/guides/codeigniter/installation Publishes the `Inspector.php` configuration file to your application's `app/Config` directory using a CodeIgniter Spark command. This allows for customization of Inspector settings. ```bash php spark inspector:install ``` -------------------------------- ### Implement ShouldQueue for Scheduled Jobs Source: https://docs.inspector.dev/guides/laravel/installation Ensures that scheduled job classes implement the ShouldQueue interface, which is a prerequisite for Inspector to monitor them correctly. ```php namespace App\Jobs; use Illuminate\Contracts\Queue\ShouldQueue; class ProcessAudioFiles implements ShouldQueue { ... } ``` -------------------------------- ### Get App Details with GET Request to Inspector.dev API Source: https://docs.inspector.dev/rest-api/application Fetches detailed information for a specific application using its ID. The app ID is provided as a path parameter. Requires an 'Authentication' header. Returns a JSON object with the app's details on success (200) or a JSON object with an error message if the app is not found (404). ```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" } ``` ```json { "message": "Resource not found." } ``` -------------------------------- ### Customize Inspector Behavior with Configuration Options (PHP) Source: https://docs.inspector.dev/guides/raw-php/configuration This example shows how to create a Configuration object and then use setter methods to customize its behavior, such as enabling data transfer and setting the maximum number of items per transaction. These options control the extent and limits of data collection. ```php $configuration = new Configuration('YOUR_INGESTION_KEY'); $configuration->setEnabled(true); $configuration->setMaxItems(500); ``` -------------------------------- ### Add Inspector Helper for Global Access Source: https://docs.inspector.dev/guides/codeigniter/installation Includes the Inspector helper in the `Config/Autoload.php` file to make Inspector functions globally available throughout the application. This simplifies monitoring custom code blocks and reporting exceptions. ```php */ public $helpers = ['inspector']; } ``` -------------------------------- ### Enable HTTP Request Monitoring with Inspector Filter Source: https://docs.inspector.dev/guides/codeigniter/installation Configures global filters in `app/Config/Filter.php` to automatically monitor all incoming HTTP requests using the Inspector package. This provides insights into request latency and performance. ```php [ ... 'inspector', ], 'after' => [ ... 'inspector', ], ]; } ``` -------------------------------- ### GET /websites/inspector_dev/{id}/exceptions Source: https://docs.inspector.dev/rest-api/analytics Retrieves a list of exceptions for a specific project. ```APIDOC ## GET /websites/inspector_dev/{id}/exceptions ### Description Retrieves a list of exceptions for a specific project, including details like message, handling status, class, file, line number, timestamps, and historical data histograms. ### Method GET ### Endpoint /websites/inspector_dev/{id}/exceptions #### Path Parameters - **id** (integer) - Required - Project's ID #### Headers - **Authentication** (string) - Required - API Key ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the exception. - **message** (string) - A description of the exception. - **handled** (boolean) - Indicates if the exception has been handled. - **muted** (boolean) - Indicates if the exception is muted. - **class** (string) - The class of the exception. - **file** (string) - The file where the exception occurred. - **line** (integer) - The line number where the exception occurred. - **hash** (string) - A hash of the exception for grouping. - **last_seen_at** (string) - The timestamp when the exception was last seen. - **created_at** (string) - The timestamp when the exception was created. - **histogram_day** (object) - Daily error count histogram. - **histogram_month** (object) - Monthly error count histogram. - **histogram_hour** (object) - Hourly error count histogram. - **total** (integer) - The total count of this exception. #### Response Example ```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 } ] ``` ``` -------------------------------- ### Get Hosts Source: https://docs.inspector.dev/rest-api/analytics Retrieves a list of hosts (servers) where the application is running, with optional filtering by date and hostnames. ```APIDOC ## POST /api/apps/:id/hosts ### Description The list of hosts (servers) where the application runs on. ### Method POST ### Endpoint `https://app.inspector.dev/api/apps/:id/hosts` #### Path Parameters - **id** (string) - Required - Project's ID #### Headers - **Authentication** (string) - Required - API key #### Request Body - **filter** (object) - Required - This object should contains "start" and "end" dates (ISO8601) to define the period you would analyze. You can also attach the hosts field as an array of hostnames to filter your data by servers. ### Request Example ```json { "filter": { "start": "2023-01-01T00:00:00Z", "end": "2023-01-31T23:59:59Z", "hosts": ["server-useast-2", "server-useast-1"] } } ``` ### Response #### Success Response (200) - **hostname** (string) - The name of the host. - **transactions** (integer) - The number of transactions on the host. - **memory_peak** (integer) - The peak memory usage on the host. - **median** (float) - The median response time on the host. #### Response Example ```json [ { "hostname": "server-useast-2", "transactions": 2320, "memory_peak": 25, "median": 168.3 }, { "hostname": "server-useast-1", "transactions": 2320, "memory_peak": 25, "median": 168.3 } ] ``` ``` -------------------------------- ### Register OutOfMemoryBootstrapper Source: https://docs.inspector.dev/guides/laravel/installation Registering the OutOfMemoryBootstrapper in Laravel's Kernel files ensures that Inspector can report transactions even when the application runs out of memory. It must be registered early. ```php protected function bootstrappers() { return array_merge( ["\Inspector\Laravel\OutOfMemoryBootstrapper::class"], parent::bootstrappers() ); } ``` -------------------------------- ### Get Hosts List - JSON Response Source: https://docs.inspector.dev/rest-api/analytics This snippet shows the JSON response structure for the 'Get Hosts' endpoint. It lists servers where an application runs, along with transaction counts, peak memory usage, and median response times within a specified period. This response is typically received after a POST request to the `/api/apps/:id/hosts` endpoint. ```json [ { "hostname": "server-useast-2", "transactions": 2320, "memory_peak": 25, "median": 168.3 }, { "hostname": "server-useast-1", "transactions": 2320, "memory_peak": 25, "median": 168.3 } ] ``` -------------------------------- ### Transaction Grouping Pattern Example Source: https://docs.inspector.dev/concepts/grouping-patterns Illustrates how to create a pattern for grouping similar transaction requests. By replacing variable parts of URLs (like user IDs) with placeholders in curly braces, multiple distinct URLs can be consolidated into a single transaction group. ```text GET /api/users/{user_id}/profile ``` ```text GET /api/users/{user_id}/projects/{project_id} ``` -------------------------------- ### Access Inspector Instance using Helper Source: https://docs.inspector.dev/guides/codeigniter/configuration This code snippet illustrates how to load the Inspector helper function and then use the `inspector()` function to get the current Inspector instance. This instance can then be used to add custom segments for monitoring. ```php // Load the helper helper('inspector'); // Use the inspector() function inspector()->addSegment(function () { // Your code here... }, 'type', 'label'); ``` -------------------------------- ### Register Inspector Service Provider for Lumen Source: https://docs.inspector.dev/guides/laravel/installation Manual registration of the Inspector Service Provider in Lumen applications. This is required for Lumen due to its minimal configuration. ```php $app->register(\Inspector\Laravel\InspectorServiceProvider::class); ``` -------------------------------- ### Configure Inspector Ingestion Key Source: https://docs.inspector.dev/guides/laravel/installation Environment variable configuration for the Inspector Ingestion Key. This key authenticates your application with the Inspector.dev platform. ```dotenv INSPECTOR_INGESTION_KEY=[ingestion key] ``` -------------------------------- ### Configure Root Path for Zero Downtime Deployment Source: https://docs.inspector.dev/concepts/ai-bug-fix This example shows how to configure the root server path in Inspector for applications using zero-downtime deployment. Due to dynamic directory creation on each release, a wildcard character '*' is used to match the changing release directory, ensuring Inspector can locate the application's root path correctly. ```bash # 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/*/ ``` -------------------------------- ### Add Inspector Exception Handler Source: https://docs.inspector.dev/guides/codeigniter/installation Integrates the Inspector exception handler into your CodeIgniter application by modifying the `app/Config/Exceptions.php` file. This enables automatic tracking of unhandled exceptions. ```php transaction() ->host ->hostname = config('app.service_name')??'rest-api' }); } } ``` -------------------------------- ### Configure Inspector Master Switch Source: https://docs.inspector.dev/guides/laravel/configuration Demonstrates how to disable data transfer by setting the 'enable' configuration option to false using an environment variable. This acts as a master switch for the Inspector package. ```php 'enable' => env('INSPECTOR_ENABLE', true) ``` -------------------------------- ### Configure Inspector Ingestion Key Source: https://docs.inspector.dev/guides/codeigniter/installation Sets the Inspector ingestion key as an environment variable in the `.env` file. This key is required for your application to send performance data to your Inspector dashboard. ```env #-------------------------------------------------------------------- # INSPECTOR #-------------------------------------------------------------------- inspector.ingestionKey = '974yn8c34ync8xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ``` -------------------------------- ### List Apps with GET Request to Inspector.dev API Source: https://docs.inspector.dev/rest-api/application Retrieves a list of all applications associated with the authenticated API key. Requires an 'Authentication' header with a valid API key. Returns a JSON array of app objects, each containing details like ID, name, platform, and creation/update 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" }, { "id": 456, "name": "Demo 2", "favorite": false, "key": "xxxxxxxxxxxxxxxxx", ... } ] ``` -------------------------------- ### Access Inspector Instance in Symfony Controller Source: https://docs.inspector.dev/guides/symfony/installation This PHP code snippet demonstrates how to access the Inspector instance within a Symfony controller. By type-hinting the `Inspector` class, you can obtain an instance to add segments and monitor specific operations like PDF creation. ```php namespace App\Controller; use Inspector\Inspector; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; class ProductController { /** * @Route("/invoice") */ public function generateInvoice(Inspector $inspector, Request $request): Response { $pdf = $inspector->addSegment(function () { return $this->createPDF(); }, 'file', 'Create Invoice PDF'); return $pdf; } } ``` -------------------------------- ### Configure Inspector Ingestion Key and Environment Variable Source: https://docs.inspector.dev/guides/symfony/installation This section shows how to configure the Inspector ingestion key by creating a YAML configuration file and adding the key as an environment variable. The ingestion key is required for Inspector to send data to your dashboard. Ensure the environment variable is set in your production environment file. ```yaml inspector: ingestion_key: '%env(INSPECTOR_INGESTION_KEY)%' ``` ```bash INSPECTOR_INGESTION_KEY=xxxxxxxxxxxxxxxxxxx ``` -------------------------------- ### Manually Report Exception in PHP Source: https://docs.inspector.dev/guides/laravel/exception-monitoring This snippet demonstrates how to catch a LogicException and manually report it using the inspector() function. This is useful for collecting diagnostics data without halting code execution. It requires the Inspector.dev library to be installed and configured. ```php try { // Your code statements here... } catch(LogicException $exception) { // Report an exception intentionally to collect diagnostics data inspector()->reportException($exception); } ``` -------------------------------- ### Error Grouping Pattern Example Source: https://docs.inspector.dev/concepts/grouping-patterns Defines a pattern for grouping similar error messages. It uses curly braces `{}` to denote dynamic parts of the error message that can vary, allowing Inspector to treat different but structurally similar errors as one. ```text Invalid datetime format: 1292 Incorrect date value: {date} for column {column_name}_at ``` -------------------------------- ### Initialize Inspector with Configuration (PHP) Source: https://docs.inspector.dev/guides/raw-php/configuration This snippet demonstrates how to create a Configuration instance with an ingestion key and then pass it to the Inspector constructor. It sets up the fundamental connection for data collection. ```php $configuration = new Configuration('YOUR_INGESTION_KEY'); $inspector = new Inspector($configuration); ``` -------------------------------- ### Manually Set Segment Timing - PHP Source: https://docs.inspector.dev/guides/raw-php/custom-segments This example shows how to manually create and time a segment after the task has been executed. It's useful for hooking into events, like ORM query execution, where the segment needs to be created retrospectively. It involves calculating the start time based on duration and explicitly setting start and end times. ```php /* * Http call to an external url has been perfromed with this result. */ $url = 'https://www.inspector.dev'; $duration_ms = 10; // Duration in milliseconds /** * ----------------------------------------- * Create the segment manually setting timing information after the execution. * ----------------------------------------- */ // convert duration in seconds $timespamp_start = microtime(true) - ($duration_ms/1000) $inspector->startSegment('api', $url) ->start($timespamp_start) ->end($duration_ms); ``` -------------------------------- ### Get Performance Data - JSON Response Source: https://docs.inspector.dev/rest-api/analytics This snippet illustrates the JSON response for the 'Performance' endpoint. It provides performance metrics for different hosts, including dates, transaction counts, p50 and p95 latency, and average memory usage. This data is returned via a POST request to the `/api/apps/:id/performance` endpoint and can be filtered by date, hosts, query string, and group hash. ```json [ { "hostname": "worker01-eu3-west", "performance": [ { "date": "2020-10-10 12:54", "count": 4, "p50": 5.37, "p95": 6.56, "memory_average": 4.52 }, { "date": "2020-10-10 13:54", "count": 4, "p50": 5.37, "p95": 6.56, "memory_average": 4.52 } ] }, { "hostname": "webapp01-eu3-west", "performance": [ { "date": "2020-10-10 12:54", "count": 4, "p50": 5.37, "p95": 6.56, "memory_average": 3.77 }, { "date": "2020-10-10 13:54", "count": 4, "p50": 5.37, "p95": 6.56, "memory_average": 3.77 } ] } ] ``` -------------------------------- ### Get Performance Distribution of Transaction Source: https://docs.inspector.dev/rest-api/transactions Retrieves the performance distribution for a specific transaction within a project. Requires project ID, transaction group hash, and authentication. The request body accepts start and optional end dates for filtering. ```http POST /api/apps/:id/transactions/:group_hash/time-distribution ``` -------------------------------- ### Get Transaction List - POST /api/apps/:id/transactions Source: https://docs.inspector.dev/rest-api/transactions Retrieves a list of transactions for a given app within a specified interval. Requires app ID, start and end dates, and optionally filters by hosts or query string. Returns an array of transaction objects. ```json [ { name: "request", transactions: [ { type: "request", duration: 42.8, group_hash: "4fbb4fa36bad346bbe8a26827a244e70", hash: "37d6f2a1bd370759ff46cc63266603b81b60da4774bfa9a72af7bf26ba3d4fb1", host: {hostname: "307510.cloudwaysapps.com", ip: "127.0.0.1"}, memory_peak: 16.98, name: "GET /api", project_id: 389, result: "success", timestamp: "2024-10-04 16:52:02", doc_count: 60, performance: [ {label: "2021-02-03 16:00", value: 38, doc_count: 61}, {label: "2021-02-03 17:00", value: 5, doc_count: 63}, {label: "2021-02-03 18:00", value: 65, doc_count: 123}, {label: "2021-02-03 19:00", value: 34, doc_count: 11}, {label: "2021-02-03 20:00", value: 43, doc_count: 110}, {label: "2021-02-03 21:00", value: 2, doc_count: 123}, ... ] }, {...}, ], }, { name: "command", transactions: [...], }, {...} ] ```