GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - codex-team/hawk.php: PHP Errors catching and monitoring

BranchesTags
Open more actions menu

Latest commit

 

History

280 Commits
280 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
images
images
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.php-cs-fixer.php
.php-cs-fixer.php
 
 
CODEOWNERS
CODEOWNERS
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
example.php
example.php
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

Hawk PHP

PHP errors Catcher for Hawk.so.

Setup

  1. Register an account, create a Project and get an Integration Token.

  2. Install SDK via composer to install the Catcher

Catcher provides support for PHP 7.2 or later

$ composer require codex-team/hawk.php

Configuration

\Hawk\Catcher::init([
    'integrationToken' => 'your integration token'
]);

Passing custom Transport

The default transport requires the ext-curl PHP extension. If ext-curl is unavailable, provide a custom transport via the transport option.

You can also provide your own transport by implementing TransportInterface. Custom transports own their endpoint and timeout configuration, so the url and timeout options are used only by the default transport.

For example, install a PHP-version-compatible Guzzle release in your application and wrap it with a custom transport:

use Hawk\Event;
use Hawk\Options;
use Hawk\Transport\TransportInterface;

class CustomGuzzleTransport implements TransportInterface
{
    private $url;
    private $client;

    public function __construct(string $url = Options::DEFAULT_URL)
    {
        $this->url = $url;
        $this->client = new \GuzzleHttp\Client();
    }

    public function getUrl(): string
    {
        return $this->url;
    }

    public function send(Event $event)
    {
        $this->client->request('POST', $this->url, [
            'headers' => [
                'Content-Type' => 'application/json',
            ],
            'body' => json_encode($event, JSON_UNESCAPED_UNICODE),
        ]);
    }
}

\Hawk\Catcher::init([
    'integrationToken' => 'your integration token',
    'transport' => new CustomGuzzleTransport(),
]);

Passing User and Context

After initialization you can set user or context for any event that will be send to Hawk

\Hawk\Catcher::get()
    ->setUser([
        'name' => 'user name',
        'photo' => 'user photo',
    ])
    ->setContext([
        ...
    ]);

Send events and exceptions manually

Use sendException method to send any caught exception

try {
    throw new Exception("Error Processing Request", 1);
} catch (Exception $e) {
    \Hawk\Catcher::get()->sendException($e);
}

Use sendEvent method to send any data (logs, notices or something else)

\Hawk\Catcher::get()->sendMessage('your message', [
    ... // Context
]);

Filtering sensitive information

Use the beforeSend hook to filter any data you don't want to send to Hawk. Use setters to clear any property.

\Hawk\Catcher::init([
    // ...
    'beforeSend' => function (\Hawk\EventPayload $eventPayload) {
        $user = $eventPayload->getUser();
        
        if (!empty($user['email'])){
            unset($user['email']);
        
            $eventPayload->setUser($user);
        }

        return $eventPayload;
    }
]);

Issues and improvements

Feel free to ask questions or improve the project.

Links

Repository: https://github.com/codex-team/hawk.php

Report a bug: https://github.com/codex-team/hawk.php/issues

Composer Package: https://packagist.org/packages/codex-team/hawk.php

CodeX Team: https://codex.so

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). See the LICENSE file for the full text.

About

PHP Errors catching and monitoring

hawk.so

Topics

catchercomposerenabling-handlerserror-catcherhawkphp

Resources

Readme
AGPL-3.0 license
Activity
Custom properties

Stars

22 stars

Watchers

4 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.