Convert Figma logo to code with AI

getsentry logosentry-php

The official PHP SDK for Sentry (sentry.io)

1,819
450
1,819
12

Top Related Projects

The official Laravel SDK for Sentry (sentry.io)

13,165

PHP errors for cool kids

Quick Overview

Sentry-php is the official PHP SDK for Sentry, an error tracking and performance monitoring platform. It allows developers to integrate Sentry's error reporting and monitoring capabilities into their PHP applications, helping them identify, track, and resolve issues in real-time.

Pros

  • Easy integration with PHP applications
  • Comprehensive error and exception tracking
  • Supports performance monitoring and distributed tracing
  • Customizable data capture and filtering options

Cons

  • Can potentially impact application performance if not configured properly
  • Requires careful handling of sensitive data to avoid unintended exposure
  • Learning curve for advanced features and configurations
  • Dependency on external service (Sentry) for error reporting

Code Examples

  1. Basic error capture:
<?php
\Sentry\init(['dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0']);

try {
    thisFunctionDoesNotExist();
} catch (Throwable $exception) {
    \Sentry\captureException($exception);
}
  1. Adding custom context:
<?php
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
    $scope->setTag('page_locale', 'de-at');
    $scope->setUser(['email' => 'john.doe@example.com']);
});
  1. Performance monitoring:
<?php
$transaction = \Sentry\startTransaction(
    name: 'test-transaction'
);

\Sentry\SentrySdk::getCurrentHub()->setSpan($transaction);

// ... perform your work ...

$transaction->finish();

Getting Started

  1. Install the SDK using Composer:

    composer require sentry/sentry
    
  2. Initialize Sentry in your application:

    \Sentry\init(['dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0']);
    
  3. Wrap your code in a try-catch block and capture exceptions:

    try {
        $this->doWork();
    } catch (Throwable $exception) {
        \Sentry\captureException($exception);
    }
    
  4. (Optional) Configure additional options as needed:

    \Sentry\init([
        'dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0',
        'traces_sample_rate' => 1.0,
        'environment' => 'production',
    ]);
    

Competitor Comparisons

The official Laravel SDK for Sentry (sentry.io)

Pros of sentry-laravel

  • Tailored integration with Laravel framework, providing out-of-the-box compatibility
  • Automatic configuration of Laravel-specific features like queue workers and Artisan commands
  • Simplified setup process with Laravel-specific service providers and facades

Cons of sentry-laravel

  • Limited to Laravel applications, lacking flexibility for other PHP frameworks
  • Potentially slower updates compared to the core PHP SDK due to additional Laravel-specific testing and compatibility checks

Code Comparison

sentry-laravel:

use Sentry\Laravel\Facade;

Facade::captureException($exception);

sentry-php:

use Sentry\SentrySdk;

SentrySdk::getCurrentHub()->captureException($exception);

The sentry-laravel package provides a more Laravel-friendly syntax through its facade, while sentry-php requires direct interaction with the Sentry SDK. This difference illustrates how sentry-laravel simplifies integration within Laravel applications, but may be less flexible for non-Laravel projects.

13,165

PHP errors for cool kids

Pros of Whoops

  • Lightweight and easy to integrate into existing PHP projects
  • Provides a clean, user-friendly error page for debugging
  • Highly customizable with handlers and editor configurations

Cons of Whoops

  • Focused solely on error handling and display, lacking advanced features
  • Limited to local development environments, not suitable for production use
  • Requires manual integration with logging systems for persistent error tracking

Code Comparison

Sentry PHP:

\Sentry\init(['dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0']);

try {
    thisFunctionWillThrowAnException();
} catch (\Throwable $exception) {
    \Sentry\captureException($exception);
}

Whoops:

$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();

thisFunctionWillThrowAnException();

Sentry PHP offers a more comprehensive error tracking solution with cloud integration, while Whoops provides a simpler, development-focused error display. Sentry PHP is better suited for production environments and distributed systems, whereas Whoops excels in local development for its ease of use and visually appealing error pages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us Check out our open positions

Official Sentry SDK for PHP

CI Coverage Status Latest Stable Version License Total Downloads Monthly Downloads Discord

The Sentry PHP error reporter tracks errors and exceptions that happen during the execution of your application and provides instant notification with detailed information needed to prioritize, identify, reproduce and fix each issue.

Getting started

Install

Install the SDK using Composer.

composer require sentry/sentry

Configuration

Initialize the SDK as early as possible in your application.

\Sentry\init(['dsn' => '___PUBLIC_DSN___' ]);

Usage

try {
    thisFunctionThrows(); // -> throw new \Exception('foo bar');
} catch (\Exception $exception) {
    \Sentry\captureException($exception);
}

Official integrations

The following integrations are fully supported and maintained by the Sentry team.

3rd party integrations using SDK 4.x

The following integrations are available and maintained by members of the Sentry community.

  • Drupal
  • WordPress
  • ... feel free to be famous, create a port to your favourite platform!

3rd party integrations using the old SDK 3.x

3rd party integrations using the old SDK 2.x

3rd party integrations using the old SDK 1.x

Community

Contributing to the SDK

Please make sure to read the CONTRIBUTING.md before making a pull request.

Thanks to everyone who has contributed to this project so far.

Getting help/support

If you need help setting up or configuring the PHP SDK (or anything else in the Sentry universe) please head over to the Sentry Community on Discord. There is a ton of great people in our Discord community ready to help you!

Resources

  • Documentation
  • Discord
  • Stack Overflow
  • Twitter Follow

License

Licensed under the MIT license, see LICENSE