GithubHelp home page GithubHelp logo

jkrcma / raven-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getsentry/sentry-php

0.0 2.0 0.0 387 KB

Raven is a PHP client for Sentry (getsentry.com)

Home Page: https://www.getsentry.com

License: BSD 3-Clause "New" or "Revised" License

raven-php's Introduction

raven-php

https://secure.travis-ci.org/getsentry/raven-php.png?branch=master

raven-php is a PHP client for Sentry.

// Instantiate a new client with a compatible DSN
$client = new Raven_Client('http://public:[email protected]/1');

// Capture a message
$event_id = $client->getIdent($client->captureMessage('my log message'));

// Capture an exception
$event_id = $client->getIdent($client->captureException($ex));

// Provide some additional data with an exception
$event_id = $client->getIdent($client->captureException($ex, array(
    'extra' => array(
        'php_version' => phpversion()
    ),
)));

// Give the user feedback
echo "Sorry, there was an error!";
echo "Your reference ID is " . $event_id;

// Install error handlers and shutdown function to catch fatal errors
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
$error_handler->registerShutdownFunction();

Installation

Install with Composer

If you're using Composer to manage dependencies, you can add Raven with it.

{
    "require": {
        "raven/raven": "$VERSION"
    }
}

(replace $VERSION with one of the available versions on Packagist) or to get the latest version off the master branch:

{
    "require": {
        "raven/raven": "dev-master"
    }
}

Note that using unstable versions is not recommended and should be avoided. Also you should define a maximum version, e.g. by doing >=0.6,<1.0 or ~0.6.

Composer will take care of the autoloading for you, so if you require the vendor/autoload.php, you're good to go.

Install source from GitHub

To install the source code:

$ git clone git://github.com/getsentry/raven-php.git

And including it using the autoloader:

require_once '/path/to/Raven/library/Raven/Autoloader.php';
Raven_Autoloader::register();

Configuration

Several options exist that allow you to configure the behavior of the Raven_Client. These are passed as the second parameter of the constructor, and is expected to be an array of key value pairs:

$client = new Raven_Client($dsn, array(
    'option_name' => 'value',
));

name

A string to override the default value for the server's hostname.

Defaults to Raven_Compat::gethostname().

tags

An array of tags to apply to events in this context.

'tags' => array(
    'php_version' => phpversion(),
)

trace

Set this to false to disable reflection tracing (function calling arguments) in stacktraces.

logger

Adjust the default logger name for messages.

Defaults to php.

Providing Request Context

Most of the time you're not actually calling out to Raven directly, but you still want to provide some additional context. This lifecycle generally constists of something like the following:

  • Set some context via a middleware (e.g. the logged in user)
  • Send all given context with any events during the request lifecycle
  • Cleanup context

There are three primary methods for providing request context:

// bind the logged in user
$client->user_context(array('email' => '[email protected]'));

// tag the request with something interesting
$client->tags_context(array('interesting' => 'yes'));

// provide a bit of additional context
$client->extra_context(array('happiness' => 'very'));

If you're performing additional requests during the lifecycle, you'll also need to ensure you cleanup the context (to reset its state):

$client->context->clear();

Contributing

First, make sure you can run the test suite. Install development dependencies :

$ composer install

You may now use phpunit :

$ bin/phpunit

Resources

raven-php's People

Contributors

abhinavlal avatar arthens avatar asuth avatar captainjojo avatar datashaman avatar dcramer avatar dknecht avatar eduardosoliv avatar fabpot avatar gromnan avatar jeromemacias avatar jonathano avatar jturmel avatar ktx avatar llange avatar m8rge avatar madssj avatar mgrinko avatar msabramo avatar mvantellingen avatar nyholm avatar pborreli avatar rbas avatar scragg0x avatar siwinski avatar strayer avatar superdav42 avatar thedamon avatar thomasbachem avatar viperfx avatar

Watchers

 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.