### Install Excimer via PECL Source: https://docs.sentry.io/platforms/php/guides/laravel/profiling Install the Excimer PHP extension using PECL. ```bash pecl install excimer ``` -------------------------------- ### Start the Sentry Agent Source: https://docs.sentry.io/platforms/php/agent Start the Sentry Agent binary from the vendor directory. It listens on 127.0.0.1:5148 by default. ```bash vendor/bin/sentry-agent ``` -------------------------------- ### Start Sentry Agent with Runtime Settings Source: https://docs.sentry.io/platforms/php/agent Start the Sentry Agent and configure runtime settings like upstream timeout and queue limit using the --name=value format. ```bash vendor/bin/sentry-agent --upstream-timeout=2.0 --queue-limit=1000 ``` -------------------------------- ### Install Excimer via apt-get Source: https://docs.sentry.io/platforms/php/guides/laravel/profiling Install the Excimer PHP extension using the apt-get package manager on Linux. ```bash apt-get install php-excimer ``` -------------------------------- ### Build Excimer from Source Source: https://docs.sentry.io/platforms/php/guides/laravel/profiling Clone the Excimer repository, then build and install the extension from source. ```bash git clone https://github.com/wikimedia/mediawiki-php-excimer.git cd excimer/ phpize && ./configure && make && sudo make install ``` -------------------------------- ### Install Sentry Agent with Composer Source: https://docs.sentry.io/platforms/php/agent Install the sentry/sentry-agent package using Composer. This package is for installing and running the agent binary. ```bash composer require sentry/sentry-agent ``` -------------------------------- ### Start Sentry Agent with Custom Listen Address Source: https://docs.sentry.io/platforms/php/agent Start the Sentry Agent and specify a custom listen address and port using the --listen flag. ```bash vendor/bin/sentry-agent --listen=127.0.0.1:5148 ``` -------------------------------- ### Basic SDK Fingerprinting Example Source: https://docs.sentry.io/platforms/php/guides/laravel/usage/sdk-fingerprinting Use this to set a static fingerprint for exceptions. Ensure the `\Sentry\withScope` function is used to apply the fingerprint to the current scope. ```php try { // Run code that possibly throws an exception } catch (\Throwable $e) { \Sentry\withScope(function (\Sentry\State\Scope $scope) use ($e) { $scope->setFingerprint(['example-exception-group']); \Sentry\captureException($e); }); } ``` -------------------------------- ### Example Debugger Output Source: https://docs.sentry.io/platforms/php/guides/laravel/troubleshooting This is an example of the output you might see when using the Sentry SDK's debug logger, showing integration status, transaction information, and sending results. ```bash sentry/sentry: [debug] The "Sentry\Integration\ExceptionListenerIntegration, Sentry\Integration\ErrorListenerIntegration, Sentry\Integration\FatalErrorListenerIntegration, Sentry\Integration\RequestIntegration, Sentry\Integration\TransactionIntegration, Sentry\Integration\FrameContextifierIntegration, Sentry\Integration\EnvironmentIntegration, Sentry\Integration\ModulesIntegration" integration(s) have been installed. sentry/sentry: [info] Transaction [e2919a7b0f954478b6994c7282b060de] was started and sampled, decided by config:traces_sample_rate. sentry/sentry: [info] Transaction [e2919a7b0f954478b6994c7282b060de] started profiling because it was sampled. sentry/sentry: [info] Sending transaction [59390dc9dd934c0290d8cdc7a589da82] to o1.ingest.sentry.io [project:1]. sentry/sentry: [warning] The profile does not contain enough samples, the profile will be discarded. sentry/sentry: [info] Sent transaction [59390dc9dd934c0290d8cdc7a589da82] to o1.ingest.sentry.io [project:1]. Result: "success" (status: 200). ``` -------------------------------- ### Install Sentry Symfony Bundle Source: https://docs.sentry.io/platforms/php/guides/symfony Use Composer to install the Sentry Symfony bundle. This command adds the necessary package to your project. ```bash composer require sentry/sentry-symfony ``` -------------------------------- ### Install Sentry SDK for Laravel Source: https://docs.sentry.io/platforms/php/guides/laravel Install the official Sentry SDK for Laravel using Composer. This is the first step to integrating Sentry with your application. ```bash composer require sentry/sentry-laravel ``` -------------------------------- ### Truncated Tag Result Example Source: https://docs.sentry.io/platforms/php/guides/laravel/troubleshooting Shows the result of the previous example after the tag value has been truncated due to the 200-character limit. ```url https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=1618033988749894848 ``` -------------------------------- ### Implement Custom Traces Sampler Logic Source: https://docs.sentry.io/platforms/php/guides/laravel/configuration/sampling Implement the `tracesSampler` method to define your sampling strategy. This example shows how to inherit the parent's sampling decision if available, otherwise applying a default sampling rate. ```php class Sentry { public static function tracesSampler(\Sentry\Tracing\SamplingContext $context): float { // Always inherit the parent sampling decision. if ($context->getParentSampled()) { return 1.0; } // The rest of your sampling logic. return 0.25; } } ``` -------------------------------- ### Install Sentry SDK with Composer Source: https://docs.sentry.io/platforms/php Use Composer to add the Sentry SDK to your PHP project. This is the primary method for including Sentry functionality. ```bash composer require sentry/sentry ``` -------------------------------- ### Capture Job Start and Success Check-ins Source: https://docs.sentry.io/platforms/php/crons Notify Sentry when a job starts and completes successfully. Ensure the Sentry PHP SDK is configured and a Monitor is created with the correct slug. ```php // 🟡 Notify Sentry your job is running: $checkInId = \Sentry\captureCheckIn( slug: '', status: CheckInStatus::inProgress() ); // Execute your scheduled task here... // 🟢 Notify Sentry your job has completed successfully: \Sentry\captureCheckIn( slug: '', status: CheckInStatus::ok(), checkInId: $checkInId, ); ``` -------------------------------- ### Implement `before_send` Callback Logic Source: https://docs.sentry.io/platforms/php/guides/laravel/configuration/filtering Implement the `beforeSend` method to access event hints and modify the event. This example filters events related to database unavailability by setting a specific fingerprint. ```php class Sentry { public static function beforeSend(\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event { if ($hint !== null && $hint->exception !== null && str_contains($hint->exception->getMessage(), 'database unavailable')) { $event->setFingerprint(['database-unavailable']); } return $event; } } ``` -------------------------------- ### Implement Before Breadcrumb Callable Service Source: https://docs.sentry.io/platforms/php/guides/symfony/configuration/symfony-options Implement the service for the `before_breadcrumb` option. This example shows a basic implementation returning the event unmodified. ```php getLevel() === \Sentry\Logs\LogLevel::info()) { // Filter out all info logs. return null; } return $log; } } ``` -------------------------------- ### Implement `beforeSendCheckIn` Callback Source: https://docs.sentry.io/platforms/php/guides/laravel/configuration/filtering Implement the callback function to inspect and potentially discard check-in events. This example discards events not originating from the 'production' environment. ```php class Sentry { public static function beforeSendCheckIn(\Sentry\Event $event): ?\Sentry\Event { $checkIn = $event->getCheckIn(); $checkInEnvironment = $checkIn->getEnvironment(); if ($checkInEnvironment !== 'production') { return null; } return $event; } } ``` -------------------------------- ### Configure Laravel Logging Channels Source: https://docs.sentry.io/platforms/php/guides/laravel/logs Ensure your `config/logging.php` allows environment variable configuration for default and stack channels. This is crucial for dynamic log channel setup. ```php // ... 'default' => env('LOG_CHANNEL', 'stack'), // ... 'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => explode(',', (string) env('LOG_STACK', 'single')), 'ignore_exceptions' => false, ], // ... ``` -------------------------------- ### Filter Events Using `before_send` and Event Hints Source: https://docs.sentry.io/platforms/php/guides/laravel/configuration/filtering This example demonstrates how to use the `before_send` callback with event hints to discard events based on the type of the original exception. If the exception is an instance of `MyException`, the event is dropped by returning `null`. ```php class Sentry { public static function beforeSend(\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event { // Ignore the event if the original exception is an instance of MyException. if ($hint !== null && $hint->exception instanceof MyException) { return null; } return $event; } } ``` -------------------------------- ### Conditional Event Filtering with `before_send` and Hints in PHP Source: https://docs.sentry.io/platforms/php/configuration/filtering This example demonstrates how to use the `before_send` callback with event hints to conditionally filter events. If the original exception is an instance of `MyException`, the event is dropped by returning `null`. ```php \Sentry\init([ 'dsn' => 'https://@o.sentry.io/', 'before_send' => function (\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event { // Ignore the event if the original exception is an instance of MyException if ($hint !== null && $hint->exception instanceof MyException) { return null; } return $event; }, ]); ``` -------------------------------- ### Initialize Sentry with Tracing Enabled Source: https://docs.sentry.io/platforms/php/profiling Configure the Sentry SDK with a DSN and set the traces sample rate to enable performance tracing. This is a prerequisite for profiling. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', 'traces_sample_rate' => 1.0, ]); ``` -------------------------------- ### Initialize Sentry SDK with DSN and max_breadcrumbs Source: https://docs.sentry.io/platforms/php/configuration/options Basic initialization of the Sentry SDK with the DSN and maximum breadcrumbs settings. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', 'max_breadcrumbs' => 50, ]); ``` -------------------------------- ### Initialize Sentry with Profiling Enabled Source: https://docs.sentry.io/platforms/php/profiling Configure the Sentry SDK with DSN, traces sample rate, and profiles sample rate to enable profiling. The profiles sample rate is relative to the traces sample rate. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', 'traces_sample_rate' => 1.0, // Set a sampling rate for profiling - this is relative to traces_sample_rate 'profiles_sample_rate' => 1.0, ]); ``` -------------------------------- ### Install Sentry PHP SDK Source: https://docs.sentry.io/platforms/php/agent Ensure your application uses Sentry PHP SDK version 4.26.0 or later by installing or updating the package with Composer. ```bash composer require sentry/sentry:^4.26.0 ``` -------------------------------- ### Configure Tracing Sample Rate in PHP Source: https://docs.sentry.io/platforms/php/tracing Use this snippet to initialize the Sentry SDK and set a fixed sample rate for transactions. Alternatively, provide a custom function to 'traces_sampler' for more granular control. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', // Specify a fixed sample rate: 'traces_sample_rate' => 0.2, // Or provide a custom sampler: 'traces_sampler' => function (\Sentry\Tracing\SamplingContext $context): float { // return a number between 0 and 1 }, ]); ``` -------------------------------- ### Configure Log Channels in .env Source: https://docs.sentry.io/platforms/php/guides/laravel/logs Set up the necessary environment variables to enable Sentry logging and define the log channels. ```bash # ... LOG_CHANNEL=stack LOG_STACK=single,sentry_logs # ... ``` ```bash # ... SENTRY_ENABLE_LOGS=true # ... ``` ```bash # ... LOG_LEVEL=info # defaults to debug SENTRY_LOG_LEVEL=warning # defaults to LOG_LEVEL # ... ``` -------------------------------- ### Initialize Sentry SDK with Release Name Source: https://docs.sentry.io/platforms/php/configuration/releases Configure the Sentry SDK by providing a DSN and a specific release name during initialization. This tags all subsequent events with the specified release version. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', 'release' => 'my-project-name@2.3.12', ]); ``` -------------------------------- ### Capture Job Check-Ins Source: https://docs.sentry.io/platforms/php/guides/symfony/crons Notify Sentry about the start, success, or failure of a scheduled job using captureCheckIn. Requires the monitor slug. ```php // 🟡 Notify Sentry your job is running: $checkInId = \Sentry\captureCheckIn( slug: '', status: CheckInStatus::inProgress() ); // Execute your scheduled task here... // 🟢 Notify Sentry your job has completed successfully: \Sentry\captureCheckIn( slug: '', status: CheckInStatus::ok(), checkInId: $checkInId, ); ``` ```php // 🔴 Notify Sentry your job has failed: \Sentry\captureCheckIn( slug: '', status: CheckInStatus::error(), checkInId: $checkInId, ); ``` -------------------------------- ### Enable Automatic Tracing Integrations Source: https://docs.sentry.io/platforms/php/guides/symfony/tracing/instrumentation/automatic-instrumentation Configure Sentry tracing and its integrations in your Symfony application. This example shows how to enable all default integrations. ```yaml sentry: tracing: enabled: true dbal: # DB queries enabled: true cache: # cache pools enabled: true twig: # templating engine enabled: true http_client: # Symfony HTTP client enabled: true ``` -------------------------------- ### Set Environment to Production Source: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options Manually set the environment to 'production'. If left empty or null, the Laravel environment will be used. ```php 'environment' => 'production', ``` -------------------------------- ### Enable Performance Tracing Source: https://docs.sentry.io/platforms/php/guides/laravel Set the traces_sample_rate in your config/sentry.php file or SENTRY_TRACES_SAMPLE_RATE in your .env file to a value greater than 0.0 to enable performance tracing. Lower this value in production to manage quota. ```shell # Be sure to lower this value in production otherwise you could burn through your quota quickly. SENTRY_TRACES_SAMPLE_RATE=1.0 ``` -------------------------------- ### Implement Custom Traces Sampler in PHP Source: https://docs.sentry.io/platforms/php/guides/symfony/tracing Implement a custom traces sampler service in PHP for Sentry. This service should return a callable function that determines the sampling rate based on the provided context. ```php 'https://@o.ingest.sentry.io/', 'integrations' => static function (array $integrations) { $integrations = array_filter($integrations, static function (\Sentry\Integration\IntegrationInterface $integration) { // Check if the integration if an instance of the exception listener and return false to remove it from the array if ($integration instanceof \Sentry\Integration\ExceptionListenerIntegration) { return false; } return true; }); return $integrations; }, ]); ``` -------------------------------- ### Configure Sentry SDK Initialization Source: https://docs.sentry.io/platforms/php Initialize the Sentry SDK as early as possible in your application's lifecycle to capture all errors. This configuration includes DSN, PII sending, and sampling rates for performance and profiling. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', // Add request headers, cookies and IP address, // see https://docs.sentry.io/platforms/php/data-management/data-collected/ for more info 'send_default_pii' => true, // ___PRODUCT_OPTION_START___ performance // Specify a fixed sample rate 'traces_sample_rate' => 1.0, // ___PRODUCT_OPTION_END___ performance // ___PRODUCT_OPTION_START___ profiling // Set a sampling rate for profiling - this is relative to traces_sample_rate 'profiles_sample_rate' => 1.0, // ___PRODUCT_OPTION_END___ profiling // ___PRODUCT_OPTION_START___ logs // Enable logs to be sent to Sentry 'enable_logs' => true, // ___PRODUCT_OPTION_END___ logs ]); ``` -------------------------------- ### Create Span with Data Attributes Source: https://docs.sentry.io/platforms/php/guides/laravel/tracing/instrumentation/custom-instrumentation Assign data attributes when starting a new child span. This is useful for tracking specific operations within a transaction. ```php $spanContext = \Sentry\Tracing\SpanContext::make() ->setOp('http.client') ->setData([ 'data_attribute_1' => 42, 'data_attribute_2' => true, ]); $transaction->startChild($context); ``` -------------------------------- ### Basic Sentry Configuration Source: https://docs.sentry.io/platforms/php/guides/symfony/configuration/options Configure the Sentry DSN and other options in the `sentry.yaml` file. The DSN can be set via an environment variable. ```yaml sentry: dsn: "%env(SENTRY_DSN)%" options: max_breadcrumbs: 50 ``` -------------------------------- ### Capture Check-In Source: https://docs.sentry.io/platforms/php/crons Manually capture check-ins to notify Sentry about the status of your scheduled job. This includes starting the job, marking it as successful, or indicating a failure. ```APIDOC ## Capture Check-In ### Description Manually capture check-ins to notify Sentry about the status of your scheduled job. This includes starting the job, marking it as successful, or indicating a failure. ### Method `captureCheckIn(slug: string, status: CheckInStatus, checkInId?: string): string` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **slug** (string) - Required - The unique slug of your Sentry Monitor. * **status** (CheckInStatus) - Required - The current status of the check-in (e.g., `inProgress()`, `ok()`, `error()`). * **checkInId** (string) - Optional - The ID of the check-in to update. Required for subsequent check-ins after the initial `inProgress`. ### Request Example ```php // Notify Sentry your job is running: $checkInId = \Sentry\captureCheckIn( slug: '', status: \Sentry\CheckInStatus::inProgress() ); // Execute your scheduled task here... // Notify Sentry your job has completed successfully: \Sentry\captureCheckIn( slug: '', status: \Sentry\CheckInStatus::ok(), checkInId: $checkInId, ); // Notify Sentry your job has failed: \Sentry\captureCheckIn( slug: '', status: \Sentry\CheckInStatus::error(), checkInId: $checkInId, ); ``` ### Response #### Success Response (200) Returns the `checkInId` (string) of the created or updated check-in. #### Response Example ```json { "checkInId": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### Initialize Sentry SDK with Logging Enabled Source: https://docs.sentry.io/platforms/php/logs Enable logs to be sent to Sentry by setting 'enable_logs' to true during SDK initialization. Remember to flush the logger at the end of your execution to send pending logs. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', // Enable logs to be sent to Sentry 'enable_logs' => true, ]); // Somewhere at the end of your execution, you should flush the logger to send pending logs to Sentry. \Sentry\logger()->flush(); ``` -------------------------------- ### Start Transaction with Data Attributes Source: https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation Create a new transaction and attach custom data attributes during its initialization. This is useful for providing context at the very beginning of a traced operation. ```php // Create a transaction and assign data attributes... $transactionContext = \Sentry\Tracing\TransactionContext::make() ->setName('Example Transaction') ->setOp('http.server') ->setData([ 'data_attribute_1' => 42, 'data_attribute_2' => true, ]); $transaction = \Sentry\startTransaction($transactionContext); ``` -------------------------------- ### Get Last Event ID in PHP Source: https://docs.sentry.io/platforms/php/guides/symfony/user-feedback Retrieve the last event ID generated by the Sentry SDK. This is necessary for associating user feedback with the correct event. ```php \Sentry\SentrySdk::getCurrentHub()->getLastEventId(); ``` -------------------------------- ### Enable Excimer Extension (FPM) Source: https://docs.sentry.io/platforms/php/profiling Enable the Excimer extension for PHP-FPM environments. ```bash phpenmod -s fpm excimer ``` -------------------------------- ### Start Span with Data Attributes Source: https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation Initiate a child span within an existing transaction and include custom data attributes. This allows for detailed context specific to sub-operations. ```php // ... or create a span and assign data attributes $spanContext = \Sentry\Tracing\SpanContext::make() ->setOp('http.client') ->setData([ 'data_attribute_1' => 42, 'data_attribute_2' => true, ]); $transaction->startChild($context); ``` -------------------------------- ### Start and Set Current Transaction Source: https://docs.sentry.io/platforms/php/guides/laravel/tracing/instrumentation/custom-instrumentation Initiate a new transaction with a name and operation, then set it as the current span on the Sentry Hub. This allows subsequent operations to be associated with this new transaction. ```php $transactionContext = \Sentry\Tracing\TransactionContext::make() ->setName('Example Transaction'); ->setOp('http.server'); $transaction = \Sentry\startTransaction($transactionContext); // A transaction is a span so we set it using `setSpan` \Sentry\SentrySdk::getCurrentHub()->setSpan($transaction); ``` -------------------------------- ### Implement `before_send_log` Callback Service Source: https://docs.sentry.io/platforms/php/guides/symfony/logs Implement the service for the `before_send_log` option. The callback function receives a log object and should return the log object to send it or `null` to discard it. ```php getLevel() === \Sentry\Logs\LogLevel::info()) { // Filter out all info logs return null; } return $log; }; } } ``` -------------------------------- ### Notify Sentry Job is In Progress Source: https://docs.sentry.io/platforms/php/crons Initiate a check-in to Sentry indicating that a scheduled job has started. This returns a check-in ID that can be used to update the job's status later. ```php // 🟡 Notify Sentry your job is running: $checkInId = \Sentry\captureCheckIn( slug: '', status: CheckInStatus::inProgress(), monitorConfig: $monitorConfig, ); ``` -------------------------------- ### Notify Sentry of Successful Job Completion (Heartbeat) Source: https://docs.sentry.io/platforms/php/crons Use this to notify Sentry that a scheduled job has completed successfully. This is part of the heartbeat monitoring which alerts you if a job doesn't start as expected. ```php // Execute your scheduled task... // 🟢 Notify Sentry your job completed successfully: \Sentry\captureCheckIn( slug: '', status: CheckInStatus::ok(), duration: 10, // Optional duration in seconds ); ``` -------------------------------- ### Basic `before_send` Callback in PHP Source: https://docs.sentry.io/platforms/php/configuration/filtering Use this snippet to initialize the Sentry SDK with a basic `before_send` callback. The callback receives the event object and can return it as is, or return `null` to discard the event. ```php \Sentry\init([ 'dsn' => 'https://@o.sentry.io/', 'before_send' => function (\Sentry\Event $event): ?\Sentry\Event { return $event; }, ]); ``` -------------------------------- ### Truncated Tag Example Source: https://docs.sentry.io/platforms/php/guides/laravel/troubleshooting Demonstrates how a long tag value exceeding the 200-character limit is truncated in Sentry. Consider splitting data across multiple tags if important information is lost. ```url https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=161803398874989484820458683436563811772030917980576 ``` -------------------------------- ### Implement `tracesSampler` Callback Source: https://docs.sentry.io/platforms/php/guides/laravel/configuration/filtering Implement the `tracesSampler` method to define the logic for sampling or dropping transactions. This callback receives a `SamplingContext` and should return a float representing the sample rate (1.0 to sample, 0.0 to drop). ```php class Sentry { // `traces_sampler` replaces `traces_sample_rate` when both are configured. public static function tracesSampler(\Sentry\Tracing\SamplingContext $context): float { if ($context->getParentSampled()) { // If the parent transaction (for example a JavaScript front-end) // is sampled, also sample the current transaction. return 1.0; } if (some_condition()) { // Drop this transaction by setting its sample rate to 0. return 0.0; } // Default sample rate for all other transactions. return 0.25; } } ``` -------------------------------- ### Filter Events with `before_send` Callback - PHP Source: https://docs.sentry.io/platforms/php/configuration/filtering Use the `before_send` callback to inspect and modify events before they are sent to Sentry. This example filters out events related to database unavailability by setting a specific fingerprint. ```php \Sentry\init([ 'dsn' => 'https://@o.ingest.sentry.io/', 'before_send' => function (\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event { if ($hint !== null && $hint->exception !== null && str_contains($hint->exception->getMessage(), 'database unavailable')) { $event->setFingerprint(['database-unavailable']); } return $event; }, ]); ``` -------------------------------- ### Configure Sentry SDK with a Debug Stdout Logger Source: https://docs.sentry.io/platforms/php/configuration/options Initialize the Sentry SDK and configure it to log debug messages to standard output. This is not recommended for production environments. ```php // This logs messages to stdout Sentry\init([ 'logger' => new \Sentry\Logger\DebugStdOutLogger(), ]); ``` -------------------------------- ### Manually Wrap HTTP Requests in a Span Source: https://docs.sentry.io/platforms/php/tracing/instrumentation/requests-module Manually instrument an HTTP request by creating a span, setting its operation and description, and finishing it with relevant HTTP data. Ensure a transaction is active before starting the span. ```php $parentSpan = \Sentry\SentrySdk::getCurrentHub()->getSpan(); if ($parentSpan !== null) { $context = \Sentry\Tracing\SpanContext::make() ->setOp('http.client'); $span = $parentSpan->startChild($context); // Set the span we just started as the current span \Sentry\SentrySdk::getCurrentHub()->setSpan($span); $client = new \Cake\Http\Client(); $response = $client->get('https://example.com/'); $span ->setDescription('GET https://example.com/') ->setStatus(\'Sentry\Tracing\SpanStatus::createFromHttpStatusCode($response->getStatusCode())\) ->setData([ 'http.request.method' => 'GET', 'http.response.body.size' => $response->getBody()->getSize(), 'http.response.status_code' => $response->getStatusCode(), ]) ->finish(); // Restore the span back to the parent span \Sentry\SentrySdk::getCurrentHub()->setSpan($parentSpan); } ``` -------------------------------- ### Manually Create and Manage Span - Laravel Source: https://docs.sentry.io/platforms/php/guides/laravel/tracing/instrumentation/custom-instrumentation Manually create, start, and finish spans for fine-grained control over transaction instrumentation. This method requires explicit handling of span lifecycles and parent span restoration. ```php function expensive_operation(): void { $parent = \Sentry\SentrySdk::getCurrentHub()->getSpan(); $span = null; // Check if we have a parent span (this is the case if we started a transaction earlier) if ($parent !== null) { $context = \Sentry\Tracing\SpanContext::make() ->setOp('some_operation') ->setDescription('This is a description'); $span = $parent->startChild($context); // Set the current span to the span we just started \Sentry\SentrySdk::getCurrentHub()->setSpan($span); } try { // Do the expensive operation... } finally { // We only have a span if we started a span earlier if ($span !== null) { $span->finish(); // Restore the current span back to the parent span \Sentry\SentrySdk::getCurrentHub()->setSpan($parent); } } } ``` -------------------------------- ### Enable Excimer Extension Source: https://docs.sentry.io/platforms/php/guides/laravel/profiling Enable the Excimer extension for PHP FPM or Apache. ```bash phpenmod -s fpm excimer # or phpenmod -s apache2 excimer ``` -------------------------------- ### Verify Sentry Configuration with Artisan Source: https://docs.sentry.io/platforms/php/guides/laravel Run this Artisan command to test if your Sentry configuration is correctly set up and able to send events. ```shell php artisan sentry:test ```