elastic / ecs-logging-php

Apache License 2.0
19 stars 35 forks source link

Extras data is ignored #13

Open chippyash opened 4 years ago

chippyash commented 4 years ago

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.

akzincsystems commented 4 years ago

bump

SergeyKleyman commented 3 years ago

It should be fixed in the latest release (1.0.2).