Giter Site home page Giter Site logo

app-enlight-php-client's Introduction

App Enlight PHP Client

IMPORTANT: This library is under development. You can use it for productive application on your own risk!

PHP Client for AppEnlight (previously known as Errormator).

App Enlight main goal is to monitor your application. This API client for PHP provides an easy to use interface to send to App Enlight:

  • logs;
  • error reports;
  • slow requests (with metrics).

Requirements

Installation

To install this API in your application copy all folders to a location accessible by your application. Then whenever you want to use the App Enlight PHP client you should use the namespace:

use AppEnlight;

Framework integrations

You can use this PHP client in any PHP application but it will require from you a little effort to integrate the client with your application. If you are using Yii frameworkyou are really lucky guy :) This PHP client is delivered with extension allowing to use client within Yii Framework with minimal effort. If you like to add support for other frameworks, please feel free to contact me.

Pass your application API key

The most important, before you initialize client, is to pass your private API key generated in App Enlight dashboard for your application. If you like, you can set the other settings to according to your needs. Note that you can ommit other settings and client will still work. Below example shows all available settings

    $settings = new \AppEnlight\Settings();
    $settings->setApiKey('123APIKEY');
    $settings->setClient('php');
    $settings->setScheme('https');
    $settings->setUrl('api.appenlight.com/api');
    $settings->setVersion('0.5');
    return $settings;

Create client

Once settings are defined, you can pass them to client.

$client = new \AppEnlight\Client($settings);

Send log data

Once the client is created you need to decide what kind of information you would like to send. You can choose from two endpoints:

  • log,
  • reports.

First is very simple and is used to store logs comming from your application.

    use \AppEnlight\Endpoint\Logs;
    use \AppEnlight\Endpoint\Data\Log;

    $uuid = $client->getUUID();

    /* add just 1 log */
    $aeLog = new Log();
    $aeLog->setMessage("Test message");
    $aeLog->setLogLevel('error');
    $aeLog->setNamespace('application.site.signin');
    $aeLog->setDate('2014-07-21T00:15:38.955371');
    $aeLog->setRequestId($uuid);
    $aeLog->setServer('localhost');
    $client->addLog($aeLog);
    $client->setEndpoint($aeLogs);

Send repot data

You can send multiple reports within one request. Each report may consist different set of data. You can send information about slow calls including traceback, error information, etc.

Below example shows how to send simple report

    use \AppEnlight;
    use \AppEnlight\Endpoint;
    use \AppEnlight\Endpoint\Data;
    use \AppEnlight\Endpoint\Data\Report;
    
    //get client
    $client = new Client($settings);

    //prepare report detail data 
    $report = new Report();
    $report->setUsername('test user');
    $report->setUrl('http://localhost');
    $report->setIp('127.0.0.1');
    $report->setUserAgent('Chrome');
    $report->setMessage('Very serious error');
    $report->setRequestId($client->getUUID());
    $report->setRequestStats(new RequestStats());
    
    //analyse trace returned by exception
    $trace = $exception->getTrace();
    foreach($trace as $t) {
      $aeTrace = new Traceback();
      $aeTrace->setFile(isset($t['file']) ? $t['file'] : 'unknown');
      $aeTrace->setFn(isset($t['class']) ? "{$t['class']}->{$t['function']}" : $t['function']);
      $aeTrace->setLine(isset($t['line']) ? $t['line'] : 0);
      $reportDetail->addTraceback($aeTrace);
    }
    
    $report->setRequest(new Request(););
  
    $report->setError('Very dangerouse error');
    $report->setHttpStatus(500);

    $client->addReport($report);
    $client->send();

Update from version 0.4 to 0.5

Note that API in version 0.5 has been changed comparing to version 0.4. Briefly, report grouping has been changed and since version 0.5 content of report_details became part of single report. For more details compare documentation Reports endpoint for version 0.4 with 0.5

Todo

  • add documentation how to use extension in Yii;

app-enlight-php-client's People

Contributors

aztechowski avatar ergo 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.