Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sentry Laravel Laravel Package

sentry/sentry-laravel

Official Sentry SDK for Laravel. Automatically capture and report unhandled exceptions and performance data to Sentry, with seamless Laravel integration and configuration. Supports modern Laravel versions and includes tooling for monitoring errors in production.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Observability Alignment: The package integrates seamlessly with Laravel’s exception handling, logging, and tracing systems, aligning with modern observability best practices. It leverages Laravel’s built-in Exceptions and Middleware systems, reducing architectural friction.
  • Modularity: Supports granular configuration (e.g., per-environment DSNs, log levels, trace sampling) without requiring monolithic changes. Features like structured logs, metrics, and feature flag integration (via Pennant) are modular and opt-in.
  • Performance: Designed for low overhead with features like log batching (log_flush_threshold) and trace sampling (SentryTracesSampleRate), critical for production-grade applications.

Integration Feasibility

  • Laravel Ecosystem Compatibility: Officially supports Laravel 11.x–13.x (and older versions via separate branches), ensuring compatibility with modern Laravel applications. Works with Lumen and Octane (via explicit fixes for transaction resets).
  • Dependency Synergy: Built atop sentry/sentry (PHP SDK), ensuring consistency with Sentry’s broader ecosystem (e.g., OTLP integration for OpenTelemetry). No conflicting dependencies with Laravel’s core.
  • Configuration Flexibility: Supports environment variables, config files, and runtime overrides, reducing deployment complexity.

Technical Risk

  • Breaking Changes: Minor risk due to Laravel’s rapid evolution (e.g., Laravel 13 support added in 4.22.0). However, the team actively backports fixes (e.g., Octane transaction resets in 4.22.0).
  • Performance Overhead: Minimal for default usage, but metrics and structured logs may introduce latency if misconfigured (e.g., excessive sampling). Mitigated by configurable thresholds (e.g., log_flush_threshold).
  • Debugging Complexity: Sentry’s structured logs and traces require familiarity with Sentry’s UI/CLI. Teams new to observability may face a learning curve (addressed by Sentry’s Discord community).

Key Questions

  1. Observability Strategy:

    • Will the team use only errors (default) or enable logs, metrics, and traces? This dictates configuration scope (e.g., SENTRY_ENABLE_LOGS, trace_metrics()).
    • Example: If adopting structured logs, ensure LOG_CHANNEL=stack and LOG_STACK includes sentry_logs.
  2. Sampling Strategy:

    • How will trace sampling be configured? Defaults may not suit high-volume APIs (e.g., adjust SentryTracesSampleRate for job queues).
  3. Sensitive Data Handling:

    • Are PII (Personally Identifiable Information) or secrets (e.g., API keys) accidentally logged? Use Sentry’s sanitization or Laravel’s beforeSend hooks.
  4. Cost vs. Value:

    • Sentry’s pricing scales with volume. Audit expected event volume (errors + logs + traces) to avoid cost surprises. Use sampling for high-traffic endpoints.
  5. CI/CD Integration:

    • Will Sentry be used for CI/CD monitoring (e.g., capturing test failures)? Requires additional setup (e.g., SENTRY_TRACES_SAMPLE_RATE=1.0 for full trace collection).

Integration Approach

Stack Fit

  • Laravel Core: Integrates natively with Laravel’s:
    • Exception Handling: Via Integration::handles($exceptions) in bootstrap/app.php.
    • Logging: As a log channel (sentry_logs) or via Log::channel('sentry_logs').
    • Middleware: Supports trace headers (e.g., sentry-trace, baggage) for distributed tracing.
    • Jobs/Queues: Custom middleware (SentryTracesSampleRate) for sampling.
  • PHP Extensions: Requires PHP 8.2+ (for Laravel 12/13) or 8.1+ (Laravel 10/11). No additional extensions needed.
  • Database: No schema changes; stores metadata in Sentry’s cloud service.

Migration Path

  1. Assessment Phase:

    • Audit current error logging (e.g., Monolog, Laravel’s default). Identify gaps (e.g., missing stack traces, context).
    • Define Sentry DSN (Data Source Name) and environment (e.g., production, staging).
  2. Installation:

    composer require sentry/sentry-laravel
    php artisan sentry:publish --dsn=https://<KEY>@<HOST>/<PROJECT>
    
    • Add SENTRY_LARAVEL_DSN to .env.
  3. Configuration:

    • Basic Setup (errors only):
      // bootstrap/app.php
      Integration::handles($exceptions);
      
    • Advanced Setup (logs + traces):
      LOG_CHANNEL=stack
      LOG_STACK=single,sentry_logs
      SENTRY_ENABLE_LOGS=true
      SENTRY_LOG_LEVEL=info
      
      // config/logging.php
      'sentry_logs' => [
          'driver' => 'sentry_logs',
          'level' => env('SENTRY_LOG_LEVEL', 'info'),
      ],
      
  4. Testing:

    • Local Development: Use SENTRY_LARAVEL_DSN=__DEBUG__ to test without sending data.
    • Staging: Validate error capture and log routing.
    • Production: Monitor Sentry’s Issues and Performance tabs for anomalies.
  5. Opt-in Features:

    • Metrics: Enable via trace_metrics() (e.g., for API latency).
    • Feature Flags: Auto-capture Pennant flags if using Laravel Pennant.
    • OTLP: For OpenTelemetry integration (requires OTLPIntegration).

Compatibility

  • Laravel Versions: Explicit support for 11.x–13.x; older versions via separate branches.
  • PHP Versions: 8.2+ for Laravel 12/13; 8.1+ for 10/11. Avoid PHP 7.x due to deprecations in the underlying sentry/sentry SDK.
  • Dependencies: No conflicts with Laravel’s core or popular packages (e.g., laravel/breeze, spatie/laravel-permission).

Sequencing

  1. Phase 1: Basic error tracking (high priority for bug resolution).
  2. Phase 2: Structured logs and performance monitoring (medium priority for debugging).
  3. Phase 3: Metrics and advanced features (low priority for analytics).
  4. Phase 4: CI/CD integration (e.g., capturing test failures).

Operational Impact

Maintenance

  • Configuration Drift: Minimal risk if using .env and config/sentry.php. Changes to Sentry’s SDK may require updates (e.g., PHP 8.2+ for Laravel 12/13).
  • Dependency Updates: Proactive updates recommended (e.g., composer update sentry/sentry-laravel). Use composer why-not to audit breaking changes.
  • Logging Retention: Sentry’s retention policies apply (default: 30 days for free tier). Archive critical logs locally if needed.

Support

  • Troubleshooting:
    • Missing Events: Verify DSN, network connectivity, and Laravel’s exception handling.
    • Performance Issues: Check log_flush_threshold and trace sampling rates.
    • Debugging: Use Sentry\init([...]) with debug: true for local testing.
  • Community: Active Discord and Stack Overflow support.
  • Sentry Status: Monitor Sentry’s status page for outages.

Scaling

  • Event Volume: Sentry’s free tier limits 5,000 events/month. Monitor usage in the Settings > Quotas tab.
    • Mitigation: Implement sampling (e.g., SENTRY_TRACES_SAMPLE_RATE=0.1 for 10% of traces).
  • Performance:
    • Logs: Batch logs with log_flush_threshold (default: 100).
    • Traces: Use SentryTracesSampleRate for high-throughput endpoints.
  • Distributed Tracing: Supports baggage and trace headers for microservices. Ensure upstream services propagate sentry-trace.

Failure Modes

Failure Scenario Impact Mitigation
Sentry API downtime Lost error logs/traces
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4