Skip to content

Latest commit

 

History

History
104 lines (77 loc) · 3 KB

File metadata and controls

104 lines (77 loc) · 3 KB
title PHP
sdk sentry.php
caseStyle snake_case
supportLevel production
description Learn how to set up Sentry in your PHP application.
categories
server
og_image /og-images/platforms-php.png

Prerequisites

  • You need a Sentry account and project
  • Your application needs to run on PHP 7.2 or later
  • You need to be using Composer
  • Read one of these other guides if you use Laravel or Symfony

Features

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

<OnboardingOptionButtons options={["error-monitoring", "performance", "profiling", "logs"]} />

Install

Install the Sentry SDK using Composer:

composer require sentry/sentry

To use Profiling, you'll also need to install the Excimer extension via PECL:

pecl install excimer

The Excimer PHP extension supports PHP 7.2 and up. Excimer requires Linux or macOS and doesn't support Windows. For additional ways to install Excimer, see docs.

Configure

To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.

\Sentry\init([
  'dsn' => '___PUBLIC_DSN___',
  // 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
]);
In order to receive stack trace arguments in your errors, make sure to set `zend.exception_ignore_args: Off` in your php.ini

Verify

In PHP you can either capture a caught exception or capture the last error with captureLastError.

try {
  $this->functionFailsForSure();
} catch (\Throwable $exception) {
  \Sentry\captureException($exception);
}

Set up Sentry through Forge

If you're using Laravel's Forge platform to provision and deploy your PHP application, you can create a Sentry organization through Forge.

Sentry and Forge

Next Steps

  • Explore practical guides on what to monitor, log, track, and investigate after setup