Skip to content

Commit

Permalink
Merge pull request #64 from codex-team/feature/add-environment-addon-…
Browse files Browse the repository at this point in the history
…to-error-payload

Add `Environment` Addon to Include Hostname in Error Payload
  • Loading branch information
pavelzotikov authored Nov 14, 2024
2 parents c5cfdb2 + 95e85c4 commit 3718d29
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "PHP errors Catcher module for Hawk.so",
"keywords": ["hawk", "php", "error", "catcher"],
"type": "library",
"version": "2.2.4",
"version": "2.2.5",
"license": "MIT",
"require": {
"ext-curl": "*",
Expand Down
42 changes: 42 additions & 0 deletions src/Addons/Environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Hawk\Addons;

/**
* Class Environment
*
* @package Hawk\Addons
*/
class Environment implements AddonInterface
{
private array $environment = [];

/**
* @inheritdoc
*/
public function getName(): string
{
return 'Environment';
}

/**
* @inheritDoc
*/
public function resolve(): array
{
$this->addHostname();

return $this->environment;
}

private function addHostname(): void
{
$hostname = gethostname();

if ($hostname !== false) {
$this->environment['hostname'] = $hostname;
}
}
}
2 changes: 1 addition & 1 deletion src/Addons/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Headers implements AddonInterface
*/
public function getName(): string
{
return 'headers';
return 'Headers';
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Catcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hawk;

use Hawk\Addons\Environment;
use Hawk\Addons\Headers;
use Hawk\Transport\CurlTransport;
use Throwable;
Expand Down Expand Up @@ -154,6 +155,7 @@ private function __construct(array $options)
*/
$builder = new EventPayloadBuilder($stacktraceBuilder);
$builder->registerAddon(new Headers());
$builder->registerAddon(new Environment());

$transport = new CurlTransport($options->getUrl());

Expand Down

0 comments on commit 3718d29

Please sign in to comment.