elastic / elastic/ecs-logging-php
Extras data is ignored
- Dominant language
- PHP
- Stars
- 21
- Forks
- 42
- Avg merge
- 28m
- Merged PRs (30d)
- 1
Description
Hi,
I'm curious. Reading through source code to figure out why data that I am inserting via processors (e.g. MonoLog WebProcessor) is not being displayed by your formatter, I see that you are completely ignoring the `extras` array member of the Monolog record structure, and instead relying on data being in the `context` member of the record. This appears to be somewhat counter-intuitive to the way that Monolog normally works.
Is this purposeful, or just an unhandled scenario at the present time?
```
use \Codeception\Test\Unit as UnitTest;
use Elastic\Monolog\Formatter\ElasticCommonSchemaFormatter;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
class ECSFormatterTest extends UnitTest
{
/**
* Logger
*/
protected $sut;
/**
* @var TestHandler
*/
protected $handler;
public function testECSFormatIsSupported()
{
$this->sut->error('Test Message', ['func' => __FUNCTION__]);
$record = $this->handler->getRecords()[0]['formatted'];
var_dump($record);exit;
}
protected function setUp(): void
{
$this->handler = new TestHandler();
$formatter = new ElasticCommonSchemaFormatter();
$this->handler->setFormatter($formatter);
//mock a web server
$serverData = [
'REQUEST_URI' => '/test',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_METHOD' => 'GET',
'SERVER_NAME' => 'zinc.test',
'HTTP_REFERER' => 'http://zinc.test',
];
$this->sut = new Logger('test', [$this->handler], [new WebProcessor($serverData)]);
}
}
```
At the very least I would expect the data that gets injected into `extras` to get into the output format `labels` node, as the `func` item does in the above test snippet. Ideally I would see 'REMOTE_ADDR' being injected to `source.ip` in the output.
Contributor guide
Assessment
This issue has not been assessed yet.