Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Extras data is ignored

Open
#13 2 comments 0 reactions 1 assignee View on GitHub

@SergeyKleyman is already working on this.

Since Feb 10, 2021.

Assessment

This issue has not been assessed yet.

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.

Dominant language
PHP
Stars
21
Forks
42
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from elastic/ecs-logging-php

All issues in elastic/ecs-logging-php

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.