Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GelfHandler "Message is invalid: additional key contains invalid characters" #1927

Open
ybelenko opened this issue Nov 21, 2024 · 0 comments
Labels

Comments

@ybelenko
Copy link

ybelenko commented Nov 21, 2024

Monolog version 1|2|3?

{
    "name": "monolog/monolog",
    "version": "3.8.0",
    "source": {
        "type": "git",
        "url": "https://github.com/Seldaek/monolog.git",
        "reference": "32e515fdc02cdafbe4593e30a9350d486b125b67"
    }
}

With the basic log call

$logger->info('Hello World', ['invalid context' => 'test']);
[2024-11-21T12:21:39.764122+00:00] Cron.ERROR: Uncaught Exception RuntimeException: "Message is invalid: additional key 'ctxt_invalid context' contains invalid characters" at /Users/ybelenko/Sites/bdo_pay/vendor/graylog2/gelf-php/src/Gelf/Publisher.php line 58 {"exception":"[object] (RuntimeException(code: 0): Message is invalid: additional key 'ctxt_invalid context' contains invalid characters at /Users/ybelenko/Sites/bdo_pay/vendor/graylog2/gelf-php/src/Gelf/Publisher.php:58)"} []

I guess Monolog should prepare $context and $extra for Publisher and strip spaces.
Valdiation part in vendor/graylog2/gelf-php/src/Gelf/MessageValidator.php:

foreach ($message->getAllAdditionals() as $key => $value) {
    if (!preg_match('#^[\w\.\-]*$#', $key)) {
        $reason = sprintf(
            "additional key '%s' contains invalid characters",
            $key
        );

        return false;
    }
}
@ybelenko ybelenko added the Bug label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant