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 captures unhandled exceptions, performance data, and context from your app, sending issues and traces to Sentry for faster debugging and monitoring. Supports modern Laravel versions with simple Composer install.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Seamless Laravel Integration: The package is purpose-built for Laravel (and Lumen), leveraging Laravel’s native exception handling, middleware, and service container. It integrates directly with Laravel’s bootstrap/app.php via the Integration::handles() method, ensuring minimal disruption to existing architecture.
  • Modular Design: Supports optional features (e.g., logs, metrics, traces) via environment variables and configuration, allowing granular adoption based on team needs.
  • Performance-Centric: Optimized for low overhead (e.g., log_flush_threshold, trace sampling middleware) and includes instrumentation for critical Laravel components (e.g., cache, queues, HTTP requests).
  • Observability-First: Aligns with modern SRE practices by providing structured logs, metrics, and distributed tracing out of the box.

Integration Feasibility

  • Low Friction: Installation requires only composer require and a one-line bootstrap/app.php modification. Configuration is environment-driven (.env + config/sentry.php).
  • Backward Compatibility: Supports Laravel 8–13+ and PHP 7.2–8.2+, with clear upgrade paths for legacy versions.
  • Extensibility: Hooks into Laravel’s event system (e.g., Illuminate\Queue\Events\JobProcessed) and supports custom integrations (e.g., Pennant feature flags).
  • Testing Support: Includes CLI tools (php artisan sentry:publish) and integrates with Laravel’s testing helpers (e.g., captureException() in tests).

Technical Risk

  • Dependency Bloat: Underlying sentry/sentry-php SDK (~50MB) may impact cold starts in serverless environments (mitigated by lazy-loading).
  • Configuration Complexity: Advanced features (e.g., OTLP, structured logs) require additional setup. Risk of misconfiguration (e.g., over-sampling traces) without proper monitoring.
  • Breaking Changes: Recent versions (v4.x+) dropped support for older Laravel/PHP versions. Migration from v3.x may require refactoring.
  • Performance Tradeoffs: Auto-instrumentation (e.g., cache spans) adds overhead. Requires benchmarking in high-throughput systems.

Key Questions

  1. Observability Goals:
    • Are we prioritizing error tracking, performance monitoring, or both? (e.g., metrics vs. traces).
    • Do we need structured logs or just exceptions?
  2. Environment Constraints:
    • Will this run in serverless (e.g., Laravel Vapor) or traditional hosting? (Impacts trace sampling and log buffering.)
    • Are there PII/data privacy concerns requiring custom sanitization?
  3. Team Maturity:
    • Does the team have experience with Sentry’s UI/alerting? (Avoids misconfigured alerts.)
    • Is there a process for reviewing/acting on Sentry events?
  4. Cost:
    • Sentry’s pricing model (e.g., event volume limits) may require sampling strategies for high-traffic apps.
  5. Alternatives:
    • Could existing tools (e.g., Laravel’s built-in error pages, Datadog) meet needs with less overhead?

Integration Approach

Stack Fit

  • Laravel Native: Designed for Laravel’s ecosystem (e.g., service providers, Facades, exception handlers). No polyfills or shims required.
  • PHP SDK Synergy: Leverages sentry/sentry-php for cross-platform features (e.g., OTLP, structured events) while adding Laravel-specific integrations (e.g., Eloquent queries, Blade templates).
  • Tooling Compatibility:
    • Works with Laravel Forge/Vapor, Valet, and Docker.
    • Supports Laravel’s queue workers, Horizon, and Octane.
    • Integrates with Laravel Mix/Vite for frontend error tracking (via sentry-trace headers).

Migration Path

  1. Pilot Phase:
    • Install in a staging environment with SENTRY_ENABLE_LOGS=false to avoid noise.
    • Start with exception tracking only (Integration::handles() in bootstrap/app.php).
  2. Gradual Rollout:
    • Enable traces for critical paths (e.g., /checkout) using Sentry\startTransaction().
    • Add metrics for key business events (e.g., trace_metrics()->count('orders_processed')).
  3. Advanced Features:
    • Configure structured logs via LOG_STACK=sentry_logs.
    • Set up sampling (Sentry\setTraceSampleRate(0.1)) for high-volume endpoints.
  4. Legacy Systems:
    • For Laravel <8.x, use pinned versions (e.g., 2.14.x) and follow deprecated guides.

Compatibility

  • Laravel Versions: Tested on 8–13+. Use laravel/framework version constraints in composer.json to avoid conflicts.
  • PHP Extensions: Requires json, curl, and openssl. No other extensions needed.
  • Database/ORM: Auto-instruments Eloquent queries but may need custom spans for raw SQL.
  • Third-Party Packages: Conflicts possible with other error handlers (e.g., whoops). Use Sentry\init() early in bootstrap/app.php.

Sequencing

  1. Core Setup:
    • Install package + configure DSN (php artisan sentry:publish).
    • Add Integration::handles() to bootstrap/app.php.
  2. Exception Tracking:
    • Verify errors appear in Sentry dashboard.
  3. Performance Monitoring:
    • Enable traces for API routes using middleware:
      use Sentry\Laravel\Integration;
      
      public function handle(Request $request, Closure $next) {
          Integration::startTransaction($request);
          return $next($request);
      }
      
  4. Logs/Metrics:
    • Configure LOG_STACK and SENTRY_ENABLE_LOGS.
    • Add custom metrics in business logic (e.g., trace_metrics()->gauge('db_query_time')).
  5. Alerting:
    • Set up Sentry rules for critical errors (e.g., QueryException).

Operational Impact

Maintenance

  • Configuration Drift: Centralized in .env and config/sentry.php. Use tools like Laravel Envoy or Ansible to sync across environments.
  • Dependency Updates: Follow sentry/sentry-php releases for breaking changes. Pin major versions in composer.json:
    "sentry/sentry-laravel": "^4.25",
    "sentry/sentry": "^4.23"
    
  • Debugging: Sentry’s own errors may require checking storage/logs/sentry.log or disabling the SDK temporarily (SENTRY_LARAVEL_DSN=).

Support

  • Troubleshooting:
    • Use Sentry\configureScope() to add context to events during debugging.
    • Check SENTRY_DEBUG environment variable for SDK logs.
    • Leverage Sentry’s Discord community for Laravel-specific issues.
  • On-Call Impact:
    • Alert fatigue risk if rules are too broad. Start with error severity only.
    • Integrate Sentry alerts with PagerDuty/Opsgenie for critical paths.
  • Vendor Lock-in: Sentry’s proprietary event format may complicate migration to other APMs (e.g., Datadog). Export data via Sentry’s API if needed.

Scaling

  • Performance:
    • Sampling: Use Sentry\setTraceSampleRate() to limit trace volume (e.g., 10% for staging).
    • Batching: Configure sentry.log_flush_threshold to reduce I/O (e.g., 100).
    • Queue Workers: Add SentryTracesSampleRate middleware to sample job traces.
  • Cost Optimization:
    • Filter sensitive data with beforeSend callback:
      Sentry\configureScope(function ($scope) {
          $scope->setTag('env', app()->environment());
      });
      
    • Use ignoreErrors to exclude known non-critical errors (e.g., deprecation notices).
  • High Availability:
    • Sentry’s SDK buffers events locally. Ensure storage/logs/sentry.log has sufficient disk space.
    • For multi-process apps (e.g., Octane), use Sentry\init() in each worker.

Failure Modes

Failure Scenario Impact Mitigation
Sentry API downtime Events lost; no error visibility Buffer events locally; set up fallback logging.
DSN misconfiguration No events sent; silent failures Validate DSN in CI/CD; use SENTRY_DEBUG=true.
Over-sampling traces High costs; noisy dashboard Set Sentry\setTraceSampleRate(0.1) by default.
PII in error reports Compliance violations Use beforeSend to redact data.
SDK version conflicts Runtime errors Pin versions in composer.json.
Laravel cache clearing Lost transaction context Use `
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope