Code Monkey home page Code Monkey logo

laravel-stackdriver's Introduction

Laravel Stackdriver

Latest Version on Packagist Total Downloads

Enables logging, tracing and error reporting to Google Stackdriver for Laravel. Requires PHP >= 7.1

Screenshots

Tracing Error reporting

Installation

Via Composer

composer require gluedev/laravel-stackdriver

And publish the config file

php artisan vendor:publish --provider="GlueDev\Laravel\Stackdriver\StackdriverServiceProvider"

Usage

First, you will want to open config/stackdriver.php. Here you can see that you have four environment settings available to enable and disable the different features of this package:

STACKDRIVER_ENABLED=false  
STACKDRIVER_LOGGING_ENABLED=true  
STACKDRIVER_TRACING_ENABLED=true
STACKDRIVER_ERROR_REPORTING_ENABLED=true

The first variable listed has priority over the others.

Authentication

At the time of writing, Google prefers you to authenticate using a service account. It will throw a warning otherwise, which you can (but probably should not) disable by setting SUPPRESS_GCLOUD_CREDS_WARNING=true

Create a service account with the appropriate roles attached to it and add it to your project. Make sure not to commit this file to git, because of security. You can then specify the path to the service account JSON file in the keyFilePath or in the STACKDRIVER_KEY_FILE_PATH environment variable.

Tracing

Tracing requires the OpenCencus module to be installed. As we use docker, this is how we install it:

RUN pecl install opencensus-alpha
RUN docker-php-ext-enable opencensus

Please note: If you run in to an opencensus.so: undefined symbol: ZVAL_DESTRUCTOR error after installing the OpenCencus extension, it is recommended to build the extension yourself, following these instructions.

Logging

Other than changing the values in the config file, logging needs no additional setup.

Error reporting

Error reporting requires you to add the following to the report function in your Exceptions/handler.php

use GlueDev\Laravel\Stackdriver\StackdriverExceptionHandler;

/**  
 * Report or log an exception.
 *
 * @param \Exception  $exception  
 * @return void  
 */
public function report(Exception $exception)  
{  
    StackdriverExceptionHandler::report($exception);  
    parent::report($exception);  
}

Log in to Google Cloud Console and you should start seeing logs, traces and errors appear.

Batch daemon

Google also provides a batch daemon, which is recommended to use. We have seen issues with slow time to first byte on requests when the daemon was not running. The easiest way to run the daemon is using Supervisor. An example configuration for you to edit:

[program:google-batch-daemon]
command = php -d auto_prepend_file='' -d disable_functions='' /app/vendor/bin/google-cloud-batch daemon
process_name = %(program_name)s
user = application
numprocs = 1
autostart = true
autorestart = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0

You also need to tell Google that the daemon is running. This is done by setting the IS_BATCH_DAEMON_RUNNING=true.

And that is it!

Change log

Please see the changelog for more information on what has changed recently.

Credits

License

Please see the license file for more information.

laravel-stackdriver's People

Contributors

diederikvandenb avatar ni-bschmitt avatar ibrunotome avatar jangidgirish avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.