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

Newrelic Bundle Laravel Package

check24-cp/newrelic-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-Centric Design: The bundle is explicitly built for Symfony, leveraging its event system, dependency injection, and routing components. This aligns well with Laravel’s ecosystem if using Laravel Symfony Bridge (e.g., laravel/symfony-bundle) or Laravel’s Symfony integration (e.g., via symfony/http-foundation for HTTP requests).
  • Transaction/Log Correlation: The traceId-based log linking is a strong fit for distributed tracing in Laravel, where request IDs (e.g., X-Request-ID headers) are already common. This could integrate with Laravel’s built-in logging or third-party loggers like monolog.
  • CLI/Command Support: Useful for Laravel’s Artisan commands, especially if using Laravel Horizon or Laravel Queues (e.g., messenger in Symfony parlance). The bundle’s CLI transaction naming strategies could mirror Laravel’s command naming conventions.

Integration Feasibility

  • New Relic PHP Agent Compatibility: The bundle extends the existing New Relic PHP Agent, meaning it requires the agent to be installed (newrelic/newrelic). Laravel projects already using the agent would benefit from minimal additional setup.
  • Symfony Abstractions: Laravel lacks native Symfony components (e.g., EventDispatcher, HttpFoundation), so integration would require:
    • Event Listeners: Laravel’s events system can replace Symfony’s EventDispatcher for transaction/log hooks.
    • HTTP Request Handling: Laravel’s Illuminate\Http\Request can be mapped to Symfony’s Request via adapters (e.g., symfony/http-foundation).
    • Routing: Symfony’s Route objects would need translation to Laravel’s Route or Uri classes.
  • Log Integration: Laravel’s Log facade can be extended to batch logs (via monolog) and inject traceId from Laravel’s context (e.g., request()->header('X-Request-ID')).

Technical Risk

  • Symfony Dependency Overhead: Introducing Symfony components for a Laravel project adds complexity. Risks include:
    • Version Conflicts: Symfony 6.x vs. Laravel’s compatible Symfony packages (e.g., symfony/http-foundation:^6.0).
    • Maintenance Burden: Updating Symfony dependencies may require Laravel-specific patches.
  • Transaction Naming Strategies: Laravel’s routing (e.g., Route::get('/user', ...)) differs from Symfony’s (/user/_route). Custom naming strategies would need to be implemented.
  • CLI Transaction Support: Laravel’s Artisan commands lack Symfony’s Command base class, requiring adapters or custom event listeners.
  • Performance Impact: Batching logs (logging.buffer_size) is beneficial but may require tuning for Laravel’s async logging (e.g., single vs. queue drivers).

Key Questions

  1. Symfony Integration Strategy:
    • Will you use laravel/symfony-bundle or manually bridge Symfony components? What’s the trade-off in complexity?
    • How will you handle Symfony’s EventDispatcher in Laravel’s event system? (e.g., via SymfonyBridge or custom listeners).
  2. Transaction Naming:
    • How will Laravel’s route names (e.g., user.profile) map to Symfony’s route naming conventions? Custom strategies needed?
  3. Log Correlation:
    • How will traceId be propagated in Laravel’s context? (e.g., middleware for X-Request-ID or custom log context).
  4. CLI/Command Support:
    • Which Laravel commands (e.g., queue:work, schedule:run) should be monitored? How will their names be formatted?
  5. Performance:
    • What’s the optimal logging.buffer_size for Laravel’s logging drivers (e.g., single, queue, slack)?
  6. Error Exclusion:
    • How will Laravel’s exceptions (e.g., HttpResponseException) be mapped to Symfony’s HttpException for exclusion rules?
  7. Testing:
    • How will you test the bundle in Laravel’s environment? (e.g., mocking Symfony components, verifying traceId propagation).

Integration Approach

Stack Fit

  • Core Compatibility:
    • New Relic PHP Agent: Required (already used in most Laravel monitoring stacks).
    • Symfony Components: Partial fit. Key components:
      • symfony/http-foundation (for Request/Response adapters).
      • symfony/event-dispatcher (for event listeners; replaceable with Laravel’s Events).
      • symfony/console (for CLI transaction support; adapt Laravel’s Artisan commands).
    • Monolog: Laravel’s logging is Monolog-based, so batching/log linking can reuse existing infrastructure.
  • Laravel-Specific Gaps:
    • No native Symfony EventDispatcher → Use Laravel’s Events or a bridge like laravel/symfony-bundle.
    • No HttpKernel → Replace with Laravel’s middleware pipeline or custom RequestContext class.
    • No Command base class → Extend Laravel’s ConsoleCommand or wrap in a Symfony-compatible adapter.

Migration Path

  1. Phase 1: New Relic Agent Setup

    • Ensure newrelic/newrelic is installed and configured (newrelic.ini).
    • Verify basic transaction logging works without the bundle.
  2. Phase 2: Symfony Component Integration

    • Install required Symfony packages:
      composer require symfony/http-foundation symfony/event-dispatcher symfony/console
      
    • Create adapters for:
      • Symfony\Component\HttpFoundation\RequestIlluminate\Http\Request.
      • Symfony\Component\Console\CommandIlluminate\Console\Command.
  3. Phase 3: Bundle Configuration

    • Publish the bundle’s config (if using laravel/symfony-bundle) or create a Laravel config file mirroring Symfony’s structure.
    • Example config/newrelic.php:
      return [
          'appname' => env('NEW_RELIC_APP_NAME', 'laravel_app'),
          'license' => env('NEW_RELIC_LICENSE'),
          'xmit' => false,
          'logging' => [
              'buffer_size' => 50,
          ],
          'exclusions' => [
              'transactions' => ['^ignored\.route$'],
              'exceptions' => [\Symfony\Component\HttpKernel\Exception\HttpException::class],
          ],
      ];
      
  4. Phase 4: Event Listeners

    • Replace Symfony’s EventDispatcher with Laravel’s Events:
      // Example: Log Laravel events to New Relic
      Event::listen(\Illuminate\Http\KernelEvents::REQUEST, function ($request) {
          $adapter = new SymfonyRequestAdapter($request);
          // Use bundle's logic to push transaction/logs
      });
      
  5. Phase 5: CLI Transaction Support

    • Extend Laravel’s Artisan to inject Symfony-style commands:
      // Example: Wrap Artisan command in Symfony Command
      class NewRelicCommand extends Symfony\Component\Console\Command\Command
      {
          protected function execute(InputInterface $input, OutputInterface $output)
          {
              // Delegate to Laravel's Artisan
              Artisan::call('queue:work', [...]);
          }
      }
      
  6. Phase 6: Log Correlation

    • Modify Laravel’s Log facade to include traceId:
      // In AppServiceProvider boot()
      Log::extend('newrelic', function ($app) {
          $handler = new NewRelicHandler(
              $app['newrelic.logger'],
              $app['request']->header('X-Request-ID')
          );
          return new Monolog\Logger('newrelic', [$handler]);
      });
      

Compatibility

  • Laravel Versions: Tested with Laravel 9/10 (Symfony 6.x compatibility). Older versions may require symfony/http-foundation:^5.4.
  • New Relic Agent: Must be v8.0+ for full compatibility with Symfony’s extensions.
  • Logging Drivers: Works best with monolog (Laravel’s default). Async drivers (e.g., queue) may need buffer tuning.
  • Middleware: The bundle assumes middleware can inject traceId. Laravel’s Request middleware can handle this.

Sequencing

  1. Prerequisites:
    • Install New Relic PHP Agent.
    • Set up basic Laravel logging (Monolog).
  2. Core Integration:
    • Add Symfony adapters.
    • Configure bundle settings in config/newrelic.php.
  3. Event Hooks:
    • Implement listeners for KernelEvents (HTTP) and ConsoleEvents (CLI).
  4. Log Enhancements:
    • Extend Monolog to include traceId.
  5. Testing:
    • Validate transactions appear in New Relic with correct names.
    • Verify logs are linked via traceId.
  6. Optimization:
    • Tune logging.buffer_size based on performance metrics.
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware