Using Rollbar with Lumen 5.7












2















So, currently the two most popular (IMHO) rollbar packages for Lumen (not Laravel) are:





  • https://github.com/rollbar/rollbar-php-laravel, and

  • https://github.com/jenssegers/laravel-rollbar


Given that https://github.com/jenssegers/laravel-rollbar explicitly states attempts to add Lumen support for 5.x and given that there is this wonderful tutorial by James Elliot on adding Rollbar to Lumen 5.2, I attempted to update the code for his tutorial and use it for Lumen 5.7.



The bulk of his work is in his RollbarLumenServiceProvider which looks like this:



namespace AppProviders;

use JenssegersRollbarRollbarLogHandler;
use IlluminateSupportServiceProvider;
use InvalidArgumentException;
use MonologHandlerRollbarHandler;
use Rollbar;
use RollbarNotifier;

class RollbarLumenServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Register the service provider.
*/
public function register()
{
$this->app->configure('rollbar');

// Don't register rollbar if it is not configured.
if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('rollbar')) {
return;
}

$app = $this->app;

$app[RollbarNotifier::class] = $app->share(function ($app) {

// Default configuration.
$defaults = [
'environment' => $app->environment(),
'root' => base_path(),
];

$config = array_merge($defaults, $app['config']->get('services.rollbar', ));

$config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

if (empty($config['access_token'])) {
throw new InvalidArgumentException('Rollbar access token not configured');
}

Rollbar::$instance = $rollbar = new RollbarNotifier($config);

return $rollbar;
});

$app[RollbarLogHandler::class] = $app->share(function ($app) {
$level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

$handler = app(RollbarHandler::class, [$this->app[RollbarNotifier::class], $level]);

return $handler;
});

// Register the fatal error handler.
register_shutdown_function(function () use ($app) {
if (isset($app[Rollbar::class])) {
$app->make(Rollbar::class);
Rollbar::report_fatal_error();
}
});

// If the Rollbar client was resolved, then there is a possibility that there
// are unsent error messages in the internal queue, so let's flush them.
register_shutdown_function(function () use ($app) {
if (isset($app[Rollbar::class])) {
$app[Rollbar::class]->flush();
}
});
}

public function boot()
{
$app = $this->app;

// Listen to log messages.
$app['log']->pushHandler(
app(RollbarLogHandler::class, [
$this->app[Rollbar::class]
])
);
}

public function provides()
{
return [
RollbarLogHandler::class
];
}
}


My attempt at updating this for Lumen 5.7 accounting for deprecation and breaking changes looks like this:



<?php
namespace AppProviders;

use JenssegersRollbarRollbarLogHandler;
use IlluminateSupportServiceProvider;
use InvalidArgumentException;
use MonologHandlerRollbarHandler;
use Rollbar;
use RollbarNotifier;

class RollbarLumenServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

private function getApp($app): LaravelLumenApplication
{
return $app;
}

/**
* Register the service provider.
*/
public function register()
{
$app = $this->getApp($this->app);

$app->configure('rollbar');

// Don't register rollbar if it is not configured.
if (!getenv('ROLLBAR_TOKEN') and !$app['config']->get('rollbar')) {
return;
}


$app->singleton(RollbarNotifier::class, function (LaravelLumenApplication $app)
{
// Default configuration.
$defaults = [
'environment' => $app->environment(),
'root' => base_path(),
];

$config = array_merge($defaults, $app['config']->get('services.rollbar', ));

$config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

if (empty($config['access_token'])) {
throw new InvalidArgumentException('Rollbar access token not configured');
}

Rollbar::$instance = $rollbar = new RollbarNotifier($config);

return $rollbar;
});

$app->singleton(RollbarHandler::class, function (LaravelLumenApplication $app)
{
$level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

//$handler = app(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);
$handler = $app->makeWith(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);

return $handler;
});

// Register the fatal error handler.
register_shutdown_function(function () use ($app)
{
if (isset($app[Rollbar::class]))
{
$app->make(Rollbar::class);
Rollbar::report_fatal_error();
}
});

// If the Rollbar client was resolved, then there is a possibility that there
// are unsent error messages in the internal queue, so let's flush them.
register_shutdown_function(function () use ($app)
{
if (isset($app[Rollbar::class])) {
$app[Rollbar::class]->flush();
}
});
}

public function boot()
{
$app = $this->app;

// Listen to log messages.
$app['log']->pushHandler(
$app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
);
}

public function provides()
{
return [
RollbarLogHandler::class
];
}
}


I think it ALMOST works. I get an exception in this method:



    public function boot()
{
$app = $this->app;

// Listen to log messages.
$app['log']->pushHandler(
$app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
);
}


Here is the Exception trace:



(1/1) ReflectionException
Class IlluminateFoundationApplication does not exist
in Container.php line 838



at ReflectionParameter->getClass()
in Container.php line 838



at Container->resolveDependencies(array(object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter)))
in Container.php line 807



at Container->build('JenssegersRollbarRollbarLogHandler')
in Container.php line 658



at Container->resolve('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
in Container.php line 609



at Container->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
in Application.php line 260



at Application->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
in Container.php line 597



at Container->makeWith('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
in RollbarLumenServiceProvider.php line 104



at RollbarLumenServiceProvider->boot()
at call_user_func_array(array(object(RollbarLumenServiceProvider), 'boot'), array())
in BoundMethod.php line 29



at BoundMethod::IlluminateContainer{closure}()
in BoundMethod.php line 87



at BoundMethod::callBoundMethod(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), object(Closure))
in BoundMethod.php line 31



at BoundMethod::call(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), array(), null)
in Container.php line 572



at Container->call(array(object(RollbarLumenServiceProvider), 'boot'))
in Application.php line 237



at Application->bootProvider(object(RollbarLumenServiceProvider))
in Application.php line 222



at Application->LaravelLumen{closure}(object(RollbarLumenServiceProvider), 'AppProvidersRollbarLumenServiceProvider')



It's at this point that I get stuck. Does anyone know how to fix this error? I am not a service container or rollbar wiz and will appreciate any help. Hopefully, this will serve as a nice community way to get Rollbar working with Lumen 5.7!










share|improve this question



























    2















    So, currently the two most popular (IMHO) rollbar packages for Lumen (not Laravel) are:





    • https://github.com/rollbar/rollbar-php-laravel, and

    • https://github.com/jenssegers/laravel-rollbar


    Given that https://github.com/jenssegers/laravel-rollbar explicitly states attempts to add Lumen support for 5.x and given that there is this wonderful tutorial by James Elliot on adding Rollbar to Lumen 5.2, I attempted to update the code for his tutorial and use it for Lumen 5.7.



    The bulk of his work is in his RollbarLumenServiceProvider which looks like this:



    namespace AppProviders;

    use JenssegersRollbarRollbarLogHandler;
    use IlluminateSupportServiceProvider;
    use InvalidArgumentException;
    use MonologHandlerRollbarHandler;
    use Rollbar;
    use RollbarNotifier;

    class RollbarLumenServiceProvider extends ServiceProvider
    {
    /**
    * Indicates if loading of the provider is deferred.
    *
    * @var bool
    */
    protected $defer = false;

    /**
    * Register the service provider.
    */
    public function register()
    {
    $this->app->configure('rollbar');

    // Don't register rollbar if it is not configured.
    if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('rollbar')) {
    return;
    }

    $app = $this->app;

    $app[RollbarNotifier::class] = $app->share(function ($app) {

    // Default configuration.
    $defaults = [
    'environment' => $app->environment(),
    'root' => base_path(),
    ];

    $config = array_merge($defaults, $app['config']->get('services.rollbar', ));

    $config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

    if (empty($config['access_token'])) {
    throw new InvalidArgumentException('Rollbar access token not configured');
    }

    Rollbar::$instance = $rollbar = new RollbarNotifier($config);

    return $rollbar;
    });

    $app[RollbarLogHandler::class] = $app->share(function ($app) {
    $level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

    $handler = app(RollbarHandler::class, [$this->app[RollbarNotifier::class], $level]);

    return $handler;
    });

    // Register the fatal error handler.
    register_shutdown_function(function () use ($app) {
    if (isset($app[Rollbar::class])) {
    $app->make(Rollbar::class);
    Rollbar::report_fatal_error();
    }
    });

    // If the Rollbar client was resolved, then there is a possibility that there
    // are unsent error messages in the internal queue, so let's flush them.
    register_shutdown_function(function () use ($app) {
    if (isset($app[Rollbar::class])) {
    $app[Rollbar::class]->flush();
    }
    });
    }

    public function boot()
    {
    $app = $this->app;

    // Listen to log messages.
    $app['log']->pushHandler(
    app(RollbarLogHandler::class, [
    $this->app[Rollbar::class]
    ])
    );
    }

    public function provides()
    {
    return [
    RollbarLogHandler::class
    ];
    }
    }


    My attempt at updating this for Lumen 5.7 accounting for deprecation and breaking changes looks like this:



    <?php
    namespace AppProviders;

    use JenssegersRollbarRollbarLogHandler;
    use IlluminateSupportServiceProvider;
    use InvalidArgumentException;
    use MonologHandlerRollbarHandler;
    use Rollbar;
    use RollbarNotifier;

    class RollbarLumenServiceProvider extends ServiceProvider
    {
    /**
    * Indicates if loading of the provider is deferred.
    *
    * @var bool
    */
    protected $defer = false;

    private function getApp($app): LaravelLumenApplication
    {
    return $app;
    }

    /**
    * Register the service provider.
    */
    public function register()
    {
    $app = $this->getApp($this->app);

    $app->configure('rollbar');

    // Don't register rollbar if it is not configured.
    if (!getenv('ROLLBAR_TOKEN') and !$app['config']->get('rollbar')) {
    return;
    }


    $app->singleton(RollbarNotifier::class, function (LaravelLumenApplication $app)
    {
    // Default configuration.
    $defaults = [
    'environment' => $app->environment(),
    'root' => base_path(),
    ];

    $config = array_merge($defaults, $app['config']->get('services.rollbar', ));

    $config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

    if (empty($config['access_token'])) {
    throw new InvalidArgumentException('Rollbar access token not configured');
    }

    Rollbar::$instance = $rollbar = new RollbarNotifier($config);

    return $rollbar;
    });

    $app->singleton(RollbarHandler::class, function (LaravelLumenApplication $app)
    {
    $level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

    //$handler = app(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);
    $handler = $app->makeWith(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);

    return $handler;
    });

    // Register the fatal error handler.
    register_shutdown_function(function () use ($app)
    {
    if (isset($app[Rollbar::class]))
    {
    $app->make(Rollbar::class);
    Rollbar::report_fatal_error();
    }
    });

    // If the Rollbar client was resolved, then there is a possibility that there
    // are unsent error messages in the internal queue, so let's flush them.
    register_shutdown_function(function () use ($app)
    {
    if (isset($app[Rollbar::class])) {
    $app[Rollbar::class]->flush();
    }
    });
    }

    public function boot()
    {
    $app = $this->app;

    // Listen to log messages.
    $app['log']->pushHandler(
    $app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
    );
    }

    public function provides()
    {
    return [
    RollbarLogHandler::class
    ];
    }
    }


    I think it ALMOST works. I get an exception in this method:



        public function boot()
    {
    $app = $this->app;

    // Listen to log messages.
    $app['log']->pushHandler(
    $app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
    );
    }


    Here is the Exception trace:



    (1/1) ReflectionException
    Class IlluminateFoundationApplication does not exist
    in Container.php line 838



    at ReflectionParameter->getClass()
    in Container.php line 838



    at Container->resolveDependencies(array(object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter)))
    in Container.php line 807



    at Container->build('JenssegersRollbarRollbarLogHandler')
    in Container.php line 658



    at Container->resolve('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
    in Container.php line 609



    at Container->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
    in Application.php line 260



    at Application->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
    in Container.php line 597



    at Container->makeWith('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
    in RollbarLumenServiceProvider.php line 104



    at RollbarLumenServiceProvider->boot()
    at call_user_func_array(array(object(RollbarLumenServiceProvider), 'boot'), array())
    in BoundMethod.php line 29



    at BoundMethod::IlluminateContainer{closure}()
    in BoundMethod.php line 87



    at BoundMethod::callBoundMethod(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), object(Closure))
    in BoundMethod.php line 31



    at BoundMethod::call(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), array(), null)
    in Container.php line 572



    at Container->call(array(object(RollbarLumenServiceProvider), 'boot'))
    in Application.php line 237



    at Application->bootProvider(object(RollbarLumenServiceProvider))
    in Application.php line 222



    at Application->LaravelLumen{closure}(object(RollbarLumenServiceProvider), 'AppProvidersRollbarLumenServiceProvider')



    It's at this point that I get stuck. Does anyone know how to fix this error? I am not a service container or rollbar wiz and will appreciate any help. Hopefully, this will serve as a nice community way to get Rollbar working with Lumen 5.7!










    share|improve this question

























      2












      2








      2


      1






      So, currently the two most popular (IMHO) rollbar packages for Lumen (not Laravel) are:





      • https://github.com/rollbar/rollbar-php-laravel, and

      • https://github.com/jenssegers/laravel-rollbar


      Given that https://github.com/jenssegers/laravel-rollbar explicitly states attempts to add Lumen support for 5.x and given that there is this wonderful tutorial by James Elliot on adding Rollbar to Lumen 5.2, I attempted to update the code for his tutorial and use it for Lumen 5.7.



      The bulk of his work is in his RollbarLumenServiceProvider which looks like this:



      namespace AppProviders;

      use JenssegersRollbarRollbarLogHandler;
      use IlluminateSupportServiceProvider;
      use InvalidArgumentException;
      use MonologHandlerRollbarHandler;
      use Rollbar;
      use RollbarNotifier;

      class RollbarLumenServiceProvider extends ServiceProvider
      {
      /**
      * Indicates if loading of the provider is deferred.
      *
      * @var bool
      */
      protected $defer = false;

      /**
      * Register the service provider.
      */
      public function register()
      {
      $this->app->configure('rollbar');

      // Don't register rollbar if it is not configured.
      if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('rollbar')) {
      return;
      }

      $app = $this->app;

      $app[RollbarNotifier::class] = $app->share(function ($app) {

      // Default configuration.
      $defaults = [
      'environment' => $app->environment(),
      'root' => base_path(),
      ];

      $config = array_merge($defaults, $app['config']->get('services.rollbar', ));

      $config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

      if (empty($config['access_token'])) {
      throw new InvalidArgumentException('Rollbar access token not configured');
      }

      Rollbar::$instance = $rollbar = new RollbarNotifier($config);

      return $rollbar;
      });

      $app[RollbarLogHandler::class] = $app->share(function ($app) {
      $level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

      $handler = app(RollbarHandler::class, [$this->app[RollbarNotifier::class], $level]);

      return $handler;
      });

      // Register the fatal error handler.
      register_shutdown_function(function () use ($app) {
      if (isset($app[Rollbar::class])) {
      $app->make(Rollbar::class);
      Rollbar::report_fatal_error();
      }
      });

      // If the Rollbar client was resolved, then there is a possibility that there
      // are unsent error messages in the internal queue, so let's flush them.
      register_shutdown_function(function () use ($app) {
      if (isset($app[Rollbar::class])) {
      $app[Rollbar::class]->flush();
      }
      });
      }

      public function boot()
      {
      $app = $this->app;

      // Listen to log messages.
      $app['log']->pushHandler(
      app(RollbarLogHandler::class, [
      $this->app[Rollbar::class]
      ])
      );
      }

      public function provides()
      {
      return [
      RollbarLogHandler::class
      ];
      }
      }


      My attempt at updating this for Lumen 5.7 accounting for deprecation and breaking changes looks like this:



      <?php
      namespace AppProviders;

      use JenssegersRollbarRollbarLogHandler;
      use IlluminateSupportServiceProvider;
      use InvalidArgumentException;
      use MonologHandlerRollbarHandler;
      use Rollbar;
      use RollbarNotifier;

      class RollbarLumenServiceProvider extends ServiceProvider
      {
      /**
      * Indicates if loading of the provider is deferred.
      *
      * @var bool
      */
      protected $defer = false;

      private function getApp($app): LaravelLumenApplication
      {
      return $app;
      }

      /**
      * Register the service provider.
      */
      public function register()
      {
      $app = $this->getApp($this->app);

      $app->configure('rollbar');

      // Don't register rollbar if it is not configured.
      if (!getenv('ROLLBAR_TOKEN') and !$app['config']->get('rollbar')) {
      return;
      }


      $app->singleton(RollbarNotifier::class, function (LaravelLumenApplication $app)
      {
      // Default configuration.
      $defaults = [
      'environment' => $app->environment(),
      'root' => base_path(),
      ];

      $config = array_merge($defaults, $app['config']->get('services.rollbar', ));

      $config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

      if (empty($config['access_token'])) {
      throw new InvalidArgumentException('Rollbar access token not configured');
      }

      Rollbar::$instance = $rollbar = new RollbarNotifier($config);

      return $rollbar;
      });

      $app->singleton(RollbarHandler::class, function (LaravelLumenApplication $app)
      {
      $level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

      //$handler = app(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);
      $handler = $app->makeWith(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);

      return $handler;
      });

      // Register the fatal error handler.
      register_shutdown_function(function () use ($app)
      {
      if (isset($app[Rollbar::class]))
      {
      $app->make(Rollbar::class);
      Rollbar::report_fatal_error();
      }
      });

      // If the Rollbar client was resolved, then there is a possibility that there
      // are unsent error messages in the internal queue, so let's flush them.
      register_shutdown_function(function () use ($app)
      {
      if (isset($app[Rollbar::class])) {
      $app[Rollbar::class]->flush();
      }
      });
      }

      public function boot()
      {
      $app = $this->app;

      // Listen to log messages.
      $app['log']->pushHandler(
      $app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
      );
      }

      public function provides()
      {
      return [
      RollbarLogHandler::class
      ];
      }
      }


      I think it ALMOST works. I get an exception in this method:



          public function boot()
      {
      $app = $this->app;

      // Listen to log messages.
      $app['log']->pushHandler(
      $app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
      );
      }


      Here is the Exception trace:



      (1/1) ReflectionException
      Class IlluminateFoundationApplication does not exist
      in Container.php line 838



      at ReflectionParameter->getClass()
      in Container.php line 838



      at Container->resolveDependencies(array(object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter)))
      in Container.php line 807



      at Container->build('JenssegersRollbarRollbarLogHandler')
      in Container.php line 658



      at Container->resolve('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in Container.php line 609



      at Container->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in Application.php line 260



      at Application->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in Container.php line 597



      at Container->makeWith('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in RollbarLumenServiceProvider.php line 104



      at RollbarLumenServiceProvider->boot()
      at call_user_func_array(array(object(RollbarLumenServiceProvider), 'boot'), array())
      in BoundMethod.php line 29



      at BoundMethod::IlluminateContainer{closure}()
      in BoundMethod.php line 87



      at BoundMethod::callBoundMethod(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), object(Closure))
      in BoundMethod.php line 31



      at BoundMethod::call(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), array(), null)
      in Container.php line 572



      at Container->call(array(object(RollbarLumenServiceProvider), 'boot'))
      in Application.php line 237



      at Application->bootProvider(object(RollbarLumenServiceProvider))
      in Application.php line 222



      at Application->LaravelLumen{closure}(object(RollbarLumenServiceProvider), 'AppProvidersRollbarLumenServiceProvider')



      It's at this point that I get stuck. Does anyone know how to fix this error? I am not a service container or rollbar wiz and will appreciate any help. Hopefully, this will serve as a nice community way to get Rollbar working with Lumen 5.7!










      share|improve this question














      So, currently the two most popular (IMHO) rollbar packages for Lumen (not Laravel) are:





      • https://github.com/rollbar/rollbar-php-laravel, and

      • https://github.com/jenssegers/laravel-rollbar


      Given that https://github.com/jenssegers/laravel-rollbar explicitly states attempts to add Lumen support for 5.x and given that there is this wonderful tutorial by James Elliot on adding Rollbar to Lumen 5.2, I attempted to update the code for his tutorial and use it for Lumen 5.7.



      The bulk of his work is in his RollbarLumenServiceProvider which looks like this:



      namespace AppProviders;

      use JenssegersRollbarRollbarLogHandler;
      use IlluminateSupportServiceProvider;
      use InvalidArgumentException;
      use MonologHandlerRollbarHandler;
      use Rollbar;
      use RollbarNotifier;

      class RollbarLumenServiceProvider extends ServiceProvider
      {
      /**
      * Indicates if loading of the provider is deferred.
      *
      * @var bool
      */
      protected $defer = false;

      /**
      * Register the service provider.
      */
      public function register()
      {
      $this->app->configure('rollbar');

      // Don't register rollbar if it is not configured.
      if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('rollbar')) {
      return;
      }

      $app = $this->app;

      $app[RollbarNotifier::class] = $app->share(function ($app) {

      // Default configuration.
      $defaults = [
      'environment' => $app->environment(),
      'root' => base_path(),
      ];

      $config = array_merge($defaults, $app['config']->get('services.rollbar', ));

      $config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

      if (empty($config['access_token'])) {
      throw new InvalidArgumentException('Rollbar access token not configured');
      }

      Rollbar::$instance = $rollbar = new RollbarNotifier($config);

      return $rollbar;
      });

      $app[RollbarLogHandler::class] = $app->share(function ($app) {
      $level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

      $handler = app(RollbarHandler::class, [$this->app[RollbarNotifier::class], $level]);

      return $handler;
      });

      // Register the fatal error handler.
      register_shutdown_function(function () use ($app) {
      if (isset($app[Rollbar::class])) {
      $app->make(Rollbar::class);
      Rollbar::report_fatal_error();
      }
      });

      // If the Rollbar client was resolved, then there is a possibility that there
      // are unsent error messages in the internal queue, so let's flush them.
      register_shutdown_function(function () use ($app) {
      if (isset($app[Rollbar::class])) {
      $app[Rollbar::class]->flush();
      }
      });
      }

      public function boot()
      {
      $app = $this->app;

      // Listen to log messages.
      $app['log']->pushHandler(
      app(RollbarLogHandler::class, [
      $this->app[Rollbar::class]
      ])
      );
      }

      public function provides()
      {
      return [
      RollbarLogHandler::class
      ];
      }
      }


      My attempt at updating this for Lumen 5.7 accounting for deprecation and breaking changes looks like this:



      <?php
      namespace AppProviders;

      use JenssegersRollbarRollbarLogHandler;
      use IlluminateSupportServiceProvider;
      use InvalidArgumentException;
      use MonologHandlerRollbarHandler;
      use Rollbar;
      use RollbarNotifier;

      class RollbarLumenServiceProvider extends ServiceProvider
      {
      /**
      * Indicates if loading of the provider is deferred.
      *
      * @var bool
      */
      protected $defer = false;

      private function getApp($app): LaravelLumenApplication
      {
      return $app;
      }

      /**
      * Register the service provider.
      */
      public function register()
      {
      $app = $this->getApp($this->app);

      $app->configure('rollbar');

      // Don't register rollbar if it is not configured.
      if (!getenv('ROLLBAR_TOKEN') and !$app['config']->get('rollbar')) {
      return;
      }


      $app->singleton(RollbarNotifier::class, function (LaravelLumenApplication $app)
      {
      // Default configuration.
      $defaults = [
      'environment' => $app->environment(),
      'root' => base_path(),
      ];

      $config = array_merge($defaults, $app['config']->get('services.rollbar', ));

      $config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');

      if (empty($config['access_token'])) {
      throw new InvalidArgumentException('Rollbar access token not configured');
      }

      Rollbar::$instance = $rollbar = new RollbarNotifier($config);

      return $rollbar;
      });

      $app->singleton(RollbarHandler::class, function (LaravelLumenApplication $app)
      {
      $level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

      //$handler = app(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);
      $handler = $app->makeWith(RollbarHandler::class, [$app[RollbarNotifier::class], $level]);

      return $handler;
      });

      // Register the fatal error handler.
      register_shutdown_function(function () use ($app)
      {
      if (isset($app[Rollbar::class]))
      {
      $app->make(Rollbar::class);
      Rollbar::report_fatal_error();
      }
      });

      // If the Rollbar client was resolved, then there is a possibility that there
      // are unsent error messages in the internal queue, so let's flush them.
      register_shutdown_function(function () use ($app)
      {
      if (isset($app[Rollbar::class])) {
      $app[Rollbar::class]->flush();
      }
      });
      }

      public function boot()
      {
      $app = $this->app;

      // Listen to log messages.
      $app['log']->pushHandler(
      $app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
      );
      }

      public function provides()
      {
      return [
      RollbarLogHandler::class
      ];
      }
      }


      I think it ALMOST works. I get an exception in this method:



          public function boot()
      {
      $app = $this->app;

      // Listen to log messages.
      $app['log']->pushHandler(
      $app->makeWith(RollbarLogHandler::class, [$app[Rollbar::class]])
      );
      }


      Here is the Exception trace:



      (1/1) ReflectionException
      Class IlluminateFoundationApplication does not exist
      in Container.php line 838



      at ReflectionParameter->getClass()
      in Container.php line 838



      at Container->resolveDependencies(array(object(ReflectionParameter), object(ReflectionParameter), object(ReflectionParameter)))
      in Container.php line 807



      at Container->build('JenssegersRollbarRollbarLogHandler')
      in Container.php line 658



      at Container->resolve('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in Container.php line 609



      at Container->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in Application.php line 260



      at Application->make('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in Container.php line 597



      at Container->makeWith('JenssegersRollbarRollbarLogHandler', array(object(Rollbar)))
      in RollbarLumenServiceProvider.php line 104



      at RollbarLumenServiceProvider->boot()
      at call_user_func_array(array(object(RollbarLumenServiceProvider), 'boot'), array())
      in BoundMethod.php line 29



      at BoundMethod::IlluminateContainer{closure}()
      in BoundMethod.php line 87



      at BoundMethod::callBoundMethod(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), object(Closure))
      in BoundMethod.php line 31



      at BoundMethod::call(object(Application), array(object(RollbarLumenServiceProvider), 'boot'), array(), null)
      in Container.php line 572



      at Container->call(array(object(RollbarLumenServiceProvider), 'boot'))
      in Application.php line 237



      at Application->bootProvider(object(RollbarLumenServiceProvider))
      in Application.php line 222



      at Application->LaravelLumen{closure}(object(RollbarLumenServiceProvider), 'AppProvidersRollbarLumenServiceProvider')



      It's at this point that I get stuck. Does anyone know how to fix this error? I am not a service container or rollbar wiz and will appreciate any help. Hopefully, this will serve as a nice community way to get Rollbar working with Lumen 5.7!







      lumen rollbar






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 20:17









      Chukky NzeChukky Nze

      519210




      519210
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I came across this question when facing the same problem. Since there were no answer I decided to give it a go myself.



          I wrote an article about it with my solution.



          http://troccoli.it/rollbar-in-lumen/



          In short, get rollbar



          composer require rollbar/rollbar


          Add the rollbar channel to your config/logging.php



          <?php

          return [
          'default' => env('LOG_CHANNEL', 'stack'),

          'channels' => [
          'stack' => [
          'driver' => 'stack',
          'channels' => ['rollbar'],
          ],
          'rollbar' => [
          'driver' => 'monolog',
          'handler' => RollbarMonologHandlerRollbarHandler::class,
          'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
          'level' => 'debug',
          ],
          ],
          ];


          Write a service provider RollbarServiceProvider.php



          <?php

          namespace AppProviders;

          use IlluminateContractsConfigRepository;
          use IlluminateSupportServiceProvider;
          use RollbarRollbarLogger;
          use RollbarRollbar;

          class RollbarServiceProvider extends ServiceProvider
          {
          public function register()
          {
          $this->app->singleton(RollbarLogger::class, function () {
          $config = $this->app->make(Repository::class);

          $defaults = [
          'environment' => app()->environment(),
          'root' => base_path(),
          'handle_exception' => true,
          'handle_error' => true,
          'handle_fatal' => true,
          ];

          $rollbarConfig = array_merge($defaults, $config->get('logging.channels.rollbar', ));

          $handleException = (bool)array_pull($rollbarConfig, 'handle_exception');
          $handleError = (bool)array_pull($rollbarConfig, 'handle_error');
          $handleFatal = (bool)array_pull($rollbarConfig, 'handle_fatal');

          Rollbar::init($rollbarConfig, $handleException, $handleError, $handleFatal);

          return Rollbar::logger();
          });
          }
          }


          Add the post_server_item- token (you can get this from your rollbar account) into the.env` file



          ROLLBAR_ACCESS_TOKEN=ROLLBAR_POST_SERVER_ITEM_TOKEN


          and finally link all this together in bootstrap/app.php



          $app->register(AppProvidersRollbarServiceProvider::class);
          $app->configure('logging');





          share|improve this answer


























          • You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

            – Chukky Nze
            Dec 10 '18 at 18:52











          • Thanks @ChukkyNze. Done.

            – giuliot
            Dec 12 '18 at 10:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419870%2fusing-rollbar-with-lumen-5-7%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I came across this question when facing the same problem. Since there were no answer I decided to give it a go myself.



          I wrote an article about it with my solution.



          http://troccoli.it/rollbar-in-lumen/



          In short, get rollbar



          composer require rollbar/rollbar


          Add the rollbar channel to your config/logging.php



          <?php

          return [
          'default' => env('LOG_CHANNEL', 'stack'),

          'channels' => [
          'stack' => [
          'driver' => 'stack',
          'channels' => ['rollbar'],
          ],
          'rollbar' => [
          'driver' => 'monolog',
          'handler' => RollbarMonologHandlerRollbarHandler::class,
          'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
          'level' => 'debug',
          ],
          ],
          ];


          Write a service provider RollbarServiceProvider.php



          <?php

          namespace AppProviders;

          use IlluminateContractsConfigRepository;
          use IlluminateSupportServiceProvider;
          use RollbarRollbarLogger;
          use RollbarRollbar;

          class RollbarServiceProvider extends ServiceProvider
          {
          public function register()
          {
          $this->app->singleton(RollbarLogger::class, function () {
          $config = $this->app->make(Repository::class);

          $defaults = [
          'environment' => app()->environment(),
          'root' => base_path(),
          'handle_exception' => true,
          'handle_error' => true,
          'handle_fatal' => true,
          ];

          $rollbarConfig = array_merge($defaults, $config->get('logging.channels.rollbar', ));

          $handleException = (bool)array_pull($rollbarConfig, 'handle_exception');
          $handleError = (bool)array_pull($rollbarConfig, 'handle_error');
          $handleFatal = (bool)array_pull($rollbarConfig, 'handle_fatal');

          Rollbar::init($rollbarConfig, $handleException, $handleError, $handleFatal);

          return Rollbar::logger();
          });
          }
          }


          Add the post_server_item- token (you can get this from your rollbar account) into the.env` file



          ROLLBAR_ACCESS_TOKEN=ROLLBAR_POST_SERVER_ITEM_TOKEN


          and finally link all this together in bootstrap/app.php



          $app->register(AppProvidersRollbarServiceProvider::class);
          $app->configure('logging');





          share|improve this answer


























          • You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

            – Chukky Nze
            Dec 10 '18 at 18:52











          • Thanks @ChukkyNze. Done.

            – giuliot
            Dec 12 '18 at 10:02
















          0














          I came across this question when facing the same problem. Since there were no answer I decided to give it a go myself.



          I wrote an article about it with my solution.



          http://troccoli.it/rollbar-in-lumen/



          In short, get rollbar



          composer require rollbar/rollbar


          Add the rollbar channel to your config/logging.php



          <?php

          return [
          'default' => env('LOG_CHANNEL', 'stack'),

          'channels' => [
          'stack' => [
          'driver' => 'stack',
          'channels' => ['rollbar'],
          ],
          'rollbar' => [
          'driver' => 'monolog',
          'handler' => RollbarMonologHandlerRollbarHandler::class,
          'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
          'level' => 'debug',
          ],
          ],
          ];


          Write a service provider RollbarServiceProvider.php



          <?php

          namespace AppProviders;

          use IlluminateContractsConfigRepository;
          use IlluminateSupportServiceProvider;
          use RollbarRollbarLogger;
          use RollbarRollbar;

          class RollbarServiceProvider extends ServiceProvider
          {
          public function register()
          {
          $this->app->singleton(RollbarLogger::class, function () {
          $config = $this->app->make(Repository::class);

          $defaults = [
          'environment' => app()->environment(),
          'root' => base_path(),
          'handle_exception' => true,
          'handle_error' => true,
          'handle_fatal' => true,
          ];

          $rollbarConfig = array_merge($defaults, $config->get('logging.channels.rollbar', ));

          $handleException = (bool)array_pull($rollbarConfig, 'handle_exception');
          $handleError = (bool)array_pull($rollbarConfig, 'handle_error');
          $handleFatal = (bool)array_pull($rollbarConfig, 'handle_fatal');

          Rollbar::init($rollbarConfig, $handleException, $handleError, $handleFatal);

          return Rollbar::logger();
          });
          }
          }


          Add the post_server_item- token (you can get this from your rollbar account) into the.env` file



          ROLLBAR_ACCESS_TOKEN=ROLLBAR_POST_SERVER_ITEM_TOKEN


          and finally link all this together in bootstrap/app.php



          $app->register(AppProvidersRollbarServiceProvider::class);
          $app->configure('logging');





          share|improve this answer


























          • You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

            – Chukky Nze
            Dec 10 '18 at 18:52











          • Thanks @ChukkyNze. Done.

            – giuliot
            Dec 12 '18 at 10:02














          0












          0








          0







          I came across this question when facing the same problem. Since there were no answer I decided to give it a go myself.



          I wrote an article about it with my solution.



          http://troccoli.it/rollbar-in-lumen/



          In short, get rollbar



          composer require rollbar/rollbar


          Add the rollbar channel to your config/logging.php



          <?php

          return [
          'default' => env('LOG_CHANNEL', 'stack'),

          'channels' => [
          'stack' => [
          'driver' => 'stack',
          'channels' => ['rollbar'],
          ],
          'rollbar' => [
          'driver' => 'monolog',
          'handler' => RollbarMonologHandlerRollbarHandler::class,
          'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
          'level' => 'debug',
          ],
          ],
          ];


          Write a service provider RollbarServiceProvider.php



          <?php

          namespace AppProviders;

          use IlluminateContractsConfigRepository;
          use IlluminateSupportServiceProvider;
          use RollbarRollbarLogger;
          use RollbarRollbar;

          class RollbarServiceProvider extends ServiceProvider
          {
          public function register()
          {
          $this->app->singleton(RollbarLogger::class, function () {
          $config = $this->app->make(Repository::class);

          $defaults = [
          'environment' => app()->environment(),
          'root' => base_path(),
          'handle_exception' => true,
          'handle_error' => true,
          'handle_fatal' => true,
          ];

          $rollbarConfig = array_merge($defaults, $config->get('logging.channels.rollbar', ));

          $handleException = (bool)array_pull($rollbarConfig, 'handle_exception');
          $handleError = (bool)array_pull($rollbarConfig, 'handle_error');
          $handleFatal = (bool)array_pull($rollbarConfig, 'handle_fatal');

          Rollbar::init($rollbarConfig, $handleException, $handleError, $handleFatal);

          return Rollbar::logger();
          });
          }
          }


          Add the post_server_item- token (you can get this from your rollbar account) into the.env` file



          ROLLBAR_ACCESS_TOKEN=ROLLBAR_POST_SERVER_ITEM_TOKEN


          and finally link all this together in bootstrap/app.php



          $app->register(AppProvidersRollbarServiceProvider::class);
          $app->configure('logging');





          share|improve this answer















          I came across this question when facing the same problem. Since there were no answer I decided to give it a go myself.



          I wrote an article about it with my solution.



          http://troccoli.it/rollbar-in-lumen/



          In short, get rollbar



          composer require rollbar/rollbar


          Add the rollbar channel to your config/logging.php



          <?php

          return [
          'default' => env('LOG_CHANNEL', 'stack'),

          'channels' => [
          'stack' => [
          'driver' => 'stack',
          'channels' => ['rollbar'],
          ],
          'rollbar' => [
          'driver' => 'monolog',
          'handler' => RollbarMonologHandlerRollbarHandler::class,
          'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
          'level' => 'debug',
          ],
          ],
          ];


          Write a service provider RollbarServiceProvider.php



          <?php

          namespace AppProviders;

          use IlluminateContractsConfigRepository;
          use IlluminateSupportServiceProvider;
          use RollbarRollbarLogger;
          use RollbarRollbar;

          class RollbarServiceProvider extends ServiceProvider
          {
          public function register()
          {
          $this->app->singleton(RollbarLogger::class, function () {
          $config = $this->app->make(Repository::class);

          $defaults = [
          'environment' => app()->environment(),
          'root' => base_path(),
          'handle_exception' => true,
          'handle_error' => true,
          'handle_fatal' => true,
          ];

          $rollbarConfig = array_merge($defaults, $config->get('logging.channels.rollbar', ));

          $handleException = (bool)array_pull($rollbarConfig, 'handle_exception');
          $handleError = (bool)array_pull($rollbarConfig, 'handle_error');
          $handleFatal = (bool)array_pull($rollbarConfig, 'handle_fatal');

          Rollbar::init($rollbarConfig, $handleException, $handleError, $handleFatal);

          return Rollbar::logger();
          });
          }
          }


          Add the post_server_item- token (you can get this from your rollbar account) into the.env` file



          ROLLBAR_ACCESS_TOKEN=ROLLBAR_POST_SERVER_ITEM_TOKEN


          and finally link all this together in bootstrap/app.php



          $app->register(AppProvidersRollbarServiceProvider::class);
          $app->configure('logging');






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 12 '18 at 12:08

























          answered Dec 8 '18 at 9:34









          giuliotgiuliot

          7111




          7111













          • You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

            – Chukky Nze
            Dec 10 '18 at 18:52











          • Thanks @ChukkyNze. Done.

            – giuliot
            Dec 12 '18 at 10:02



















          • You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

            – Chukky Nze
            Dec 10 '18 at 18:52











          • Thanks @ChukkyNze. Done.

            – giuliot
            Dec 12 '18 at 10:02

















          You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

          – Chukky Nze
          Dec 10 '18 at 18:52





          You might want to flesh out your answer to include the steps to make it work (which it did). Stack isn't friendly to "answers" that point to external articles and I don't want to do it for you and take the credit you deserve.

          – Chukky Nze
          Dec 10 '18 at 18:52













          Thanks @ChukkyNze. Done.

          – giuliot
          Dec 12 '18 at 10:02





          Thanks @ChukkyNze. Done.

          – giuliot
          Dec 12 '18 at 10:02




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419870%2fusing-rollbar-with-lumen-5-7%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?