-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use correlation id from butler-audit when logging to Graylog.
Use the correlation-id published by butler-audit when logging to graylog to allow for grouping all graylog entries originating from the same request. This change is made to be able to trace requests between systems.
- Loading branch information
1 parent
5fc4ffb
commit 96897ac
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Butler\Service\Tests\Unit; | ||
|
||
use Butler\Audit\Facades\Auditor; | ||
use Butler\Service\Logging\GraylogLoggerFactory; | ||
use Butler\Service\Tests\TestCase; | ||
use Gelf\Message; | ||
use Gelf\Transport\UdpTransport; | ||
use Mockery; | ||
|
||
class GraylogLoggerFactoryTest extends TestCase | ||
{ | ||
public function test_correctly_uses_configuration_and_correlation_id_from_container() | ||
{ | ||
Auditor::correlationId('example-correlation-id'); | ||
|
||
app()->bind(UdpTransport::class, function () { | ||
$transport = Mockery::mock(UdpTransport::class); | ||
$transport->expects()->send( | ||
Mockery::on(function (Message $message) { | ||
return $message->getShortMessage() === 'Testing' | ||
&& $message->getAdditional('trace_id') === 'example-correlation-id' | ||
&& $message->getAdditional('service') === 'butler-service'; | ||
}) | ||
); | ||
return $transport; | ||
}); | ||
|
||
$config = [ | ||
'name' => 'butler-service', | ||
'name_key' => 'service', | ||
'host' => '127.0.0.1', | ||
'port' => 12201, | ||
]; | ||
|
||
$factory = new GraylogLoggerFactory($config); | ||
$logger = $factory($config); | ||
$logger->info('Testing'); | ||
} | ||
} |