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

Elastic Apm Php Agent Laravel Package

philkra/elastic-apm-php-agent

PHP agent for Elastic APM that instruments your application to capture transactions, spans, errors, and performance metrics. Sends telemetry to Elastic APM Server for tracing and monitoring, with support for web and CLI workloads and configurable sampling.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Aligns with Laravel’s event-driven and middleware-based architecture, enabling seamless integration into request lifecycle (e.g., Kernel.php, middleware, or service providers).
    • Supports distributed tracing (transactions/spans), critical for microservices or monolithic apps with external dependencies (e.g., queues, APIs, DB calls).
    • Minimal overhead is ideal for production-grade observability without performance degradation.
    • Elastic APM compatibility ensures integration with existing Elastic Stack (e.g., Kibana dashboards, alerts, or SIEM tools).
  • Cons:
    • Archived status (last release in 2019) raises concerns about compatibility with modern PHP/Laravel (e.g., PHP 8.x, Laravel 10.x) and security vulnerabilities (e.g., outdated dependencies).
    • Lack of active maintenance may limit long-term viability or bug fixes for edge cases.
    • No native Laravel-specific integrations (e.g., Horizon queues, Scout, or Forge) requires manual instrumentation.

Integration Feasibility

  • Laravel-Specific Hooks:
    • Middleware: Wrap requests in transactions via HandleExceptions or custom middleware.
    • Service Providers: Boot the agent in AppServiceProvider with config (e.g., config/apm.php).
    • Exceptions: Extend App\Exceptions\Handler to capture unhandled errors.
    • Artisan Commands: Instrument CLI transactions for background jobs.
  • Custom Spans:
    • Use decorators (e.g., Span::start()) around:
      • Database queries (Query Builder/Eloquent).
      • HTTP clients (Guzzle, HTTP client).
      • Queue jobs (Laravel Queues, Horizon).
      • Third-party APIs (e.g., Stripe, PayPal).
  • Metadata:
    • Inject dynamic labels (e.g., user_id, request_id) via middleware or context managers.

Technical Risk

  • Compatibility Risks:
    • PHP 8.x: Potential issues with named arguments, union types, or attribute syntax (if used internally).
    • Laravel 10.x: Changes in Request handling or exception hierarchy may break auto-detection.
    • Elastic APM Server: May require configuration tweaks for newer server versions (e.g., API changes).
  • Functional Gaps:
    • No built-in Laravel queue worker support: Requires manual instrumentation for Horizon/Redis queues.
    • No native support for Laravel’s Scout: Custom spans needed for search operations.
    • No async instrumentation: May miss spans in event listeners or deferred jobs without explicit wrapping.
  • Security Risks:
    • Outdated dependencies: Risk of CVEs in underlying libraries (e.g., monolog, guzzle).
    • Sensitive data leakage: Ensure metadata (e.g., user_data) doesn’t expose PII without sanitization.

Key Questions

  1. Compatibility:
    • Has the package been tested with PHP 8.1+ and Laravel 9/10? If not, what are the upgrade paths?
    • Are there known issues with Elastic APM Server v8.x (latest stable)?
  2. Maintenance:
    • Are there community forks or alternatives (e.g., elastic/apm-agent-php) that are actively maintained?
    • What’s the migration path if this package is abandoned?
  3. Performance:
    • What’s the real-world overhead in production (e.g., latency impact on 99th percentile requests)?
    • How does it handle high-throughput environments (e.g., 10K+ RPS)?
  4. Instrumentation Coverage:
    • How would you instrument Laravel-specific components (e.g., Scout, Horizon, Forge) without built-in support?
    • Can it trace serverless/Laravel Vapor deployments effectively?
  5. Data Privacy:
    • How is sensitive metadata (e.g., tokens, PII) handled to prevent leaks?
    • Are there built-in redaction mechanisms for Elastic APM?

Integration Approach

Stack Fit

  • Best For:
    • Laravel monoliths with external dependencies (DB, APIs, queues).
    • Microservices needing distributed tracing across PHP services.
    • Observability-heavy teams already using Elastic Stack (Kibana, Logstash).
  • Less Ideal For:
    • Greenfield projects where a modern alternative (e.g., OpenTelemetry) is preferred.
    • Teams without Elastic APM infrastructure (requires setup of APM Server, Kibana).
    • Low-complexity apps where built-in Laravel logging suffices.

Migration Path

  1. Assessment Phase:
    • Audit current observability tools (e.g., Sentry, Datadog) and define gaps this package fills.
    • Test compatibility with a staging environment mirroring production (PHP/Laravel versions).
  2. Pilot Integration:
    • Phase 1: Instrument a non-critical Laravel module (e.g., a background job or API endpoint).
      • Add middleware for auto-transactions.
      • Wrap key services (e.g., HttpClient, Database) with custom spans.
    • Phase 2: Extend to core routes and exceptions via App\Exceptions\Handler.
    • Phase 3: Add metadata (e.g., user_id, environment) via middleware.
  3. Full Rollout:
    • Gradually enable across all services; monitor Elastic APM for missing spans/errors.
    • Validate traces in Kibana for accuracy (e.g., latency, error context).

Compatibility

  • PHP/Laravel:
    • Workarounds for PHP 8.x:
      • Use composer require php:^8.1 with --ignore-platform-reqs if needed.
      • Patch the agent for breaking changes (e.g., match expressions).
    • Laravel-Specific:
      • Override Illuminate\Foundation\Bootstrap\HandleExceptions to capture exceptions early.
      • Use tap() or decorators for Eloquent/Query Builder instrumentation.
  • Elastic APM Server:
    • Configure apm-server.yml to match Laravel’s service names (e.g., service.name: "laravel-app").
    • Adjust transaction_sample_rate to avoid overwhelming the server.

Sequencing

Step Action Dependencies
1. Setup Install package, configure apm-server URL, and basic service metadata. Elastic APM Server running.
2. Auto-Transactions Add middleware to wrap requests in transactions. Laravel middleware pipeline.
3. Custom Spans Instrument DB/API calls with spans. Guzzle/HTTP Client, Eloquent, Queues.
4. Error Reporting Extend Handler to send exceptions to APM. Exception handling layer.
5. Metadata Inject dynamic labels (e.g., user_id) via middleware. Auth system (e.g., Laravel Sanctum).
6. Validation Verify traces in Kibana; check for missing spans/errors. Elastic APM UI access.
7. Optimization Adjust sampling rates; prune unnecessary spans. Performance baselines.

Operational Impact

Maintenance

  • Pros:
    • Minimal code changes: Most instrumentation is declarative (e.g., middleware, decorators).
    • Centralized config: APM settings can be managed via environment variables or config files.
  • Cons:
    • No active maintenance: Bug fixes or Laravel updates will require manual patches.
    • Dependency risks: Outdated libraries may need forking or replacement.
  • Mitigation:
    • Fork the repo and maintain it internally (e.g., via GitHub Enterprise).
    • Set up CI checks to validate compatibility with Laravel/PHP updates.
    • Document workarounds for known issues (e.g., PHP 8.x quirks).

Support

  • Pros:
    • Elastic APM ecosystem: Leverage existing docs, community, and Elastic support for server-side issues.
    • Stack traces: Rich error context reduces debugging time.
  • Cons:
    • Limited community support: Issues may go unanswered due to archived status.
    • Learning curve: Team may need training on Elastic APM’s Kibana UI and trace analysis.
  • Mitigation:
    • Internal runbooks: Document common issues (e.g., "How to fix missing spans in Horizon").
    • Cross-train: Assign team members to Elastic APM/Kibana for troubleshooting.

Scaling

  • Performance:
    • Overhead: Minimal if configured correctly (e.g., sampling rates, async reporting).
    • Bottlenecks: APM Server or network latency may impact high-throughput apps.
  • Throughput:
    • Elastic APM Server: Ensure it’s scaled to handle Laravel
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